lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r487931 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/search/BooleanQuery.java
Date Sun, 17 Dec 2006 02:40:38 GMT
Author: yonik
Date: Sat Dec 16 18:40:37 2006
New Revision: 487931

URL: http://svn.apache.org/viewvc?view=rev&rev=487931
Log:
replace Vector with ArrayList, add clauses() to return that List of clauses: LUCENE-745

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=diff&rev=487931&r1=487930&r2=487931
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Sat Dec 16 18:40:37 2006
@@ -310,6 +310,10 @@
      of norms of segments with no deleted docs.
     (Michael Busch via Yonik Seeley)
 
+ 15. LUCENE-745: Add BooleanQuery.clauses(), allowing direct access
+     to the List of clauses and replaced the internal synchronized Vector
+     with an unsynchronized List. (Yonik Seeley)
+
 Test Cases
   1. Added TestTermScorer.java (Grant Ingersoll)
   2. Added TestWindowsMMap.java (Benson Margulies via Mike McCandless)

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java?view=diff&rev=487931&r1=487930&r2=487931
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java Sat Dec 16 18:40:37
2006
@@ -22,9 +22,7 @@
 import org.apache.lucene.search.BooleanClause.Occur;
 
 import java.io.IOException;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.Vector;
+import java.util.*;
 
 /** A Query that matches documents matching boolean combinations of other
   * queries, e.g. {@link TermQuery}s, {@link PhraseQuery}s or other
@@ -75,7 +73,7 @@
     BooleanQuery.maxClauseCount = maxClauseCount;
   }
 
-  private Vector clauses = new Vector();
+  private ArrayList clauses = new ArrayList();
   private boolean disableCoord;
 
   /** Constructs an empty boolean query. */
@@ -166,14 +164,17 @@
     if (clauses.size() >= maxClauseCount)
       throw new TooManyClauses();
 
-    clauses.addElement(clause);
+    clauses.add(clause);
   }
 
   /** Returns the set of clauses in this query. */
   public BooleanClause[] getClauses() {
-    return (BooleanClause[])clauses.toArray(new BooleanClause[0]);
+    return (BooleanClause[])clauses.toArray(new BooleanClause[clauses.size()]);
   }
 
+  /** Returns the list of clauses in this query. */
+  public List clauses() { return clauses; }
+
   private class BooleanWeight implements Weight {
     protected Similarity similarity;
     protected Vector weights = new Vector();
@@ -182,7 +183,7 @@
       throws IOException {
       this.similarity = getSimilarity(searcher);
       for (int i = 0 ; i < clauses.size(); i++) {
-        BooleanClause c = (BooleanClause)clauses.elementAt(i);
+        BooleanClause c = (BooleanClause)clauses.get(i);
         weights.add(c.getQuery().createWeight(searcher));
       }
     }
@@ -193,7 +194,7 @@
     public float sumOfSquaredWeights() throws IOException {
       float sum = 0.0f;
       for (int i = 0 ; i < weights.size(); i++) {
-        BooleanClause c = (BooleanClause)clauses.elementAt(i);
+        BooleanClause c = (BooleanClause)clauses.get(i);
         Weight w = (Weight)weights.elementAt(i);
         // call sumOfSquaredWeights for all clauses in case of side effects
         float s = w.sumOfSquaredWeights();         // sum sub weights
@@ -211,7 +212,7 @@
     public void normalize(float norm) {
       norm *= getBoost();                         // incorporate boost
       for (int i = 0 ; i < weights.size(); i++) {
-        BooleanClause c = (BooleanClause)clauses.elementAt(i);
+        BooleanClause c = (BooleanClause)clauses.get(i);
         Weight w = (Weight)weights.elementAt(i);
         // normalize all clauses, (even if prohibited in case of side affects)
         w.normalize(norm);
@@ -229,7 +230,7 @@
       boolean allRequired = true;
       boolean noneBoolean = true;
       for (int i = 0 ; i < weights.size(); i++) {
-        BooleanClause c = (BooleanClause)clauses.elementAt(i);
+        BooleanClause c = (BooleanClause)clauses.get(i);
         if (!c.isRequired())
           allRequired = false;
         if (c.getQuery() instanceof BooleanQuery)
@@ -253,7 +254,7 @@
       BooleanScorer result = new BooleanScorer(similarity);
 
       for (int i = 0 ; i < weights.size(); i++) {
-        BooleanClause c = (BooleanClause)clauses.elementAt(i);
+        BooleanClause c = (BooleanClause)clauses.get(i);
         Weight w = (Weight)weights.elementAt(i);
         Scorer subScorer = w.scorer(reader);
         if (subScorer != null)
@@ -277,7 +278,7 @@
       boolean fail = false;
       int shouldMatchCount = 0;
       for (int i = 0 ; i < weights.size(); i++) {
-        BooleanClause c = (BooleanClause)clauses.elementAt(i);
+        BooleanClause c = (BooleanClause)clauses.get(i);
         Weight w = (Weight)weights.elementAt(i);
         Explanation e = w.explain(reader, doc);
         if (!c.isProhibited()) maxCoord++;
@@ -349,7 +350,7 @@
                                                  minNrShouldMatch);
 
       for (int i = 0 ; i < weights.size(); i++) {
-        BooleanClause c = (BooleanClause)clauses.elementAt(i);
+        BooleanClause c = (BooleanClause)clauses.get(i);
         Weight w = (Weight)weights.elementAt(i);
         Scorer subScorer = w.scorer(reader);
         if (subScorer != null)
@@ -386,7 +387,7 @@
 
   public Query rewrite(IndexReader reader) throws IOException {
     if (clauses.size() == 1) {                    // optimize 1-clause queries
-      BooleanClause c = (BooleanClause)clauses.elementAt(0);
+      BooleanClause c = (BooleanClause)clauses.get(0);
       if (!c.isProhibited()) {			  // just return clause
 
         Query query = c.getQuery().rewrite(reader);    // rewrite first
@@ -403,13 +404,12 @@
 
     BooleanQuery clone = null;                    // recursively rewrite
     for (int i = 0 ; i < clauses.size(); i++) {
-      BooleanClause c = (BooleanClause)clauses.elementAt(i);
+      BooleanClause c = (BooleanClause)clauses.get(i);
       Query query = c.getQuery().rewrite(reader);
       if (query != c.getQuery()) {                     // clause rewrote: must clone
         if (clone == null)
           clone = (BooleanQuery)this.clone();
-        clone.clauses.setElementAt
-          (new BooleanClause(query, c.getOccur()), i);
+        clone.clauses.set(i, new BooleanClause(query, c.getOccur()));
       }
     }
     if (clone != null) {
@@ -428,7 +428,7 @@
 
   public Object clone() {
     BooleanQuery clone = (BooleanQuery)super.clone();
-    clone.clauses = (Vector)this.clauses.clone();
+    clone.clauses = (ArrayList)this.clauses.clone();
     return clone;
   }
 
@@ -441,7 +441,7 @@
     }
 
     for (int i = 0 ; i < clauses.size(); i++) {
-      BooleanClause c = (BooleanClause)clauses.elementAt(i);
+      BooleanClause c = (BooleanClause)clauses.get(i);
       if (c.isProhibited())
         buffer.append("-");
       else if (c.isRequired())



Mime
View raw message