You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by dn...@apache.org on 2005/01/28 23:22:04 UTC
cvs commit: jakarta-lucene/src/test/org/apache/lucene/search TestPhraseQuery.java
dnaber 2005/01/28 14:22:04
Modified: src/test/org/apache/lucene/search TestPhraseQuery.java
Log:
test case that makes sure sloppy phrase queries use the term distance to calculate the result ranking
Revision Changes Path
1.10 +40 -0 jakarta-lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java
Index: TestPhraseQuery.java
===================================================================
RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TestPhraseQuery.java 7 Sep 2004 18:26:36 -0000 1.9
+++ TestPhraseQuery.java 28 Jan 2005 22:22:04 -0000 1.10
@@ -16,6 +16,8 @@
* limitations under the License.
*/
+import java.io.IOException;
+
import junit.framework.TestCase;
import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.analysis.StopAnalyzer;
@@ -23,6 +25,7 @@
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
+import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
/**
@@ -254,4 +257,41 @@
searcher.close();
directory.close();
}
+
+ public void testSlopScoring() throws IOException {
+ Directory directory = new RAMDirectory();
+ IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
+
+ Document doc = new Document();
+ doc.add(new Field("field", "foo firstname lastname foo", Field.Store.YES, Field.Index.TOKENIZED));
+ writer.addDocument(doc);
+
+ Document doc2 = new Document();
+ doc2.add(new Field("field", "foo firstname xxx lastname foo", Field.Store.YES, Field.Index.TOKENIZED));
+ writer.addDocument(doc2);
+
+ Document doc3 = new Document();
+ doc3.add(new Field("field", "foo firstname xxx yyy lastname foo", Field.Store.YES, Field.Index.TOKENIZED));
+ writer.addDocument(doc3);
+
+ writer.optimize();
+ writer.close();
+
+ Searcher searcher = new IndexSearcher(directory);
+ PhraseQuery query = new PhraseQuery();
+ query.add(new Term("field", "firstname"));
+ query.add(new Term("field", "lastname"));
+ query.setSlop(Integer.MAX_VALUE);
+ Hits hits = searcher.search(query);
+ assertEquals(3, hits.length());
+ // Make sure that those matches where the terms appear closer to
+ // each other get a higher score:
+ assertEquals(0.71, hits.score(0), 0.01);
+ assertEquals(0, hits.id(0));
+ assertEquals(0.44, hits.score(1), 0.01);
+ assertEquals(1, hits.id(1));
+ assertEquals(0.31, hits.score(2), 0.01);
+ assertEquals(2, hits.id(2));
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org