lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r912508 - /lucene/java/trunk/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java
Date Mon, 22 Feb 2010 08:27:05 GMT
Author: uschindler
Date: Mon Feb 22 08:27:05 2010
New Revision: 912508

URL: http://svn.apache.org/viewvc?rev=912508&view=rev
Log:
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.


Modified:
    lucene/java/trunk/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java?rev=912508&r1=912507&r2=912508&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java
(original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java
Mon Feb 22 08:27:05 2010
@@ -29,6 +29,7 @@
 import java.util.Map;
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
 
 /**
  * Test CustomScoreQuery search.
@@ -188,6 +189,7 @@
     }
   }
 
+  @Test
   public 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 @@
     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;



Mime
View raw message