You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Khurram Shehzad <kh...@outlook.com> on 2018/08/24 10:45:31 UTC
SQL OR in lucene : where ((term1=a and term2=b) OR (term3=a and
term4=b)) and context in (2,3,4,5.....200)
Hi,
I have a requirement to replicate following SQL query logic containing OR condition as
where
((term1=a and term2=b) OR (term3=a and term4=b)) and context in (2,3,4,5.....200)
roughly in lucene
(+term1:a +term2:b) (+term3:a and +term4:b) #context:2 4 7 ... 198
It doesn't seem to me getting desired effect of "OR" logic using Occur.Should.
Above lucene query will retrieve all documents satisfying context condition and disregarding first two conditions.
But it can be workable, if I manage to apply context condition separately.
More probably using custom filtering through Collector interface https://lucene.apache.org/core/7_3_1/core/org/apache/lucene/search/Collector.html.
Any idea please.
Regards,
Khurram
Re: SQL OR in lucene : where ((term1=a and term2=b) OR (term3=a and
term4=b)) and context in (2,3,4,5.....200)
Posted by Michael Sokolov <ms...@gmail.com>.
# is a required, non-scoring term (Occur.FILTER) - semantically it
functions like Occur.MUST. It looks to me as if the Shehzad's query is
missing a clause, eg based on his description it should look like:
+((+term1:a +term2:b) (+term3:a and +term4:b)) #context:2 4 7 ... 198
I agree w/Tomoko, if you want more help, you must post your code
On Fri, Aug 24, 2018 at 9:35 AM Tomoko Uchida <to...@gmail.com>
wrote:
> Hi Khurram,
>
> Lucene query parser's OR operator or Occur.Should are work as expected
> for me, I suspect you could miss some points.
>
> > roughly in lucene
> > (+term1:a +term2:b) (+term3:a and +term4:b) #context:2 4 7 ... 198
>
> It does not look like an ordinary lucene query string to me ('#' is
> not an operator of StandardQueryParser or ClassicQueryParser,) which
> parser do you use?
> If you try to build a query by Java code, I suggest you post your
> exact code snippet.
>
> p.s. dev mailing list is not for user questions, you should post such
> questions to java-user list only, anyway. ;)
>
> Regards,
> Tomoko
>
> 2018年8月24日(金) 19:45 Khurram Shehzad <kh...@outlook.com>:
> >
> > Hi,
> >
> >
> > I have a requirement to replicate following SQL query logic containing
> OR condition as
> >
> > where
> >
> > ((term1=a and term2=b) OR (term3=a and term4=b)) and context in
> (2,3,4,5.....200)
> >
> >
> > roughly in lucene
> >
> >
> > (+term1:a +term2:b) (+term3:a and +term4:b) #context:2 4 7 ... 198
> >
> >
> > It doesn't seem to me getting desired effect of "OR" logic using
> Occur.Should.
> >
> >
> > Above lucene query will retrieve all documents satisfying context
> condition and disregarding first two conditions.
> >
> >
> > But it can be workable, if I manage to apply context condition
> separately.
> >
> >
> > More probably using custom filtering through Collector interface
> https://lucene.apache.org/core/7_3_1/core/org/apache/lucene/search/Collector.html
> .
> >
> >
> > Any idea please.
> >
> >
> > Regards,
> > Khurram
>
>
>
> --
> Tomoko Uchida
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
Re: SQL OR in lucene : where ((term1=a and term2=b) OR (term3=a and
term4=b)) and context in (2,3,4,5.....200)
Posted by András Péteri <ap...@b2international.com>.
Hi Khurram,
My understanding is that once you add a MUST or FILTER clause to a boolean
query, SHOULD clauses become entirely optional, ie. none of them have to
match the document being returned, unless you also set the "minimum number
should match" property to a value >= 1 on the query.
This does not apply to boolean queries that consist purely of SHOULD
clauses, in which case at least one of them has to apply for each document
in the result set (and you can also tune the same property as above, to
modify this behavior).
Regards,
András
On Fri, Aug 24, 2018 at 3:34 PM, Tomoko Uchida <tomoko.uchida.1111@gmail.com
> wrote:
> Hi Khurram,
>
> Lucene query parser's OR operator or Occur.Should are work as expected
> for me, I suspect you could miss some points.
>
> > roughly in lucene
> > (+term1:a +term2:b) (+term3:a and +term4:b) #context:2 4 7 ... 198
>
> It does not look like an ordinary lucene query string to me ('#' is
> not an operator of StandardQueryParser or ClassicQueryParser,) which
> parser do you use?
> If you try to build a query by Java code, I suggest you post your
> exact code snippet.
>
> p.s. dev mailing list is not for user questions, you should post such
> questions to java-user list only, anyway. ;)
>
> Regards,
> Tomoko
>
> 2018年8月24日(金) 19:45 Khurram Shehzad <kh...@outlook.com>:
> >
> > Hi,
> >
> >
> > I have a requirement to replicate following SQL query logic containing
> OR condition as
> >
> > where
> >
> > ((term1=a and term2=b) OR (term3=a and term4=b)) and context in
> (2,3,4,5.....200)
> >
> >
> > roughly in lucene
> >
> >
> > (+term1:a +term2:b) (+term3:a and +term4:b) #context:2 4 7 ... 198
> >
> >
> > It doesn't seem to me getting desired effect of "OR" logic using
> Occur.Should.
> >
> >
> > Above lucene query will retrieve all documents satisfying context
> condition and disregarding first two conditions.
> >
> >
> > But it can be workable, if I manage to apply context condition
> separately.
> >
> >
> > More probably using custom filtering through Collector interface
> https://lucene.apache.org/core/7_3_1/core/org/apache/lucene/
> search/Collector.html.
> >
> >
> > Any idea please.
> >
> >
> > Regards,
> > Khurram
>
>
>
> --
> Tomoko Uchida
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
--
András Péteri
Re: SQL OR in lucene : where ((term1=a and term2=b) OR (term3=a and
term4=b)) and context in (2,3,4,5.....200)
Posted by Tomoko Uchida <to...@gmail.com>.
Hi Khurram,
Lucene query parser's OR operator or Occur.Should are work as expected
for me, I suspect you could miss some points.
> roughly in lucene
> (+term1:a +term2:b) (+term3:a and +term4:b) #context:2 4 7 ... 198
It does not look like an ordinary lucene query string to me ('#' is
not an operator of StandardQueryParser or ClassicQueryParser,) which
parser do you use?
If you try to build a query by Java code, I suggest you post your
exact code snippet.
p.s. dev mailing list is not for user questions, you should post such
questions to java-user list only, anyway. ;)
Regards,
Tomoko
2018年8月24日(金) 19:45 Khurram Shehzad <kh...@outlook.com>:
>
> Hi,
>
>
> I have a requirement to replicate following SQL query logic containing OR condition as
>
> where
>
> ((term1=a and term2=b) OR (term3=a and term4=b)) and context in (2,3,4,5.....200)
>
>
> roughly in lucene
>
>
> (+term1:a +term2:b) (+term3:a and +term4:b) #context:2 4 7 ... 198
>
>
> It doesn't seem to me getting desired effect of "OR" logic using Occur.Should.
>
>
> Above lucene query will retrieve all documents satisfying context condition and disregarding first two conditions.
>
>
> But it can be workable, if I manage to apply context condition separately.
>
>
> More probably using custom filtering through Collector interface https://lucene.apache.org/core/7_3_1/core/org/apache/lucene/search/Collector.html.
>
>
> Any idea please.
>
>
> Regards,
> Khurram
--
Tomoko Uchida
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: SQL OR in lucene : where ((term1=a and term2=b) OR (term3=a and
term4=b)) and context in (2,3,4,5.....200)
Posted by Shawn Heisey <ap...@elyograg.org>.
On 8/24/2018 4:45 AM, Khurram Shehzad wrote:
> I have a requirement to replicate following SQL query logic containing
> OR condition as
>
> *where
> *
>
> *((term1=a and term2=b) OR (term3=a and term4=b)) and context
> in (2,3,4,5.....200)
> *
>
> roughly in lucene
>
>
> *(+term1:a +term2:b) (+term3:a and +term4:b) #context:2 4 7 ... 198*
>
Tomoko is correct, this should be on the user list, not the dev list.
This list is for discussing the development of the Lucene/Solr software
itself, not for questions or user code.
The following is probably the syntax you're looking for. I placed it on
two lines to control the line wrapping by the email client. When you do
it for real, it should only be one line:
+((+term1:a +term2:b) (+term3:a +term4:b))
+context:(2 4 7 ... 200)
Thanks,
Shawn
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org
Re: SQL OR in lucene : where ((term1=a and term2=b) OR (term3=a and
term4=b)) and context in (2,3,4,5.....200)
Posted by Tomoko Uchida <to...@gmail.com>.
Hi Khurram,
Lucene query parser's OR operator or Occur.Should are work as expected
for me, I suspect you could miss some points.
> roughly in lucene
> (+term1:a +term2:b) (+term3:a and +term4:b) #context:2 4 7 ... 198
It does not look like an ordinary lucene query string to me ('#' is
not an operator of StandardQueryParser or ClassicQueryParser,) which
parser do you use?
If you try to build a query by Java code, I suggest you post your
exact code snippet.
p.s. dev mailing list is not for user questions, you should post such
questions to java-user list only, anyway. ;)
Regards,
Tomoko
2018年8月24日(金) 19:45 Khurram Shehzad <kh...@outlook.com>:
>
> Hi,
>
>
> I have a requirement to replicate following SQL query logic containing OR condition as
>
> where
>
> ((term1=a and term2=b) OR (term3=a and term4=b)) and context in (2,3,4,5.....200)
>
>
> roughly in lucene
>
>
> (+term1:a +term2:b) (+term3:a and +term4:b) #context:2 4 7 ... 198
>
>
> It doesn't seem to me getting desired effect of "OR" logic using Occur.Should.
>
>
> Above lucene query will retrieve all documents satisfying context condition and disregarding first two conditions.
>
>
> But it can be workable, if I manage to apply context condition separately.
>
>
> More probably using custom filtering through Collector interface https://lucene.apache.org/core/7_3_1/core/org/apache/lucene/search/Collector.html.
>
>
> Any idea please.
>
>
> Regards,
> Khurram
--
Tomoko Uchida
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org