lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Huang <metapr...@yahoo.com>
Subject Re: Question: force a field must be matched?
Date Thu, 15 Sep 2005 18:56:18 GMT
Yes, "+" is what I missed! Thanks.

Suppose there is a book published by 3 publishers (I
don't know how that works in real world):

// At index time:
  doc.add( Field.Keyword("publisher", "Manning") );
  doc.add( Field.Keyword("publisher", "SAMS") );
  doc.add( Field.Keyword("publisher", "O'Reilly") );

// At search time:
  queryString += " +publisher:SAMS";
  ...

should find me that Document.


--- Chris Hostetter <hossman_lucene@fucit.org> wrote:

> : I wonder if that's the same as
> :
> :   queryString + " publisher:Manning"
> :
> : and pass on to the query parser?
> 
> assuming queryString is a java variable containing
> your initial query,
> then you are close, but not quite.  If you want to
> tell QueryParser to
> make a clause "required" then you have to prefice it
> with a "+".
> 
> something like...
> 
>   String userQueryString = ...;
>   String queryString = userQueryString + "
> +publisher:Manning";
> 
> ...is probably what you want.
> 
> Alternately, instead of giving QueryParser a string
> you have built up
> from little pieces, I would recommend that you let
> QueryParser build a
> Query just off of the user input, and then either:
> 
>   a) Filter that query at search time (take a look
> at the Filter class and
>      it's subclasses)
>   b) Modify the Query object returned by the
> QueryParser -- either adding
>      a mandatory clause to it if it's a
> BooleanQuery, or wrapping it in a
>      new BooleanQuery that already contains your
> required clause.
> 
> 
> -Hoss
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail:
> java-user-help@lucene.apache.org
> 
> 



		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

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


Mime
View raw message