lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject cvs commit: jakarta-lucene/src/java/org/apache/lucene/search BooleanQuery.java
Date Mon, 20 Jan 2003 19:01:32 GMT
cutting     2003/01/20 11:01:31

  Modified:    src/java/org/apache/lucene/search BooleanQuery.java
  Log:
  Optimized last fix so that the BooleanQuery is only cloned when one of its clauses has rewritten.
  
  Revision  Changes    Path
  1.13      +15 -12    jakarta-lucene/src/java/org/apache/lucene/search/BooleanQuery.java
  
  Index: BooleanQuery.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/BooleanQuery.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- BooleanQuery.java	20 Jan 2003 18:40:19 -0000	1.12
  +++ BooleanQuery.java	20 Jan 2003 19:01:31 -0000	1.13
  @@ -202,26 +202,29 @@
       if (clauses.size() == 1) {                    // optimize 1-clause queries
         BooleanClause c = (BooleanClause)clauses.elementAt(0);
         if (!c.prohibited) {			  // just return clause
  -        Query clone = (Query)c.query.clone();     // have to clone to boost
  -        clone.setBoost(getBoost() * clone.getBoost());
  -        return clone;
  +        Query query = c.query;
  +        if (getBoost() != 1.0f) {                 // have to clone to boost
  +          query = (Query)query.clone();
  +          query.setBoost(getBoost() * query.getBoost());
  +        }
  +        return query;
         }
       }
   
  -    BooleanQuery clone = (BooleanQuery)this.clone(); // recursively clone
  -    boolean changed = false;
  +    BooleanQuery clone = null;                    // recursively rewrite
       for (int i = 0 ; i < clauses.size(); i++) {
         BooleanClause c = (BooleanClause)clauses.elementAt(i);
  -      Query q = c.query.rewrite(reader);
  -      if (q != c.query) {                         // rewrote
  -        changed = true;                           // replace in clone
  +      Query query = c.query.rewrite(reader);
  +      if (query != c.query) {                     // clause rewrote: must clone
  +        if (clone == null)
  +          clone = (BooleanQuery)this.clone();
           clone.clauses.setElementAt
  -          (new BooleanClause(q, c.required, c.prohibited), i);
  +          (new BooleanClause(query, c.required, c.prohibited), i);
         }
       }
  -    if (changed)
  -      return clone;                               // clauses rewrote
  -    else
  +    if (clone != null) {
  +      return clone;                               // some clauses rewrote
  +    } else
         return this;                                // no clauses rewrote
     }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>


Mime
View raw message