You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2012/09/16 14:37:36 UTC
svn commit: r1385252 -
/lucene/dev/branches/lucene3842/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.java
Author: mikemccand
Date: Sun Sep 16 12:37:36 2012
New Revision: 1385252
URL: http://svn.apache.org/viewvc?rev=1385252&view=rev
Log:
LUCENE-3842: add test cases for WFSTCompletionLookup
Modified:
lucene/dev/branches/lucene3842/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.java
Modified: lucene/dev/branches/lucene3842/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3842/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.java?rev=1385252&r1=1385251&r2=1385252&view=diff
==============================================================================
--- lucene/dev/branches/lucene3842/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.java (original)
+++ lucene/dev/branches/lucene3842/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.java Sun Sep 16 12:37:36 2012
@@ -75,6 +75,54 @@ public class WFSTCompletionTest extends
assertEquals("barbara", results.get(2).key.toString());
assertEquals(6, results.get(2).value, 0.01F);
}
+
+ public void testExactFirst() throws Exception {
+
+ WFSTCompletionLookup suggester = new WFSTCompletionLookup(true);
+
+ suggester.build(new TermFreqArrayIterator(new TermFreq[] {
+ new TermFreq("x y", 20),
+ new TermFreq("x", 2),
+ }));
+
+ for(int topN=1;topN<4;topN++) {
+ List<LookupResult> results = suggester.lookup("x", false, topN);
+
+ assertEquals(Math.min(topN, 2), results.size());
+
+ assertEquals("x", results.get(0).key);
+ assertEquals(2, results.get(0).value);
+
+ if (topN > 1) {
+ assertEquals("x y", results.get(1).key);
+ assertEquals(20, results.get(1).value);
+ }
+ }
+ }
+
+ public void testNonExactFirst() throws Exception {
+
+ WFSTCompletionLookup suggester = new WFSTCompletionLookup(false);
+
+ suggester.build(new TermFreqArrayIterator(new TermFreq[] {
+ new TermFreq("x y", 20),
+ new TermFreq("x", 2),
+ }));
+
+ for(int topN=1;topN<4;topN++) {
+ List<LookupResult> results = suggester.lookup("x", false, topN);
+
+ assertEquals(Math.min(topN, 2), results.size());
+
+ assertEquals("x y", results.get(0).key);
+ assertEquals(20, results.get(0).value);
+
+ if (topN > 1) {
+ assertEquals("x", results.get(1).key);
+ assertEquals(2, results.get(1).value);
+ }
+ }
+ }
public void testRandom() throws Exception {
int numWords = atLeast(1000);