use of com.greplin.lucene.document.DocumentBuilder in project greplin-lucene-utils by Cue.
the class PredicateBonusQueryTest method testBasics.
@Test
public void testBasics() throws Exception {
IndexWriter writer = new IndexWriter(this.directory, new IndexWriterConfig(Version.LUCENE_35, new WhitespaceAnalyzer(Version.LUCENE_35)));
writer.addDocument(new DocumentBuilder().add("value", "5").build());
writer.close();
IndexReader reader = IndexReader.open(this.directory);
IndexSearcher searcher = new IndexSearcher(reader);
Query query = new ConstantScoreQuery(new TermQuery(new Term("value", "5")));
Assert.assertEquals(1.0, searcher.search(query, 1).getMaxScore(), 0.00001);
Query noBonus = new PredicateBonusQuery(query, Predicates.NONE, 10.0f);
Assert.assertEquals(1.0, searcher.search(noBonus, 1).getMaxScore(), 0.00001);
Query bonus = new PredicateBonusQuery(query, Predicates.ALL, 100.0f);
Assert.assertEquals(101.0, searcher.search(bonus, 1).getMaxScore(), 0.00001);
Query noMatch = new TermQuery(new Term("value", "not5"));
Assert.assertEquals(Double.NaN, searcher.search(noMatch, 1).getMaxScore(), 0.00001);
Query noMatchNoBonus = new PredicateBonusQuery(noMatch, Predicates.NONE, 10.0f);
Assert.assertEquals(Double.NaN, searcher.search(noMatchNoBonus, 1).getMaxScore(), 0.00001);
Query noMatchIgnoresBonus = new PredicateBonusQuery(noMatch, Predicates.ALL, 100.0f);
Assert.assertEquals(Double.NaN, searcher.search(noMatchIgnoresBonus, 1).getMaxScore(), 0.00001);
}
Aggregations