Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
- improved "did you mean" - added &meanCount= to query string - &meanCount=0 ==> no suggestion, no performance loss - sorting suggestions by sb.indexSegment.termIndex().count()
apfelmaennchen09acfa66d162
diff --git a/htroot/yacysearch.java b/htroot/yacysearch.javaindex 1245c0a8a..a4c95aa30 100644--- a/htroot/yacysearch.java+++ b/htroot/yacysearch.java@@ -469,35 +469,41 @@ public class yacysearch {sb.localSearches.add(theQuery);// check suggestions- DidYouMean didYouMean = new DidYouMean(sb);- Iterator<String> meanIt = didYouMean.getSuggestion(querystring).iterator();- int meanCount = 0;- String suggestion;- prop.put("didYouMean", 0);- while(meanIt.hasNext()) {- suggestion = meanIt.next();- prop.put("didYouMean_suggestions_"+meanCount+"_word", suggestion);- prop.put("didYouMean_suggestions_"+meanCount+"_url",- "/yacysearch.html" + "?display=" + display +- "&search=" + suggestion +- "&maximumRecords="+ theQuery.displayResults() +- "&startRecord=" + (0 * theQuery.displayResults()) +- "&resource=" + ((theQuery.isLocal()) ? "local" : "global") +- "&verify=" + ((theQuery.onlineSnippetFetch) ? "true" : "false") +- "&nav=" + theQuery.navigators +- "&urlmaskfilter=" + originalUrlMask +- "&prefermaskfilter=" + theQuery.prefer +- "&cat=href&constraint=" + ((theQuery.constraint == null) ? "" : theQuery.constraint.exportB64()) +- "&contentdom=" + theQuery.contentdom() +- "&former=" + theQuery.queryString(true)- );- prop.put("didYouMean_suggestions_"+meanCount+"_sep","|");- meanCount++;+ int meanMax = 0;+ if (post != null && post.containsKey("meanCount")) {+ meanMax = Integer.parseInt(post.get("meanCount"));+ }+ if(meanMax > 0) {+ DidYouMean didYouMean = new DidYouMean(sb);+ Iterator<String> meanIt = didYouMean.getSuggestion(querystring).iterator();+ int meanCount = 0;+ String suggestion;+ while(meanCount<meanMax && meanIt.hasNext()) {+ suggestion = meanIt.next();+ prop.put("didYouMean_suggestions_"+meanCount+"_word", suggestion);+ prop.put("didYouMean_suggestions_"+meanCount+"_url",+ "/yacysearch.html" + "?display=" + display ++ "&search=" + suggestion ++ "&maximumRecords="+ theQuery.displayResults() ++ "&startRecord=" + (0 * theQuery.displayResults()) ++ "&resource=" + ((theQuery.isLocal()) ? "local" : "global") ++ "&verify=" + ((theQuery.onlineSnippetFetch) ? "true" : "false") ++ "&nav=" + theQuery.navigators ++ "&urlmaskfilter=" + originalUrlMask ++ "&prefermaskfilter=" + theQuery.prefer ++ "&cat=href&constraint=" + ((theQuery.constraint == null) ? "" : theQuery.constraint.exportB64()) ++ "&contentdom=" + theQuery.contentdom() ++ "&former=" + theQuery.queryString(true)+ );+ prop.put("didYouMean_suggestions_"+meanCount+"_sep","|");+ meanCount++;+ }+ prop.put("didYouMean_suggestions_"+(meanCount-1)+"_sep","");+ prop.put("didYouMean", 1);+ prop.put("didYouMean_suggestions", meanCount);+ } else {+ prop.put("didYouMean", 0);}- prop.put("didYouMean_suggestions_"+(meanCount-1)+"_sep","");- if(meanCount > 0)- prop.put("didYouMean", 1);- prop.put("didYouMean_suggestions", meanCount);// update the search trackertry {diff --git a/source/de/anomic/tools/DidYouMean.java b/source/de/anomic/tools/DidYouMean.javaindex 0c9f52189..baaeec91e 100644--- a/source/de/anomic/tools/DidYouMean.java+++ b/source/de/anomic/tools/DidYouMean.java@@ -42,15 +42,12 @@ public class DidYouMean {ReversingTwoConsecutiveLetters();final Iterator<String> it = this.set.iterator();- // final TreeSet<String> rset = new TreeSet<String>(new wordSizeComparator());- final TreeSet<String> rset = new TreeSet<String>();+ final TreeSet<String> rset = new TreeSet<String>(new wordSizeComparator());String s;- int count = 0;- while(count<10 && it.hasNext()) {+ while(it.hasNext()) {s = it.next();if(sb.indexSegment.termIndex().has(Word.word2hash(s))) {rset.add(s);- count++;}}rset.remove(word.toLowerCase());@@ -90,7 +87,7 @@ public class DidYouMean {public int compare(final String o1, final String o2) {final Integer i1 = sb.indexSegment.termIndex().count(Word.word2hash(o1));final Integer i2 = sb.indexSegment.termIndex().count(Word.word2hash(o2));- return i1.compareTo(i2);+ return i2.compareTo(i1);}}