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 Tue, 19 Feb 2002 00:44:01 GMT
briangoetz    02/02/18 16:44:00

  Modified:    src/java/org/apache/lucene/queryParser QueryParser.jj
               src/java/org/apache/lucene/search PhraseQuery.java
               src/test/org/apache/lucene/queryParser TestQueryParser.java
  Log:
  Add ~N syntax to phrase queries in query parser to allow for user-settable slop
  
  Revision  Changes    Path
  1.14      +10 -1     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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- QueryParser.jj	15 Feb 2002 02:55:46 -0000	1.13
  +++ QueryParser.jj	19 Feb 2002 00:44:00 -0000	1.14
  @@ -288,6 +288,7 @@
   | <QUOTED:     "\"" (~["\""])+ "\"">
   | <TERM:      <_TERM_START_CHAR> (<_TERM_CHAR>)*  >
   | <FUZZY:     "~" >
  +| <SLOP:      "~" (<_NUM_CHAR>)+ >
   | <PREFIXTERM:  <_TERM_START_CHAR> (<_TERM_CHAR>)* "*" >
   | <WILDTERM:  <_TERM_START_CHAR> 
                 (<_TERM_CHAR> | ( [ "*", "?" ] ))* >
  @@ -375,7 +376,7 @@
       
   
   Query Term(String field) : { 
  -  Token term, boost=null;
  +  Token term, boost=null, slop=null;
     boolean prefix = false;
     boolean wildcard = false;
     boolean fuzzy = false;
  @@ -411,10 +412,18 @@
                               rangein);
           }
        | term=<QUOTED> 
  +       [ slop=<SLOP> ]
          [ <CARAT> boost=<NUMBER> ]
          { 
            q = getFieldQuery(field, analyzer, 
                              term.image.substring(1, term.image.length()-1)); 
  +         if (slop != null && q instanceof PhraseQuery) {
  +           try { 
  +             int s = Float.valueOf(slop.image.substring(1)).intValue();
  +             ((PhraseQuery) q).setSlop(s);
  +           }
  +           catch (Exception ignored) { }
  +         }
          }
     )
     { 
  
  
  
  1.3       +5 -0      jakarta-lucene/src/java/org/apache/lucene/search/PhraseQuery.java
  
  Index: PhraseQuery.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/PhraseQuery.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PhraseQuery.java	17 Jan 2002 02:00:09 -0000	1.2
  +++ PhraseQuery.java	19 Feb 2002 00:44:00 -0000	1.3
  @@ -163,6 +163,11 @@
       }
       buffer.append("\"");
   
  +    if (slop != 0) {
  +      buffer.append("~");
  +      buffer.append(slop);
  +    }
  +
       if (boost != 1.0f) {
         buffer.append("^");
         buffer.append(Float.toString(boost));
  
  
  
  1.10      +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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestQueryParser.java	28 Jan 2002 20:25:20 -0000	1.9
  +++ TestQueryParser.java	19 Feb 2002 00:44:00 -0000	1.10
  @@ -166,6 +166,7 @@
       assertQueryEquals("term^2.0", null, "term^2.0");
       assertQueryEquals("term^2", null, "term^2.0");
       assertQueryEquals("\"germ term\"^2.0", null, "\"germ term\"^2.0");
  +    assertQueryEquals("\"term germ\"^2", null, "\"term germ\"^2.0");
   
       assertQueryEquals("(foo OR bar) AND (baz OR boo)", null, 
                         "+(foo bar) +(baz boo)");
  @@ -182,6 +183,14 @@
       assertQueryEquals("a&b", a, "a&b");
       assertQueryEquals("a&&b", a, "a&&b");
       assertQueryEquals(".NET", a, ".NET");
  +  }
  +
  +  public void testSlop() throws Exception {
  +    assertQueryEquals("\"term germ\"~2", null, "\"term germ\"~2");
  +    assertQueryEquals("\"term germ\"~2 flork", null, "\"term germ\"~2 flork");
  +    assertQueryEquals("\"term\"~2", null, "term");
  +    assertQueryEquals("\" \"~2 germ", null, "germ");
  +    assertQueryEquals("\"term germ\"~2^2", null, "\"term germ\"~2^2.0");
     }
   
     public void testNumber() throws Exception {
  
  
  

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