From 09acfa66d1623706087150eeb69d180ab202e280 Mon Sep 17 00:00:00 2001 From: apfelmaennchen Date: Sat, 13 Jun 2009 06:20:05 +0000 Subject: [PATCH] - 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 --- htroot/yacysearch.java | 62 ++++++++++++++------------ source/de/anomic/tools/DidYouMean.java | 9 ++-- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java index 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 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 meanIt = didYouMean.getSuggestion(querystring).iterator(); + int meanCount = 0; + String suggestion; + while(meanCount 0) - prop.put("didYouMean", 1); - prop.put("didYouMean_suggestions", meanCount); // update the search tracker try { diff --git a/source/de/anomic/tools/DidYouMean.java b/source/de/anomic/tools/DidYouMean.java index 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 it = this.set.iterator(); - // final TreeSet rset = new TreeSet(new wordSizeComparator()); - final TreeSet rset = new TreeSet(); + final TreeSet rset = new TreeSet(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); } }