You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Vaijanath Rao <va...@gmail.com> on 2011/02/25 06:16:41 UTC
Best way to Use SHOULD and MUST Clauses
Hi All,
I need to create a boolean query with MUST clause as well as SHOULD Clause.
The result I get is the one which has MUST Clause but there are no SHOULD
Clause present.
I need something like the following
+term:abc +loc:nyc and one of the ngrams for spell check like spell:co,
spell:cor and so on
Currently if include them as one BooleanQuery I get the doc maching the must
clause on top but does not have any of the spell field used. So I tried to
used setMinimumNumberShouldMatch(1), which causes no documents to match.
I tried the following approaches
Approach : 1
a. All Must Terms in one BooleanQuery
b. All SpellTerms as Should in Second BooleanQuery
c. FinalQuery as MustBooleanQuery and SpellBooleanQuery ( both added as
Must) : output no results found
Approach : 2
a. All Must Terms in One BooleanQuery
b. All SpellTerms added as Should Clauses to finalQuery
c. Adding MustBooleanQuery to finalQuery : Top record match found only has
Must part and no should clauses
Approach :3
Same as 2 but with setMinimumNumberShouldMatch(1), so that atleast one
spellTerms is matched : Output is no result found
Approach :4
a. Add All Must terms into finalquery as Must Clause
b.All SpellTerms added as Should Clauses to finalQuery
c.Result: Top record match found only has Must part and no should clauses
Approach :5
Same as 4 but with setMinimumNumberShouldMatch(1)
c.Result: No Result Found
I am calling TopDocs = searcher.search(finalQuery,MAX_HITS); in all the
above cases and using Lucene 3.0.2
Can someone help me in getting this query right to get atleast one spellterm
to be matched with the document.
--Thanks and Regards
Vaijanath N. Rao
Re: Best way to Use SHOULD and MUST Clauses
Posted by Vaijanath Rao <va...@gmail.com>.
Hi All,
Sorry just ignore this mail, did not realize I was hitting a different index
and looking at different index all together.
It's working like it should be.
--Thanks and Regards
Vaijanath N. Rao
On Fri, Feb 25, 2011 at 10:46 AM, Vaijanath Rao <va...@gmail.com> wrote:
> Hi All,
>
> I need to create a boolean query with MUST clause as well as SHOULD Clause.
> The result I get is the one which has MUST Clause but there are no SHOULD
> Clause present.
> I need something like the following
> +term:abc +loc:nyc and one of the ngrams for spell check like spell:co,
> spell:cor and so on
>
> Currently if include them as one BooleanQuery I get the doc maching the
> must clause on top but does not have any of the spell field used. So I tried
> to used setMinimumNumberShouldMatch(1), which causes no documents to match.
>
> I tried the following approaches
>
> Approach : 1
> a. All Must Terms in one BooleanQuery
> b. All SpellTerms as Should in Second BooleanQuery
> c. FinalQuery as MustBooleanQuery and SpellBooleanQuery ( both added as
> Must) : output no results found
>
> Approach : 2
> a. All Must Terms in One BooleanQuery
> b. All SpellTerms added as Should Clauses to finalQuery
> c. Adding MustBooleanQuery to finalQuery : Top record match found only has
> Must part and no should clauses
>
> Approach :3
> Same as 2 but with setMinimumNumberShouldMatch(1), so that atleast one
> spellTerms is matched : Output is no result found
>
> Approach :4
> a. Add All Must terms into finalquery as Must Clause
> b.All SpellTerms added as Should Clauses to finalQuery
> c.Result: Top record match found only has Must part and no should clauses
>
> Approach :5
> Same as 4 but with setMinimumNumberShouldMatch(1)
> c.Result: No Result Found
>
> I am calling TopDocs = searcher.search(finalQuery,MAX_HITS); in all the
> above cases and using Lucene 3.0.2
>
> Can someone help me in getting this query right to get atleast one
> spellterm to be matched with the document.
>
> --Thanks and Regards
> Vaijanath N. Rao
>
--
I am feeling fine, healthier and Happier, what about you