diff --git a/modules/suggest/src/test/org/apache/lucene/search/suggest/fst/FSTLookupTest.java b/modules/suggest/src/test/org/apache/lucene/search/suggest/fst/FSTLookupTest.java index 057c87e4a04..224ab3f5d26 100644 --- a/modules/suggest/src/test/org/apache/lucene/search/suggest/fst/FSTLookupTest.java +++ b/modules/suggest/src/test/org/apache/lucene/search/suggest/fst/FSTLookupTest.java @@ -43,6 +43,12 @@ public class FSTLookupTest extends LuceneTestCase { public void setUp() throws Exception { super.setUp(); + + lookup = new FSTLookup(); + lookup.build(new TermFreqArrayIterator(evalKeys())); + } + + private TermFreq[] evalKeys() { final TermFreq[] keys = new TermFreq[] { tf("one", 0.5f), tf("oneness", 1), @@ -61,9 +67,7 @@ public class FSTLookupTest extends LuceneTestCase { tf("fourty", 1), tf("xo", 1), }; - - lookup = new FSTLookup(); - lookup.build(new TermFreqArrayIterator(keys)); + return keys; } public void testExactMatchHighPriority() throws Exception { @@ -76,6 +80,31 @@ public class FSTLookupTest extends LuceneTestCase { "oneness/1.0"); } + public void testRequestedCount() throws Exception { + // 'one' is promoted after collecting two higher ranking results. + assertMatchEquals(lookup.lookup("one", true, 2), + "one/0.0", + "oneness/1.0"); + + // 'one' is at the top after collecting all alphabetical results. + assertMatchEquals(lookup.lookup("one", false, 2), + "one/0.0", + "oneness/1.0"); + + lookup = new FSTLookup(10, false); + lookup.build(new TermFreqArrayIterator(evalKeys())); + + // 'one' is not promoted after collecting two higher ranking results. + assertMatchEquals(lookup.lookup("one", true, 2), + "oneness/1.0", + "onerous/1.0"); + + // 'one' is at the top after collecting all alphabetical results. + assertMatchEquals(lookup.lookup("one", false, 2), + "one/0.0", + "oneness/1.0"); + } + public void testMiss() throws Exception { assertMatchEquals(lookup.lookup("xyz", true, 1)); }