mirror of https://github.com/apache/lucene.git
added test coverage demonstrating negative query boosts
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1383685 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9e42025307
commit
122bf3435f
|
@ -34,6 +34,49 @@ import org.apache.lucene.search.*;
|
|||
/** JUnit adaptation of an older test case SearchTest. */
|
||||
public class TestSearch extends LuceneTestCase {
|
||||
|
||||
public void testNegativeQueryBoost() throws Exception {
|
||||
Query q = new TermQuery(new Term("foo", "bar"));
|
||||
q.setBoost(-42f);
|
||||
assertEquals(-42f, q.getBoost(), 0.0f);
|
||||
|
||||
Directory directory = newDirectory();
|
||||
try {
|
||||
Analyzer analyzer = new MockAnalyzer(random());
|
||||
IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
|
||||
|
||||
IndexWriter writer = new IndexWriter(directory, conf);
|
||||
try {
|
||||
Document d = new Document();
|
||||
d.add(newTextField("foo", "bar", Field.Store.YES));
|
||||
writer.addDocument(d);
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
|
||||
IndexReader reader = DirectoryReader.open(directory);
|
||||
try {
|
||||
IndexSearcher searcher = new IndexSearcher(reader);
|
||||
|
||||
ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
|
||||
assertEquals(1, hits.length);
|
||||
assertTrue("score is not negative: " + hits[0].score,
|
||||
hits[0].score < 0);
|
||||
|
||||
Explanation explain = searcher.explain(q, hits[0].doc);
|
||||
assertEquals("score doesn't match explanation",
|
||||
hits[0].score, explain.getValue(), 0.001f);
|
||||
assertTrue("explain doesn't think doc is a match",
|
||||
explain.isMatch());
|
||||
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} finally {
|
||||
directory.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** This test performs a number of searches. It also compares output
|
||||
* of searches using multi-file index segments with single-file
|
||||
* index segments.
|
||||
|
|
Loading…
Reference in New Issue