- improved "did you mean"

- added &meanCount= to query string
- &meanCount=0 ==> no suggestion, no performance loss
- sorting suggestions by sb.indexSegment.termIndex().count()

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6059 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
apfelmaennchen 2009-06-13 06:20:05 +00:00
parent da6ce37f7b
commit 09acfa66d1
2 changed files with 37 additions and 34 deletions

View File

@ -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&amp;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&amp;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 tracker
try {

View File

@ -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);
}
}