Apache Solr open-source search software
throw IAE from suggesters that ignore onlyMorePopular arg
Michael McCandless59fe6f6a2147
diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.javaindex 38c3e914467..4461b208d1c 100644--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java@@ -504,6 +504,10 @@ public class AnalyzingSuggester extends Lookup {public List<LookupResult> lookup(final CharSequence key, boolean onlyMorePopular, int num) {assert num > 0;+ if (onlyMorePopular) {+ throw new IllegalArgumentException("this suggester only works with onlyMorePopular=false");+ }+//System.out.println("lookup key=" + key + " num=" + num);try {diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/WFSTCompletionLookup.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/WFSTCompletionLookup.javaindex 0ee605585ec..b7d9f79c964 100644--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/WFSTCompletionLookup.java+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/WFSTCompletionLookup.java@@ -143,6 +143,11 @@ public class WFSTCompletionLookup extends Lookup {@Overridepublic List<LookupResult> lookup(CharSequence key, boolean onlyMorePopular, int num) {assert num > 0;++ if (onlyMorePopular) {+ throw new IllegalArgumentException("this suggester only works with onlyMorePopular=false");+ }+BytesRef scratch = new BytesRef(key);int prefixLength = scratch.length;Arc<Long> arc = new Arc<Long>();diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.javaindex accceebf6f0..859dd7efc9d 100644--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.java+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.java@@ -46,7 +46,7 @@ public class WFSTCompletionTest extends LuceneTestCase {assertEquals(50, results.get(0).value, 0.01F);// make sure we don't get a dup exact suggestion:- results = suggester.lookup(_TestUtil.stringToCharSequence("foo", random), true, 2);+ results = suggester.lookup(_TestUtil.stringToCharSequence("foo", random), false, 2);assertEquals(1, results.size());assertEquals("foo", results.get(0).key.toString());assertEquals(50, results.get(0).value, 0.01F);diff --git a/solr/core/src/java/org/apache/solr/spelling/suggest/Suggester.java b/solr/core/src/java/org/apache/solr/spelling/suggest/Suggester.javaindex b1220a90922..521bb94398f 100644--- a/solr/core/src/java/org/apache/solr/spelling/suggest/Suggester.java+++ b/solr/core/src/java/org/apache/solr/spelling/suggest/Suggester.java@@ -32,11 +32,12 @@ import org.apache.lucene.search.spell.Dictionary;import org.apache.lucene.search.spell.HighFrequencyDictionary;import org.apache.lucene.search.spell.SuggestMode;import org.apache.lucene.search.suggest.FileDictionary;-import org.apache.lucene.search.suggest.Lookup;import org.apache.lucene.search.suggest.Lookup.LookupResult;+import org.apache.lucene.search.suggest.Lookup;+import org.apache.lucene.search.suggest.analyzing.AnalyzingSuggester;+import org.apache.lucene.search.suggest.fst.WFSTCompletionLookup;import org.apache.lucene.util.CharsRef;import org.apache.lucene.util.IOUtils;-import org.apache.solr.common.util.NamedList;import org.apache.solr.core.SolrCore;import org.apache.solr.search.SolrIndexSearcher;@@ -187,8 +188,10 @@ public class Suggester extends SolrSpellChecker {scratch.chars = t.buffer();scratch.offset = 0;scratch.length = t.length();- List<LookupResult> suggestions = lookup.lookup(scratch,- (options.suggestMode == SuggestMode.SUGGEST_MORE_POPULAR), options.count);+ boolean onlyMorePopular = (options.suggestMode == SuggestMode.SUGGEST_MORE_POPULAR) &&+ !(lookup instanceof WFSTCompletionLookup) &&+ !(lookup instanceof AnalyzingSuggester);+ List<LookupResult> suggestions = lookup.lookup(scratch, onlyMorePopular, options.count);if (suggestions == null) {continue;}