public virtual void TestNegativeQueryBoost() { Query q = new TermQuery(new Term("foo", "bar")); q.Boost = -42f; Assert.AreEqual(-42f, q.Boost, 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 = newSearcher(reader); ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs; Assert.AreEqual(1, hits.Length); Assert.IsTrue("score is not negative: " + hits[0].score, hits[0].score < 0); Explanation explain = searcher.explain(q, hits[0].doc); Assert.AreEqual("score doesn't match explanation", hits[0].score, explain.Value, 0.001f); Assert.IsTrue("explain doesn't think doc is a match", explain.Match); } finally { reader.close(); } } finally { directory.close(); } }