lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject cvs commit: jakarta-lucene/src/test/org/apache/lucene/queryParser TestQueryParser.java
Date Wed, 03 Mar 2004 12:07:13 GMT
otis        2004/03/03 04:07:13

  Modified:    src/java/org/apache/lucene/queryParser QueryParser.java
                        QueryParser.jj QueryParserTokenManager.java
               src/test/org/apache/lucene/queryParser TestQueryParser.java
  Log:
  - Applied a patch that treats \n and \r characters in query strings the same
    way that \t and " " are treated.
    http://issues.apache.org/bugzilla/show_bug.cgi?id=18847
    Contributed by Daniel Naber
  
  Revision  Changes    Path
  1.10      +25 -25    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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- QueryParser.java	3 Mar 2004 11:24:48 -0000	1.9
  +++ QueryParser.java	3 Mar 2004 12:07:13 -0000	1.10
  @@ -76,8 +76,8 @@
     Locale locale = Locale.getDefault();
   
     /** Parses a query string, returning a {@link org.apache.lucene.search.Query}.
  -   *  @param query	the query string to be parsed.
  -   *  @param field	the default field for query terms.
  +   *  @param query  the query string to be parsed.
  +   *  @param field  the default field for query terms.
      *  @param analyzer   used to find terms in the query text.
      *  @throws ParseException if the parsing fails
      */
  @@ -88,7 +88,7 @@
     }
   
     /** Constructs a query parser.
  -   *  @param f	the default field for query terms.
  +   *  @param f  the default field for query terms.
      *  @param a   used to find terms in the query text.
      */
     public QueryParser(String f, Analyzer a) {
  @@ -99,7 +99,7 @@
   
     /** Parses a query string, returning a
      * <a href="lucene.search.Query.html">Query</a>.
  -   *  @param query	the query string to be parsed.
  +   *  @param query  the query string to be parsed.
      *  @throws ParseException if the parsing fails
      */
     public Query parse(String query) throws ParseException {
  @@ -302,7 +302,7 @@
     {
       BooleanQuery query = new BooleanQuery();
       for (int i = 0; i < clauses.size(); i++) {
  -        query.add((BooleanClause)clauses.elementAt(i));
  +  query.add((BooleanClause)clauses.elementAt(i));
       }
       return query;
     }
  @@ -331,7 +331,7 @@
     protected Query getWildcardQuery(String field, String termStr) throws ParseException
     {
       if (lowercaseWildcardTerms) {
  -        termStr = termStr.toLowerCase();
  +  termStr = termStr.toLowerCase();
       }
       Term t = new Term(field, termStr);
       return new WildcardQuery(t);
  @@ -363,7 +363,7 @@
     protected Query getPrefixQuery(String field, String termStr) throws ParseException
     {
       if (lowercaseWildcardTerms) {
  -        termStr = termStr.toLowerCase();
  +  termStr = termStr.toLowerCase();
       }
       Term t = new Term(field, termStr);
       return new PrefixQuery(t);
  @@ -511,7 +511,7 @@
         if (clauses.size() == 1 && firstQuery != null)
           {if (true) return firstQuery;}
         else {
  -        {if (true) return getBooleanQuery(clauses);}
  +  {if (true) return getBooleanQuery(clauses);}
         }
       throw new Error("Missing return statement in function");
     }
  @@ -522,7 +522,7 @@
       if (jj_2_1(2)) {
         fieldToken = jj_consume_token(TERM);
         jj_consume_token(COLON);
  -        field=discardEscapeChar(fieldToken.image);
  +      field=discardEscapeChar(fieldToken.image);
       } else {
         ;
       }
  @@ -557,10 +557,10 @@
       }
         if (boost != null) {
           float f = (float)1.0;
  -        try {
  -          f = Float.valueOf(boost.image).floatValue();
  +  try {
  +    f = Float.valueOf(boost.image).floatValue();
             q.setBoost(f);
  -        } catch (Exception ignored) { }
  +  } catch (Exception ignored) { }
         }
         {if (true) return q;}
       throw new Error("Missing return statement in function");
  @@ -627,11 +627,11 @@
         }
          String termImage=discardEscapeChar(term.image);
          if (wildcard) {
  -             q = getWildcardQuery(field, termImage);
  +       q = getWildcardQuery(field, termImage);
          } else if (prefix) {
            q = getPrefixQuery(field,
  -                discardEscapeChar(term.image.substring
  -                            (0, term.image.length()-1)));
  +           discardEscapeChar(term.image.substring
  +          (0, term.image.length()-1)));
          } else if (fuzzy) {
            q = getFuzzyQuery(field, termImage);
          } else {
  @@ -685,13 +685,13 @@
             if (goop1.kind == RANGEIN_QUOTED) {
               goop1.image = goop1.image.substring(1, goop1.image.length()-1);
             } else {
  -                goop1.image = discardEscapeChar(goop1.image);
  +            goop1.image = discardEscapeChar(goop1.image);
             }
             if (goop2.kind == RANGEIN_QUOTED) {
               goop2.image = goop2.image.substring(1, goop2.image.length()-1);
  -                  } else {
  -                        goop2.image = discardEscapeChar(goop2.image);
  -                  }
  +      } else {
  +        goop2.image = discardEscapeChar(goop2.image);
  +      }
             q = getRangeQuery(field, analyzer, goop1.image, goop2.image, true);
         break;
       case RANGEEX_START:
  @@ -745,9 +745,9 @@
             }
             if (goop2.kind == RANGEEX_QUOTED) {
               goop2.image = goop2.image.substring(1, goop2.image.length()-1);
  -                  } else {
  -                        goop2.image = discardEscapeChar(goop2.image);
  -                  }
  +      } else {
  +        goop2.image = discardEscapeChar(goop2.image);
  +      }
   
             q = getRangeQuery(field, analyzer, goop1.image, goop2.image, false);
         break;
  @@ -791,9 +791,9 @@
           f = Float.valueOf(boost.image).floatValue();
         }
         catch (Exception ignored) {
  -          /* Should this be handled somehow? (defaults to "no boost", if
  -	   * boost number is invalid)
  -	   */
  +    /* Should this be handled somehow? (defaults to "no boost", if
  +     * boost number is invalid)
  +     */
         }
   
         // avoid boosting null queries, such as those caused by stop words
  
  
  
  1.41      +2 -2      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.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- QueryParser.jj	3 Mar 2004 11:24:48 -0000	1.40
  +++ QueryParser.jj	3 Mar 2004 12:07:13 -0000	1.41
  @@ -443,11 +443,11 @@
     <#_NUM_CHAR:   ["0"-"9"] >
   | <#_ESCAPED_CHAR: "\\" [ "\\", "+", "-", "!", "(", ")", ":", "^",
                             "[", "]", "\"", "{", "}", "~", "*", "?" ] >
  -| <#_TERM_START_CHAR: ( ~[ " ", "\t", "+", "-", "!", "(", ")", ":", "^",
  +| <#_TERM_START_CHAR: ( ~[ " ", "\t", "\n", "\r", "+", "-", "!", "(", ")", ":", "^",
                              "[", "]", "\"", "{", "}", "~", "*", "?" ]
                          | <_ESCAPED_CHAR> ) >
   | <#_TERM_CHAR: ( <_TERM_START_CHAR> | <_ESCAPED_CHAR> ) >
  -| <#_WHITESPACE: ( " " | "\t" ) >
  +| <#_WHITESPACE: ( " " | "\t" | "\n" | "\r") >
   }
   
   <DEFAULT, RangeIn, RangeEx> SKIP : {
  
  
  
  1.2       +8 -8      jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java
  
  Index: QueryParserTokenManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- QueryParserTokenManager.java	11 Sep 2003 01:51:33 -0000	1.1
  +++ QueryParserTokenManager.java	3 Mar 2004 12:07:13 -0000	1.2
  @@ -121,13 +121,13 @@
               switch(jjstateSet[--i])
               {
                  case 0:
  -                  if ((0x7bffd0f8fffffdffL & l) != 0L)
  +                  if ((0x7bffd0f8ffffd9ffL & l) != 0L)
                     {
                        if (kind > 17)
                           kind = 17;
                        jjCheckNAddStates(0, 6);
                     }
  -                  else if ((0x100000200L & l) != 0L)
  +                  else if ((0x100002600L & l) != 0L)
                     {
                        if (kind > 6)
                           kind = 6;
  @@ -174,14 +174,14 @@
                     jjstateSet[jjnewStateCnt++] = 18;
                     break;
                  case 19:
  -                  if ((0x7bffd0f8fffffdffL & l) == 0L)
  +                  if ((0x7bffd0f8ffffd9ffL & l) == 0L)
                        break;
                     if (kind > 17)
                        kind = 17;
                     jjCheckNAddStates(0, 6);
                     break;
                  case 20:
  -                  if ((0x7bffd0f8fffffdffL & l) == 0L)
  +                  if ((0x7bffd0f8ffffd9ffL & l) == 0L)
                        break;
                     if (kind > 17)
                        kind = 17;
  @@ -195,7 +195,7 @@
                     jjCheckNAddTwoStates(20, 21);
                     break;
                  case 23:
  -                  if ((0x7bffd0f8fffffdffL & l) != 0L)
  +                  if ((0x7bffd0f8ffffd9ffL & l) != 0L)
                        jjCheckNAddStates(7, 9);
                     break;
                  case 24:
  @@ -207,7 +207,7 @@
                        jjCheckNAddStates(7, 9);
                     break;
                  case 27:
  -                  if ((0xfbffd4f8fffffdffL & l) == 0L)
  +                  if ((0xfbffd4f8ffffd9ffL & l) == 0L)
                        break;
                     if (kind > 21)
                        kind = 21;
  @@ -501,7 +501,7 @@
                           kind = 32;
                        jjCheckNAdd(4);
                     }
  -                  if ((0x100000200L & l) != 0L)
  +                  if ((0x100002600L & l) != 0L)
                     {
                        if (kind > 6)
                           kind = 6;
  @@ -761,7 +761,7 @@
                           kind = 28;
                        jjCheckNAdd(4);
                     }
  -                  if ((0x100000200L & l) != 0L)
  +                  if ((0x100002600L & l) != 0L)
                     {
                        if (kind > 6)
                           kind = 6;
  
  
  
  1.25      +36 -0     jakarta-lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java
  
  Index: TestQueryParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- TestQueryParser.java	3 Mar 2004 11:24:49 -0000	1.24
  +++ TestQueryParser.java	3 Mar 2004 12:07:13 -0000	1.25
  @@ -371,6 +371,42 @@
   	assertQueryEquals("[ a\\\\ TO a\\* ]", null, "[a\\ TO a*]");
     }
   
  +  public void testTabNewlineCarriageReturn()
  +    throws Exception {
  +    assertQueryEqualsDOA("+weltbank +worlbank", null,
  +      "+weltbank +worlbank");
  +
  +    assertQueryEqualsDOA("+weltbank\n+worlbank", null,
  +      "+weltbank +worlbank");
  +    assertQueryEqualsDOA("weltbank \n+worlbank", null,
  +      "+weltbank +worlbank");
  +    assertQueryEqualsDOA("weltbank \n +worlbank", null,
  +      "+weltbank +worlbank");
  +
  +    assertQueryEqualsDOA("+weltbank\r+worlbank", null,
  +      "+weltbank +worlbank");
  +    assertQueryEqualsDOA("weltbank \r+worlbank", null,
  +      "+weltbank +worlbank");
  +    assertQueryEqualsDOA("weltbank \r +worlbank", null,
  +      "+weltbank +worlbank");
  +
  +    assertQueryEqualsDOA("+weltbank\r\n+worlbank", null,
  +      "+weltbank +worlbank");
  +    assertQueryEqualsDOA("weltbank \r\n+worlbank", null,
  +      "+weltbank +worlbank");
  +    assertQueryEqualsDOA("weltbank \r\n +worlbank", null,
  +      "+weltbank +worlbank");
  +    assertQueryEqualsDOA("weltbank \r \n +worlbank", null,
  +      "+weltbank +worlbank");
  +
  +    assertQueryEqualsDOA("+weltbank\t+worlbank", null,
  +      "+weltbank +worlbank");
  +    assertQueryEqualsDOA("weltbank \t+worlbank", null,
  +      "+weltbank +worlbank");
  +    assertQueryEqualsDOA("weltbank \t +worlbank", null,
  +      "+weltbank +worlbank");
  +  }
  +
     public void testSimpleDAO()
       throws Exception {
       assertQueryEqualsDOA("term term term", null, "+term +term +term");
  
  
  

---------------------------------------------------------------------
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