lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r808519 - in /lucene/java/trunk: ./ contrib/regex/src/java/org/apache/lucene/search/regex/ src/java/org/apache/lucene/search/ src/test/org/apache/lucene/search/
Date Thu, 27 Aug 2009 16:57:28 GMT
Author: mikemccand
Date: Thu Aug 27 16:57:27 2009
New Revision: 808519

URL: http://svn.apache.org/viewvc?rev=808519&view=rev
Log:
LUCENE-1860: default all multi-term queries to constant score auto

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/common-build.xml
    lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/PrefixQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/TermRangeQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/WildcardQuery.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=808519&r1=808518&r2=808519&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Thu Aug 27 16:57:27 2009
@@ -205,6 +205,12 @@
     The usage of the US locale is important to guarantee correct ordering of
     generated terms.  (Uwe Schindler)
 
+15. LUCENE-1860: MultiTermQuery now defaults to
+    CONSTANT_SCORE_AUTO_REWRITE_DEFAULT rewrite method (previously it
+    was SCORING_BOOLEAN_QUERY_REWRITE).  This means that PrefixQuery
+    and WildcardQuery will now produce constant score for all matching
+    docs, equal to the boost of the query.  (Mike McCandless)
+
 API Changes
 
 1. LUCENE-1419: Add expert API to set custom indexing chain. This API is 

Modified: lucene/java/trunk/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/common-build.xml?rev=808519&r1=808518&r2=808519&view=diff
==============================================================================
--- lucene/java/trunk/common-build.xml (original)
+++ lucene/java/trunk/common-build.xml Thu Aug 27 16:57:27 2009
@@ -42,7 +42,7 @@
   <property name="Name" value="Lucene"/>
   <property name="dev.version" value="2.9"/>
   <property name="version" value="${dev.version}"/>
-  <property name="compatibility.tag" value="lucene_2_4_back_compat_tests_20090815"/>
+  <property name="compatibility.tag" value="lucene_2_4_back_compat_tests_20090827"/>
   <property name="spec.version" value="${version}"/>	
   <property name="year" value="2000-${current.year}"/>
   <property name="final.name" value="lucene-${name}-${version}"/>

Modified: lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java?rev=808519&r1=808518&r2=808519&view=diff
==============================================================================
--- lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java
(original)
+++ lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java
Thu Aug 27 16:57:27 2009
@@ -50,8 +50,7 @@
   public Query rewrite(IndexReader reader) throws IOException {
     RegexQuery orig = new RegexQuery(term);
     orig.setRegexImplementation(regexImpl);
-
-    // RegexQuery (via MultiTermQuery).rewrite always returns a BooleanQuery
+    orig.setRewriteMethod(RegexQuery.SCORING_BOOLEAN_QUERY_REWRITE);
     BooleanQuery bq = (BooleanQuery) orig.rewrite(reader);
 
     BooleanClause[] clauses = bq.getClauses();

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java?rev=808519&r1=808518&r2=808519&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java Thu Aug 27 16:57:27
2009
@@ -60,7 +60,7 @@
 public abstract class MultiTermQuery extends Query {
   /* @deprecated move to sub class */
   protected Term term;
-  protected RewriteMethod rewriteMethod = SCORING_BOOLEAN_QUERY_REWRITE;
+  protected RewriteMethod rewriteMethod = CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
   transient int numberOfTerms = 0;
 
   /** Abstract class that defines how the query is rewritten. */

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/PrefixQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/PrefixQuery.java?rev=808519&r1=808518&r2=808519&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/PrefixQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/PrefixQuery.java Thu Aug 27 16:57:27
2009
@@ -26,13 +26,9 @@
 /** A Query that matches documents containing terms with a specified prefix. A PrefixQuery
  * is built by QueryParser for input like <code>app*</code>.
  *
- * <p><b>NOTE</b>: Currently this query uses {@link
- * MultiTermQuery#SCORING_BOOLEAN_QUERY_REWRITE}, which
- * assigns not-very-useful scores to the resulting hits.  In
- * 3.0 this default will change to {@link
- * MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}; you
- * can use {@link MultiTermQuery#setRewriteMethod} to change
- * it. */
+ * <p>This query uses the {@link
+ * MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}
+ * rewrite method. */
 public class PrefixQuery extends MultiTermQuery {
   private Term prefix;
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/TermRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/TermRangeQuery.java?rev=808519&r1=808518&r2=808519&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/TermRangeQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/TermRangeQuery.java Thu Aug 27 16:57:27
2009
@@ -109,7 +109,6 @@
     this.includeLower = includeLower;
     this.includeUpper = includeUpper;
     this.collator = collator;
-    rewriteMethod = CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
   }
 
   /** Returns the field name for this query */

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/WildcardQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/WildcardQuery.java?rev=808519&r1=808518&r2=808519&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/WildcardQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/WildcardQuery.java Thu Aug 27 16:57:27
2009
@@ -30,12 +30,9 @@
  * a Wildcard term should not start with one of the wildcards <code>*</code>
or
  * <code>?</code>.
  * 
- * <p><b>NOTE</b>: Currently this query uses {@link
- * MultiTermQuery#SCORING_BOOLEAN_QUERY_REWRITE}, which
- * assigns not-very-useful scores to the resulting hits.  In
- * 3.0 this default will change to {@link
- * MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}; you can use {@link
- * MultiTermQuery#setRewriteMethod} to change it.
+ * <p>This query uses the {@link
+ * MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}
+ * rewrite method.
  *
  * @see WildcardTermEnum */
 public class WildcardQuery extends MultiTermQuery {

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java?rev=808519&r1=808518&r2=808519&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java Thu Aug
27 16:57:27 2009
@@ -53,7 +53,22 @@
     super(name);
   }
 
-  public void testMethod() {
+  private int getCount(IndexReader r, Query q) throws Exception {
+    if (q instanceof BooleanQuery) {
+      return ((BooleanQuery) q).getClauses().length;
+    } else if (q instanceof ConstantScoreQuery) {
+      DocIdSetIterator iter = ((ConstantScoreQuery) q).getFilter().getDocIdSet(r).iterator();
+      int count = 0;
+      while(iter.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+        count++;
+      }
+      return count;
+    } else {
+      throw new RuntimeException("unepxected query " + q);
+    }
+  }
+
+  public void testMethod() throws Exception {
     RAMDirectory directory = new RAMDirectory();
 
     String[] categories = new String[]{"food",
@@ -63,6 +78,7 @@
 
     Query rw1 = null;
     Query rw2 = null;
+    IndexReader reader = null;
     try {
       IndexWriter writer = new IndexWriter(directory, new
                                            WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
@@ -73,9 +89,8 @@
       }
       writer.close();
       
-      IndexReader reader = IndexReader.open(directory);
+      reader = IndexReader.open(directory);
       PrefixQuery query = new PrefixQuery(new Term("category", "foo"));
-      
       rw1 = query.rewrite(reader);
       
       BooleanQuery bq = new BooleanQuery();
@@ -86,20 +101,7 @@
       fail(e.getMessage());
     }
 
-    BooleanQuery bq1 = null;
-    if (rw1 instanceof BooleanQuery) {
-      bq1 = (BooleanQuery) rw1;
-    }
-
-    BooleanQuery bq2 = null;
-    if (rw2 instanceof BooleanQuery) {
-        bq2 = (BooleanQuery) rw2;
-    } else {
-      fail("Rewrite");
-    }
-
-    assertEquals("Number of Clauses Mismatch", bq1.getClauses().length,
-                 bq2.getClauses().length);
+    assertEquals("Number of Clauses Mismatch", getCount(reader, rw1), getCount(reader, rw2));
   }
 }
 



Mime
View raw message