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.
pull/8/head
Michael Peter Christen 10 years ago
parent 886fca2260
commit 1fec7fb3c1

@ -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) {

@ -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 {

@ -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 words
preSorted = 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&lt;String&gt; 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

Loading…
Cancel
Save