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, 14 Jan 2002 03:02:39 GMT
briangoetz    02/01/13 19:02:39

  Modified:    src/java/org/apache/lucene/queryParser QueryParser.jj
               src/test/org/apache/lucene/queryParser TestQueryParser.java
  Log:
  Enable boosting on range queries, phrpase queries (I think this used to work, but got broken
when range queries were added); add tests cases for range queries
  
  Revision  Changes    Path
  1.7       +16 -6     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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- QueryParser.jj	13 Nov 2001 19:00:22 -0000	1.6
  +++ QueryParser.jj	14 Jan 2002 03:02:39 -0000	1.7
  @@ -168,7 +168,9 @@
       clauses.addElement(new BooleanClause(q, required, prohibited));
     }
   
  -  private Query getFieldQuery(String field, Analyzer analyzer, String queryText) {
  +  private Query getFieldQuery(String field, 
  +                              Analyzer analyzer, 
  +                              String queryText) {
       // Use the analyzer to get all the tokens, and then build a TermQuery,
       // PhraseQuery, or nothing based on the term count
       
  @@ -202,10 +204,14 @@
       }
     }
   
  -  private Query getRangeQuery(String field, Analyzer analyzer, String queryText, boolean
inclusive) 
  +  private Query getRangeQuery(String field, 
  +                              Analyzer analyzer, 
  +                              String queryText, 
  +                              boolean inclusive) 
     {
       // Use the analyzer to get all the tokens.  There should be 1 or 2.
  -    TokenStream source = analyzer.tokenStream(field, new StringReader(queryText));
  +    TokenStream source = analyzer.tokenStream(field, 
  +                                              new StringReader(queryText));
       Term[] terms = new Term[2];
       org.apache.lucene.analysis.Token t;
   
  @@ -233,7 +239,7 @@
   
     public static void main(String[] args) throws Exception {
       QueryParser qp = new QueryParser("field", 
  -                                     new org.apache.lucene.analysis.SimpleAnalyzer());
  +                           new org.apache.lucene.analysis.SimpleAnalyzer());
       Query q = qp.parse(args[0]);
       System.out.println(q.toString("field"));
     }
  @@ -277,8 +283,8 @@
   | <PREFIXTERM:  <_TERM_START_CHAR> (<_TERM_CHAR>)* "*" >
   | <WILDTERM:  <_TERM_START_CHAR> 
                 (<_TERM_CHAR> | ( [ "*", "?" ] ))* >
  -| <RANGEIN:   "[" (~["]"])+ "]">
  -| <RANGEEX:   "{" (~["}"])+ "}">
  +| <RANGEIN:   "[" ( ~[ "]" ] )+ "]">
  +| <RANGEEX:   "{" ( ~[ "}" ] )+ "}">
   }
   
   <DEFAULT> SKIP : {
  @@ -382,12 +388,14 @@
            q = getFieldQuery(field, analyzer, term.image); 
        }
        | ( term=<RANGEIN> { rangein=true; } | term=<RANGEEX> )
  +       [ <CARAT> boost=<NUMBER> ]
           {
             q = getRangeQuery(field, analyzer, 
                               term.image.substring(1, term.image.length()-1), 
                               rangein);
           }
        | term=<QUOTED> 
  +       [ <CARAT> boost=<NUMBER> ]
          { 
            q = getFieldQuery(field, analyzer, 
                              term.image.substring(1, term.image.length()-1)); 
  @@ -407,6 +415,8 @@
           ((PhraseQuery) q).setBoost(f);
         else if (q instanceof MultiTermQuery)
           ((MultiTermQuery) q).setBoost(f);
  +      else if (q instanceof RangeQuery)
  +        ((RangeQuery) q).setBoost(f);
       }
       return q; 
     }
  
  
  
  1.5       +12 -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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestQueryParser.java	3 Nov 2001 02:33:46 -0000	1.4
  +++ TestQueryParser.java	14 Jan 2002 03:02:39 -0000	1.5
  @@ -158,6 +158,7 @@
       assertQueryEquals("germ term^2.0", null, "germ term^2.0");
       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("(foo OR bar) AND (baz OR boo)", null, 
                         "+(foo bar) +(baz boo)");
  @@ -179,6 +180,17 @@
       assertQueryEquals("term AND NOT phrase term", qpAnalyzer, 
                         "+term -\"phrase1 phrase2\" term");
       assertQueryEquals("stop", qpAnalyzer, "");
  +  }
  +
  +  public void testRange() throws Exception {
  +    assertQueryEquals("[ a z]", null, "[a-z]");
  +    assertQueryEquals("[ a z ]", null, "[a-z]");
  +    assertQueryEquals("{ a z}", null, "{a-z}");
  +    assertQueryEquals("{ a z }", null, "{a-z}");
  +    assertQueryEquals("{ a z }^2.0", null, "{a-z}^2.0");
  +    assertQueryEquals("[ a z] OR bar", null, "[a-z] bar");
  +    assertQueryEquals("[ a z] AND bar", null, "+[a-z] +bar");
  +    assertQueryEquals("( bar blar { a z}) ", null, "(bar blar {a-z})");
     }
   }
   
  
  
  

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