lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erick Erickson <erickerick...@gmail.com>
Subject Re: Set a field as required in a MultiFieldQueryParser
Date Sun, 01 Feb 2009 17:09:20 GMT
I think query.toString() is your friend here. I'm having a hard
time figuring out, from your description, what you actually want,
so maybe some examples would help too.

If your users enter terms for each field, then it seems to me that
you'd want MUST between clauses (in which case MultiFieldQueryParser
seems unnecesary). That is, if your form is somethinng like
title: <user enters term>
description: <user enters another term>
category: <user enters category>

If you have them enter just a single term, that is your form looks
something like
word:<user enters term to find in title OR description OR etc>
category: <user enters category>

 and want to form a query like
(title:term OR description:term OR etc:term) AND category:cat, it's not
clear from the docs how you would create this in a *single* MFQP. But
you could easily use MFQP to form the (a OR b OR c) clause, add that
to a BoleanQuery with MUST, and then create your simple query on
category and add *that* as a second MUST clause in your BooleanQuery
and use that for your search.

HTH
Erick


On Sun, Feb 1, 2009 at 5:33 AM, Sylvain <sylvaintersideral@gmail.com> wrote:

> Hello everybody,
>
> I have a search app in which the user can specify in which category the
> documents he's searching are. So all my indexed documents have a
> "category" field as well as other fields such as title, description,
> etc. So when the user enters his query, only the documents that are in
> the given category and which match a part of the query must be returned.
>
> So I tried to use a MultiFieldQueryParser with SHOULD clauses on the
> title, description, etc and a MUST clause on the category field. It
> works pretty well but the problem is that _all_ the documents in the
> searched category are returned, even if they don't have any similarity
> with the search string (except for the category of course).
>
> I think that's because of the MUST field which takes precedence on the
> SHOULD fields or something like that ? I saw in the BooleanQuery the
> method setMinimumNumberShouldMatch(). I think I should use this with my
> MultiFieldQueryParser to set a minimum of 1 or 2 fields, but this method
> only exists for BooleanQuery instances so I can't use it... I thought
> about using directly a BooleanQuery but I want to use the FrenchAnalyzer
> for the request.
>
> Any idea on how to achieve this ?
>
> Thanks for your help !
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message