Apache Lucene open-source search software
LUCENE-2190: Add testcase for rewrite. Also add missing annotation for other test added by Mike. CustomScore uses JUnit4, so @Test is needed. We should somehow customize LuceneTestCaseJ4 to emulate old behaviour, else we get lots of tests without annotation never ran.
Uwe Schindlera79929bc245c
diff --git a/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java b/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.javaindex 1cb5b3289cd..0965e795563 100755--- a/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java+++ b/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java@@ -29,6 +29,7 @@ import java.util.HashMap;import java.util.Map;import org.apache.lucene.index.IndexReader;+import org.apache.lucene.index.Term;/*** Test CustomScoreQuery search.@@ -188,6 +189,7 @@ public class TestCustomScoreQuery extends FunctionTestSetup {}}+ @Testpublic void testCustomExternalQuery() throws Exception {QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, TEXT_FIELD,anlzr);String qtxt = "first aid text"; // from the doc texts in FunctionQuerySetup.@@ -207,6 +209,29 @@ public class TestCustomScoreQuery extends FunctionTestSetup {s.close();}+ @Test+ public void testRewrite() throws Exception {+ final IndexSearcher s = new IndexSearcher(dir, true);++ Query q = new TermQuery(new Term(TEXT_FIELD, "first"));+ CustomScoreQuery original = new CustomScoreQuery(q);+ CustomScoreQuery rewritten = (CustomScoreQuery) original.rewrite(s.getIndexReader());+ assertTrue("rewritten query should be identical, as TermQuery does not rewrite", original == rewritten);+ assertTrue("no hits for query", s.search(rewritten,1).totalHits > 0);+ assertEquals(s.search(q,1).totalHits, s.search(rewritten,1).totalHits);++ q = new TermRangeQuery(TEXT_FIELD, null, null, true, true); // everything+ original = new CustomScoreQuery(q);+ rewritten = (CustomScoreQuery) original.rewrite(s.getIndexReader());+ assertTrue("rewritten query should not be identical, as TermRangeQuery rewrites", original != rewritten);+ assertTrue("rewritten query should be a CustomScoreQuery", rewritten instanceof CustomScoreQuery);+ assertTrue("no hits for query", s.search(rewritten,1).totalHits > 0);+ assertEquals(s.search(q,1).totalHits, s.search(original,1).totalHits);+ assertEquals(s.search(q,1).totalHits, s.search(rewritten,1).totalHits);++ s.close();+ }+// Test that FieldScoreQuery returns docs with expected score.private void doTestCustomScore(String field, FieldScoreQuery.Type tp, double dboost) throws Exception, ParseException {float boost = (float) dboost;