[prev in list] [next in list] [prev in thread] [next in thread]
List: lucene-user
Subject: Re: Creating composite query in lucene
From: sandeep das <yarnhadoop () gmail ! com>
Date: 2016-03-10 7:41:04
Message-ID: CAD1=LDqWddzp20mwhkWJ2ROViVf+15=g_W7Pr9QE2UcNcrTHPw () mail ! gmail ! com
[Download RAW message or body]
Hi Jack,
Thanks a lot for your suggestion.
Regards,
Sandeep
On Tue, Mar 8, 2016 at 8:32 PM, Jack Krupansky <jack.krupansky@gmail.com>
wrote:
> BooleanQuery can be nested, so you do a top-level BQ that has two clauses,
> the first a TQ for a:x and the second another BQ that itself has two
> clauses, both SHOULD.
>
> -- Jack Krupansky
>
> On Tue, Mar 8, 2016 at 4:38 AM, sandeep das <yarnhadoop@gmail.com> wrote:
>
> > Hi,
> >
> > I'm using lucene-5.2.0 and in query interface I wish to compose a query
> > like
> > "a=x and (b=y or d=z)"
> >
> >
> > Which can be described as If any document has value "x" for field "a" and
> > field "b" has value "y" or field "d" has value "z" then that document
> > should be chosen. There are three fields in my document i.e. a, b and c.
> >
> > I was thinking of using BooleanQuery object to implement such query but
> it
> > seems difficult to implement the same.
> >
> > If I write the above clause in terms of boolean query then this is the
> best
> > I can think of:
> >
> > ((BooleanQuery)query).add(new RegexpQuery(new Term("a", "x")),
> > BooleanClause.Occur.MUST);
> >
> > ((BooleanQuery)query).add(new RegexpQuery(new Term("b", "y")),
> > BooleanClause.Occur.SHOULD);
> >
> > ((BooleanQuery)query).add(new RegexpQuery(new Term("c", "z")),
> > BooleanClause.Occur.SHOULD);
> >
> >
> > But in the above case a document will be selected even if it does not
> have
> > value of field "b" as "y" or value of field "c" as "z" but has value of
> > field "a" as "x". The OR condition might be ignored.
> >
> > Correct me If my understanding is wrong here.
> >
> > Can someone please suggest some better solution to compose such query?
> >
> > Regards,
> > Sandeep
> >
>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic