Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
suppress access to solr when doing search suggestions in case that the index has more than two million documents. This protects the index from beeing flooded with search requests that cannot be resolved before the real search query has to be computet.
Michael Peter Christen1fec7fb3c130
diff --git a/htroot/suggest.java b/htroot/suggest.javaindex e64741744..441505299 100644--- a/htroot/suggest.java+++ b/htroot/suggest.java@@ -68,7 +68,7 @@ public class suggest {int c = 0;final DidYouMean didYouMean = new DidYouMean(sb.index, querystring);- final Collection<StringBuilder> suggestions = didYouMean.getSuggestions(timeout, count);+ final Collection<StringBuilder> suggestions = didYouMean.getSuggestions(timeout, count, sb.index.fulltext().collectionSize() < 2000000);//[#[query]#,[#{suggestions}##[text]##(eol)#,::#(/eol)##{/suggestions}#]]synchronized (suggestions) {for (StringBuilder suggestion: suggestions) {diff --git a/htroot/yacysearch.java b/htroot/yacysearch.javaindex e782057e6..e31e95d2f 100644--- a/htroot/yacysearch.java+++ b/htroot/yacysearch.java@@ -760,7 +760,7 @@ public class yacysearch {prop.put("meanCount", meanMax);if ( meanMax > 0 && !json && !rss && sb.index.connectedRWI()) {final DidYouMean didYouMean = new DidYouMean(indexSegment, querystring);- final Iterator<StringBuilder> meanIt = didYouMean.getSuggestions(100, 5).iterator();+ final Iterator<StringBuilder> meanIt = didYouMean.getSuggestions(100, 5, sb.index.fulltext().collectionSize() < 2000000).iterator();int meanCount = 0;String suggestion;try {diff --git a/source/net/yacy/data/DidYouMean.java b/source/net/yacy/data/DidYouMean.javaindex 7478911bf..c33aecb34 100644--- a/source/net/yacy/data/DidYouMean.java+++ b/source/net/yacy/data/DidYouMean.java@@ -154,7 +154,7 @@ public class DidYouMean {* @param preSortSelection the number of words that participate in the IO-intensive sort* @return*/- public Collection<StringBuilder> getSuggestions(final long timeout, final int preSortSelection) {+ public Collection<StringBuilder> getSuggestions(final long timeout, final int preSortSelection, boolean askIndex) {if (this.word.length() < MinimumInputWordLength) {return this.resultSet; // return nothing if input is too short}@@ -162,14 +162,14 @@ public class DidYouMean {final long timelimit = startTime + timeout;int lastIndexOfSpace = this.word.lastIndexOf(" ");final Collection<StringBuilder> preSorted;- if (lastIndexOfSpace > 0) {+ if (askIndex && lastIndexOfSpace > 0) {// several wordspreSorted = getSuggestions(this.word.substring(0, lastIndexOfSpace), this.word.substring(lastIndexOfSpace + 1), timeout, preSortSelection, this.segment);} else {if (this.endsWithSpace) {preSorted = getSuggestions(this.word.toString(), "", timeout, preSortSelection, this.segment);} else {- preSorted = getSuggestions(timeout);+ preSorted = getSuggestions(timeout, askIndex);}}final ReversibleScoreMap<StringBuilder> scored = new ClusteredScoreMap<StringBuilder>(StringBuilderComparator.CASE_INSENSITIVE_ORDER);@@ -347,7 +347,7 @@ public class DidYouMean {* @param timeout execution time in ms.* @return a Set<String> with word variations contained in term index.*/- private Collection<StringBuilder> getSuggestions(final long timeout) {+ private Collection<StringBuilder> getSuggestions(final long timeout, boolean askIndex) {final long startTime = System.currentTimeMillis();this.timeLimit = startTime + timeout;@@ -368,7 +368,7 @@ public class DidYouMean {}test(this.word);- this.resultSet.addAll(getSuggestions("", this.word.toString(), timeout, 10, this.segment));+ if (askIndex) this.resultSet.addAll(getSuggestions("", this.word.toString(), timeout, 10, this.segment));if (this.more) {// finish the producer