lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From briango...@apache.org
Subject cvs commit: jakarta-lucene/src/test/org/apache/lucene/queryParser TestQueryParser.java
Date Mon, 06 May 2002 21:59:44 GMT
briangoetz    02/05/06 14:59:44

  Modified:    .        build.xml
               src/java/org/apache/lucene/queryParser QueryParser.jj
               src/test/org/apache/lucene/queryParser TestQueryParser.java
  Log:
  Add escape character to query parser (backslash); add unit test for escape character; wrap
TokenMgrError with ParseException in QueryParser.parse
  
  Revision  Changes    Path
  1.25      +1 -1      jakarta-lucene/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/build.xml,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- build.xml	30 Apr 2002 15:16:18 -0000	1.24
  +++ build.xml	6 May 2002 21:59:44 -0000	1.25
  @@ -198,6 +198,7 @@
     <!-- ================================================================== -->
     <target name="demo" depends="compile" if="javacc.present">
       <mkdir dir="${build.demo}"/>
  +    <mkdir dir="${build.demo.src}" />
   
       <copy todir="${build.demo.src}">
         <fileset dir="${demo.src}">
  @@ -211,7 +212,6 @@
         javacchome="${javacc.zip.dir}"
         outputdirectory="${build.demo.src}/org/apache/lucene/demo/html"
       />
  -
       <mkdir dir="${build.demo.classes}"/>
   
       <javac
  
  
  
  1.16      +14 -7     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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- QueryParser.jj	22 Feb 2002 21:06:16 -0000	1.15
  +++ QueryParser.jj	6 May 2002 21:59:44 -0000	1.16
  @@ -111,12 +111,16 @@
      *  @param field	the default field for query terms.
      *  @param analyzer   used to find terms in the query text.
      *  @throws ParseException if the parsing fails
  -   *  @throws TokenMgrError if the parsing fails
      */
     static public Query parse(String query, String field, Analyzer analyzer)
  -       throws ParseException, TokenMgrError {
  -    QueryParser parser = new QueryParser(field, analyzer);
  -    return parser.parse(query);
  +       throws ParseException {
  +    try {
  +      QueryParser parser = new QueryParser(field, analyzer);
  +      return parser.parse(query);
  +    }
  +    catch (TokenMgrError tme) { 
  +      throw new ParseException(tme.getMessage());
  +    }
     }
          
     Analyzer analyzer;
  @@ -269,9 +273,12 @@
   
   <*> TOKEN : {
     <#_NUM_CHAR:   ["0"-"9"] >
  -| <#_TERM_START_CHAR: ~[ " ", "\t", "+", "-", "!", "(", ")", ":", "^", 
  -                         "[", "]", "\"", "{", "}", "~", "*" ] >
  -| <#_TERM_CHAR: <_TERM_START_CHAR> >
  +| <#_ESCAPED_CHAR: "\\" [ "\\", "+", "-", "!", "(", ")", ":", "^", 
  +                          "[", "]", "\"", "{", "}", "~", "*" ] >
  +| <#_TERM_START_CHAR: ( ~[ " ", "\t", "+", "-", "!", "(", ")", ":", "^", 
  +                           "[", "]", "\"", "{", "}", "~", "*" ] 
  +                       | <_ESCAPED_CHAR> ) >
  +| <#_TERM_CHAR: ( <_TERM_START_CHAR> | <_ESCAPED_CHAR> ) >
   | <#_WHITESPACE: ( " " | "\t" ) >
   }
   
  
  
  
  1.11      +9 -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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestQueryParser.java	19 Feb 2002 00:44:00 -0000	1.10
  +++ TestQueryParser.java	6 May 2002 21:59:44 -0000	1.11
  @@ -246,4 +246,13 @@
       assertQueryEquals("( bar blar { a z}) ", null, "bar blar {a-z}");
       assertQueryEquals("gack ( bar blar { a z}) ", null, "gack (bar blar {a-z})");
     }
  +
  +  public void testEscaped() throws Exception {
  +    Analyzer a = new WhitespaceAnalyzer();
  +    assertQueryEquals("\\[brackets", a, "\\[brackets");
  +    assertQueryEquals("\\[brackets", null, "brackets");
  +    assertQueryEquals("\\\\", a, "\\\\");
  +    assertQueryEquals("\\+blah", a, "\\+blah");
  +    assertQueryEquals("\\(blah", a, "\\(blah");
  +  }
   }
  
  
  

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