lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Otis Gospodnetic <otis_gospodne...@yahoo.com>
Subject Re: Default conjuction behaviour
Date Mon, 16 Sep 2002 13:53:41 GMT
Hello,

This functionality should already be in the QueryParser that is in CVS.
I'm not sure if the QueryParser in CVS checks the operators as much as
yours does...

Otis



--- Norbert_Pabiķ <npabis@e-point.pl> wrote:
> Hi,
> 
> Now conjuction behaviour in lucene is always set to OR.
> In my work I need to set it during runtime.
> It is easy with my patched QueryParser.
> 
> Please have a look at the patch and say what you think of it.
> Maybe it is a good idea to include such a funcionality into Lucene?
> 
> -- 
> Norbert Pabiķ
> > --- /tmp/uu/QueryParser.jj	Sun Jun  9 22:47:55 2002
> +++ ./QueryParser.jj	Mon Sep 16 14:09:36 2002
> @@ -106,6 +106,10 @@
>   */
>  
>  public class QueryParser {
> +
> +  /** Default conjunction behaviour. */
> +  private int conjunctionBehaviour = CONJ_OR;
> +
>    /** 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.
> @@ -122,7 +126,38 @@
>        throw new ParseException(tme.getMessage());
>      }
>    }
> -       
> +
> +  /** Parses a query string, returning a {@link
> org.apache.lucene.search.Query}.
> +   * Enables setting default conjunction behaviour set.
> +   * @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.
> +   * @param conjunctionBehaviour default conjunction behaviour 
> +   * (NONE, OR, AND)
> +   *  @throws ParseException if the parsing fails
> +   */       
> +  public static Query parse(String query, String field, Analyzer
> analyzer, int conjunctionBehaviour)
> +        throws ParseException, IllegalArgumentException {
> +    if (conjunctionBehaviour != CONJ_NONE && 
> +        conjunctionBehaviour != CONJ_AND && 
> +        conjunctionBehaviour != CONJ_OR) {
> +        throw new IllegalArgumentException("Illegal conjunction
> behaviour:" + conjunctionBehaviour);
> +    } else {
> +        QueryParser queryparser = new QueryParser(field, analyzer);
> +        queryparser.setConjuctionBehaviour(conjunctionBehaviour);
> +
> +        return queryparser.parse(query);
> +    }
> +  }
> +
> +  /** Sets default conjunction behaviour.
> +   * @param conjunctionBehaviour default conjunction behaviour 
> +   * (NONE, OR, AND)
> +   */       
> +  public void setConjuctionBehaviour(int conjunctionBehaviour) {
> +    this.conjunctionBehaviour = conjunctionBehaviour;
> +  }
> +
>    Analyzer analyzer;
>    String field;
>    int phraseSlop = 0;
> @@ -256,9 +291,9 @@
>      System.out.println(q.toString("field"));
>    }
>  
> -  private static final int CONJ_NONE   = 0;
> -  private static final int CONJ_AND    = 1;
> -  private static final int CONJ_OR     = 2;
> +  public static final int CONJ_NONE   = 0;
> +  public static final int CONJ_AND    = 1;
> +  public static final int CONJ_OR     = 2;
>  
>    private static final int MOD_NONE    = 0;
>    private static final int MOD_NOT     = 10;
> @@ -315,7 +350,7 @@
>  // *   Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )
>  
>  int Conjunction() : { 
> -  int ret = CONJ_NONE;
> +  int ret = conjunctionBehaviour;
>  }
>  {
>    [ 
> 
> > --
> To unsubscribe, e-mail:  
> <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:lucene-dev-help@jakarta.apache.org>


__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com

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