mirror of https://github.com/apache/lucene.git
throw IAE from suggesters that ignore onlyMorePopular arg
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1401024 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4a17b6a1ed
commit
59fe6f6a21
|
@ -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 {
|
||||
|
|
|
@ -143,6 +143,11 @@ public class WFSTCompletionLookup extends Lookup {
|
|||
@Override
|
||||
public 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>();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue