lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject svn commit: r289556 - in /lucene/java/trunk: ./ src/java/org/apache/lucene/search/spans/
Date Fri, 16 Sep 2005 14:17:36 GMT
Author: ehatcher
Date: Fri Sep 16 07:17:32 2005
New Revision: 289556

URL: http://svn.apache.org/viewcvs?rev=289556&view=rev
Log:
Added rewrite methods to all SpanQuery subclasses that nest SpanQuerys

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/CHANGES.txt?rev=289556&r1=289555&r2=289556&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Sep 16 07:17:32 2005
@@ -144,7 +144,8 @@
     
 20. Added a new class MatchAllDocsQuery that matches all documents.
     (John Wang via Daniel Naber, bug #34946)
-    
+
+
 API Changes
 
  1. Several methods and fields have been deprecated. The API documentation 
@@ -164,6 +165,10 @@
     
  4. Add a serializable Parameter Class to standardize parameter enum
     classes in BooleanClause and Field. (Christoph)
+
+ 5. Added rewrite methods to all SpanQuery subclasses that nest other SpanQuerys.
+    This allows custom SpanQuery subclasses that rewrite (for term expansion, for
+    example) to nest within the built-in SpanQuery classes successfully.
 
 Bug fixes
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java?rev=289556&r1=289555&r2=289556&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java Fri Sep
16 07:17:32 2005
@@ -21,6 +21,7 @@
 import java.util.Collection;
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.Query;
 
 /** Matches spans near the beginning of a field. */
 public class SpanFirstQuery extends SpanQuery {
@@ -87,4 +88,19 @@
       };
   }
 
+  public Query rewrite(IndexReader reader) throws IOException {
+    SpanFirstQuery clone = null;
+
+    SpanQuery rewritten = (SpanQuery) match.rewrite(reader);
+    if (rewritten != match) {
+      clone = (SpanFirstQuery) this.clone();
+      clone.match = rewritten;
+    }
+
+    if (clone != null) {
+      return clone;                        // some clauses rewrote
+    } else {
+      return this;                         // no clauses rewrote
+    }
+  }
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java?rev=289556&r1=289555&r2=289556&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java Fri Sep 16
07:17:32 2005
@@ -25,6 +25,7 @@
 
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.Query;
 
 /** Matches spans which are near one another.  One can specify <i>slop</i>, the
  * maximum number of intervening unmatched positions, as well as whether
@@ -110,6 +111,24 @@
     return new NearSpans(this, reader);
   }
 
+  public Query rewrite(IndexReader reader) throws IOException {
+    SpanNearQuery clone = null;
+    for (int i = 0 ; i < clauses.size(); i++) {
+      SpanQuery c = (SpanQuery)clauses.get(i);
+      SpanQuery query = (SpanQuery) c.rewrite(reader);
+      if (query != c) {                     // clause rewrote: must clone
+        if (clone == null)
+          clone = (SpanNearQuery) this.clone();
+        clone.clauses.set(i,query);
+      }
+    }
+    if (clone != null) {
+      return clone;                        // some clauses rewrote
+    } else {
+      return this;                         // no clauses rewrote
+    }
+  }
+
   /** Returns true iff <code>o</code> is equal to this. */
   public boolean equals(Object o) {
     if (this == o) return true;
@@ -124,7 +143,7 @@
 
     return true;
   }
-  
+
   public int hashCode() {
     int result;
     result = clauses.hashCode();

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java?rev=289556&r1=289555&r2=289556&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNotQuery.java Fri Sep 16
07:17:32 2005
@@ -21,6 +21,7 @@
 import java.util.Collection;
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.Query;
 
 /** Removes matches which overlap with another SpanQuery. */
 public class SpanNotQuery extends SpanQuery {
@@ -125,6 +126,27 @@
         }
 
       };
+  }
+
+  public Query rewrite(IndexReader reader) throws IOException {
+    SpanNotQuery clone = null;
+
+    SpanQuery rewrittenInclude = (SpanQuery) include.rewrite(reader);
+    if (rewrittenInclude != include) {
+      clone = (SpanNotQuery) this.clone();
+      clone.include = rewrittenInclude;
+    }
+    SpanQuery rewrittenExclude = (SpanQuery) exclude.rewrite(reader);
+    if (rewrittenExclude != include) {
+      if (clone == null) clone = (SpanNotQuery) this.clone();
+      clone.exclude = rewrittenExclude;
+    }
+
+    if (clone != null) {
+      return clone;                        // some clauses rewrote
+    } else {
+      return this;                         // no clauses rewrote
+    }
   }
 
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java?rev=289556&r1=289555&r2=289556&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanOrQuery.java Fri Sep 16
07:17:32 2005
@@ -25,6 +25,7 @@
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.util.PriorityQueue;
+import org.apache.lucene.search.Query;
 
 /** Matches the union of its clauses.*/
 public class SpanOrQuery extends SpanQuery {
@@ -62,6 +63,24 @@
       terms.addAll(clause.getTerms());
     }
     return terms;
+  }
+
+  public Query rewrite(IndexReader reader) throws IOException {
+    SpanOrQuery clone = null;
+    for (int i = 0 ; i < clauses.size(); i++) {
+      SpanQuery c = (SpanQuery)clauses.get(i);
+      SpanQuery query = (SpanQuery) c.rewrite(reader);
+      if (query != c) {                     // clause rewrote: must clone
+        if (clone == null)
+          clone = (SpanOrQuery) this.clone();
+        clone.clauses.set(i,query);
+      }
+    }
+    if (clone != null) {
+      return clone;                        // some clauses rewrote
+    } else {
+      return this;                         // no clauses rewrote
+    }
   }
 
   public String toString(String field) {



Mime
View raw message