You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by eh...@apache.org on 2004/05/22 19:34:31 UTC

cvs commit: jakarta-lucene/src/java/org/apache/lucene/queryParser QueryParser.jj QueryParser.java

ehatcher    2004/05/22 10:34:31

  Modified:    .        CHANGES.txt
               src/java/org/apache/lucene/queryParser QueryParser.jj
                        QueryParser.java
  Log:
  enhancement to QueryParser to allow slop factor passed to a new getFieldQuery method
  
  Revision  Changes    Path
  1.88      +9 -2      jakarta-lucene/CHANGES.txt
  
  Index: CHANGES.txt
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/CHANGES.txt,v
  retrieving revision 1.87
  retrieving revision 1.88
  diff -u -r1.87 -r1.88
  --- CHANGES.txt	20 May 2004 17:16:56 -0000	1.87
  +++ CHANGES.txt	22 May 2004 17:34:31 -0000	1.88
  @@ -11,6 +11,13 @@
    2. Added new class FieldCache to manage in-memory caches of field term
       values.  (Tim Jones)
   
  + 3. Added overloaded getFieldQuery method to QueryParser which
  +    accepts the slop factor specified for the phrase (or the default
  +    phrase slop for the QueryParser instance).  This allows overriding
  +    methods to replace a PhraseQuery with a SpanNearQuery instead,
  +    keeping the proper slop factor. (Erik Hatcher)
  +
  +
   1.4 RC3
   
    1. Fixed several search bugs introduced by the skipTo() changes in
  @@ -265,7 +272,7 @@
   
    7. Modified QueryParser to make it possible to programmatically specify the
       default Boolean operator (OR or AND).
  -    (P�ter Hal�csy via otis)
  +    (P�ter Hal�csy via otis)
   
    8. Made many search methods and classes non-final, per requests.
       This includes IndexWriter and IndexSearcher, among others.
  
  
  
  1.43      +27 -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.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- QueryParser.jj	24 Mar 2004 10:12:27 -0000	1.42
  +++ QueryParser.jj	22 May 2004 17:34:31 -0000	1.43
  @@ -285,6 +285,26 @@
     }
   
     /**
  +   * Base implementation delegates to {@link #getFieldQuery(String,Analyzer,String)}.
  +   * This method may be overridden, for example, to return
  +   * a SpanNearQuery instead of a PhraseQuery.
  +   *
  +   * @exception ParseException throw in overridden method to disallow
  +   */
  +  protected Query getFieldQuery(String field,
  +                                Analyzer analyzer,
  +                                String queryText,
  +                                int slop)  throws ParseException {
  +    Query query = getFieldQuery(field, analyzer, queryText);
  +
  +    if (query instanceof PhraseQuery) {
  +      ((PhraseQuery) query).setSlop(slop);
  +    }
  +
  +    return query;
  +  }
  +
  +  /**
      * @exception ParseException throw in overridden method to disallow
      */
     protected Query getRangeQuery(String field,
  @@ -655,15 +675,17 @@
          [ slop=<SLOP> ]
          [ <CARAT> boost=<NUMBER> ]
          {
  -         q = getFieldQuery(field, analyzer,
  -                           term.image.substring(1, term.image.length()-1));
  -         if (slop != null && q instanceof PhraseQuery) {
  +         int s = phraseSlop;
  +
  +         if (slop != null) {
              try {
  -             int s = Float.valueOf(slop.image.substring(1)).intValue();
  -             ((PhraseQuery) q).setSlop(s);
  +             s = Float.valueOf(slop.image.substring(1)).intValue();
              }
              catch (Exception ignored) { }
            }
  +         q = getFieldQuery(field, analyzer,
  +                           term.image.substring(1, term.image.length()-1),
  +                           s);
          }
     )
     {
  
  
  
  1.11      +27 -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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- QueryParser.java	3 Mar 2004 12:07:13 -0000	1.10
  +++ QueryParser.java	22 May 2004 17:34:31 -0000	1.11
  @@ -262,6 +262,26 @@
     }
   
     /**
  +   * Base implementation delegates to {@link #getFieldQuery(String,Analyzer,String)}.
  +   * This method may be overridden, for example, to return
  +   * a SpanNearQuery instead of a PhraseQuery.
  +   *
  +   * @exception ParseException throw in overridden method to disallow
  +   */
  +  protected Query getFieldQuery(String field,
  +                                Analyzer analyzer,
  +                                String queryText,
  +                                int slop)  throws ParseException {
  +    Query query = getFieldQuery(field, analyzer, queryText);
  +
  +    if (query instanceof PhraseQuery) {
  +      ((PhraseQuery) query).setSlop(slop);
  +    }
  +
  +    return query;
  +  }
  +
  +  /**
      * @exception ParseException throw in overridden method to disallow
      */
     protected Query getRangeQuery(String field,
  @@ -770,15 +790,17 @@
           jj_la1[20] = jj_gen;
           ;
         }
  -         q = getFieldQuery(field, analyzer,
  -                           term.image.substring(1, term.image.length()-1));
  -         if (slop != null && q instanceof PhraseQuery) {
  +         int s = phraseSlop;
  +
  +         if (slop != null) {
              try {
  -             int s = Float.valueOf(slop.image.substring(1)).intValue();
  -             ((PhraseQuery) q).setSlop(s);
  +             s = Float.valueOf(slop.image.substring(1)).intValue();
              }
              catch (Exception ignored) { }
            }
  +         q = getFieldQuery(field, analyzer,
  +                           term.image.substring(1, term.image.length()-1),
  +                           s);
         break;
       default:
         jj_la1[21] = jj_gen;
  
  
  

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