- 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
pull/1/head
apfelmaennchen 16 years ago
parent da6ce37f7b
commit 09acfa66d1

@ -469,12 +469,16 @@ public class yacysearch {
sb.localSearches.add(theQuery);
// check suggestions
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;
prop.put("didYouMean", 0);
while(meanIt.hasNext()) {
while(meanCount<meanMax && meanIt.hasNext()) {
suggestion = meanIt.next();
prop.put("didYouMean_suggestions_"+meanCount+"_word", suggestion);
prop.put("didYouMean_suggestions_"+meanCount+"_url",
@ -495,9 +499,11 @@ public class yacysearch {
meanCount++;
}
prop.put("didYouMean_suggestions_"+(meanCount-1)+"_sep","");
if(meanCount > 0)
prop.put("didYouMean", 1);
prop.put("didYouMean_suggestions", meanCount);
} else {
prop.put("didYouMean", 0);
}
// update the search tracker
try {

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

Loading…
Cancel
Save