Backporting test changes.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/branch_3x@1171133 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/FSTLookup.java b/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/FSTLookup.java
index 1b7ea77..a3e6319 100644
--- a/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/FSTLookup.java
+++ b/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/FSTLookup.java
@@ -335,7 +335,7 @@
// so we will collect it too.
output.setLength(matchLength);
if (collect(res, num, weight, output, arc) && greedy) {
- // We have enough suggestion to return immediately. Keep on looking for an
+ // We have enough suggestions to return immediately. Keep on looking for an
// exact match, if requested.
if (exactMatchFirst) {
Float exactMatchWeight = getExactMatchStartingFromRootArc(i, key);
diff --git a/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/suggest/fst/FSTLookupTest.java b/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/suggest/fst/FSTLookupTest.java
index 057c87e..224ab3f 100644
--- a/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/suggest/fst/FSTLookupTest.java
+++ b/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/suggest/fst/FSTLookupTest.java
@@ -43,6 +43,12 @@
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 @@
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 @@
"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));
}