lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dna...@apache.org
Subject cvs commit: jakarta-lucene/src/java/org/apache/lucene/queryParser MultiFieldQueryParser.java QueryParser.java QueryParser.jj
Date Fri, 27 Aug 2004 21:50:17 GMT
dnaber      2004/08/27 14:50:17

  Modified:    src/java/org/apache/lucene/queryParser
                        MultiFieldQueryParser.java QueryParser.java
                        QueryParser.jj
  Log:
  don't use the deprecated API for BooleanQuery.add()
  
  Revision  Changes    Path
  1.6       +10 -9     jakarta-lucene/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java
  
  Index: MultiFieldQueryParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MultiFieldQueryParser.java	23 Aug 2004 23:07:41 -0000	1.5
  +++ MultiFieldQueryParser.java	27 Aug 2004 21:50:17 -0000	1.6
  @@ -21,6 +21,7 @@
   import org.apache.lucene.queryParser.ParseException;
   import org.apache.lucene.queryParser.QueryParser;
   import org.apache.lucene.queryParser.QueryParserTokenManager;
  +import org.apache.lucene.search.BooleanClause;
   import org.apache.lucene.search.BooleanQuery;
   import org.apache.lucene.search.Query;
   
  @@ -75,7 +76,7 @@
           for (int i = 0; i < fields.length; i++)
           {
               Query q = parse(query, fields[i], analyzer);
  -            bQuery.add(q, false, false);
  +            bQuery.add(q, BooleanClause.Occur.SHOULD);
           }
           return bQuery;
       }
  @@ -106,7 +107,7 @@
           for (int i = 0; i < fields.length; i++)
           {
               Query q = parse(queries[i], fields[i], analyzer);
  -            bQuery.add(q, false, false);
  +            bQuery.add(q, BooleanClause.Occur.SHOULD);
           }
           return bQuery;
       }
  @@ -153,13 +154,13 @@
               switch (flag)
               {
                   case REQUIRED_FIELD:
  -                    bQuery.add(q, true, false);
  +                    bQuery.add(q, BooleanClause.Occur.MUST);
                       break;
                   case PROHIBITED_FIELD:
  -                    bQuery.add(q, false, true);
  +                    bQuery.add(q, BooleanClause.Occur.MUST_NOT);
                       break;
                   default:
  -                    bQuery.add(q, false, false);
  +                    bQuery.add(q, BooleanClause.Occur.SHOULD);
                       break;
               }
           }
  @@ -210,13 +211,13 @@
               switch (flag)
               {
                   case REQUIRED_FIELD:
  -                    bQuery.add(q, true, false);
  +                    bQuery.add(q, BooleanClause.Occur.MUST);
                       break;
                   case PROHIBITED_FIELD:
  -                    bQuery.add(q, false, true);
  +                    bQuery.add(q, BooleanClause.Occur.MUST_NOT);
                       break;
                   default:
  -                    bQuery.add(q, false, false);
  +                    bQuery.add(q, BooleanClause.Occur.SHOULD);
                       break;
               }
           }
  
  
  
  1.12      +12 -5     jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.java
  
  Index: QueryParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- QueryParser.java	22 May 2004 17:34:31 -0000	1.11
  +++ QueryParser.java	27 Aug 2004 21:50:17 -0000	1.12
  @@ -179,8 +179,8 @@
       // unless it's already prohibited
       if (conj == CONJ_AND) {
         BooleanClause c = (BooleanClause) clauses.elementAt(clauses.size()-1);
  -      if (!c.prohibited)
  -        c.required = true;
  +      if (!c.isProhibited())
  +        c.setOccur(BooleanClause.Occur.MUST);
       }
   
       if (operator == DEFAULT_OPERATOR_AND && conj == CONJ_OR) {
  @@ -189,8 +189,8 @@
         // notice if the input is a OR b, first term is parsed as required; without
         // this modification a OR b would parsed as +a OR b
         BooleanClause c = (BooleanClause) clauses.elementAt(clauses.size()-1);
  -      if (!c.prohibited)
  -        c.required = false;
  +      if (!c.isProhibited())
  +        c.setOccur(BooleanClause.Occur.SHOULD);
       }
   
       // We might have been passed a null query; the term might have been
  @@ -212,7 +212,14 @@
         prohibited = (mods == MOD_NOT);
         required   = (!prohibited && conj != CONJ_OR);
       }
  -    clauses.addElement(new BooleanClause(q, required, prohibited));
  +    if (required && !prohibited)
  +      clauses.addElement(new BooleanClause(q, BooleanClause.Occur.MUST));
  +    else if (!required && !prohibited)
  +      clauses.addElement(new BooleanClause(q, BooleanClause.Occur.SHOULD));
  +    else if (!required && prohibited)
  +      clauses.addElement(new BooleanClause(q, BooleanClause.Occur.MUST_NOT));
  +    else
  +      throw new RuntimeException("Clause cannot be both required and prohibited");
     }
   
     /**
  
  
  
  1.44      +12 -5     jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.jj
  
  Index: QueryParser.jj
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.jj,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- QueryParser.jj	22 May 2004 17:34:31 -0000	1.43
  +++ QueryParser.jj	27 Aug 2004 21:50:17 -0000	1.44
  @@ -202,8 +202,8 @@
       // unless it's already prohibited
       if (conj == CONJ_AND) {
         BooleanClause c = (BooleanClause) clauses.elementAt(clauses.size()-1);
  -      if (!c.prohibited)
  -        c.required = true;
  +      if (!c.isProhibited())
  +        c.setOccur(BooleanClause.Occur.MUST);
       }
   
       if (operator == DEFAULT_OPERATOR_AND && conj == CONJ_OR) {
  @@ -212,8 +212,8 @@
         // notice if the input is a OR b, first term is parsed as required; without
         // this modification a OR b would parsed as +a OR b
         BooleanClause c = (BooleanClause) clauses.elementAt(clauses.size()-1);
  -      if (!c.prohibited)
  -        c.required = false;
  +      if (!c.isProhibited())
  +        c.setOccur(BooleanClause.Occur.SHOULD);
       }
   
       // We might have been passed a null query; the term might have been
  @@ -235,7 +235,14 @@
         prohibited = (mods == MOD_NOT);
         required   = (!prohibited && conj != CONJ_OR);
       }
  -    clauses.addElement(new BooleanClause(q, required, prohibited));
  +    if (required && !prohibited)
  +      clauses.addElement(new BooleanClause(q, BooleanClause.Occur.MUST));
  +    else if (!required && !prohibited)
  +      clauses.addElement(new BooleanClause(q, BooleanClause.Occur.SHOULD));
  +    else if (!required && prohibited)
  +      clauses.addElement(new BooleanClause(q, BooleanClause.Occur.MUST_NOT));
  +    else
  +      throw new RuntimeException("Clause cannot be both required and prohibited");
     }
   
     /**
  
  
  

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


Mime
View raw message