You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by OTH <om...@gmail.com> on 2017/08/10 20:36:19 UTC

Need help with query syntax

Hello,

I have the following use case:

I have two fields (among others); one is 'name' and the other is 'type'.
 'Name' is the field I need to search, whereas, with 'type', I need to make
sure that it has a certain value, depending on the situation.  Often, when
I search the 'name' field, the search query would have multiple tokens.
Furthermore, each query token needs to have a scoring weight attached to
it.

However, I'm unable to figure out the syntax which would allow all these
things to happen.

For example, if I use the following query:
select?q=type:value+AND+name:america^1+name:state^1+name:united^1
It would only return documents where 'name' includes the token 'america'
(and where type==value).  It will totally ignore
"+name:state^1+name:united^1", it seems.

This does not happen if I omit "type:value+AND+".  So, with the following
query:
select?q=name:america^1+name:state^1+name:united^1
It returns all documents which contain any of the three tokens {america,
state, united}; which is what I need.  However, it also returns documents
where type != value; which I can't have.

If I put "type:value" at the end of the query command, like so:
select?q=name:america^1+name:state^1+name:united^1+AND+type:value
In this case, it will only return documents which contain the "united"
token in the name field (and where type==value).  Again, it will totally
ignore "name:america^1+name:state^1", it seems.

I tried putting an "AND" between everything, like so:
select?q=type:value+AND+name:america^1+AND+name:state^1+AND+name:united^1
But this, of course, would only return documents which contain all the
tokens {america, state, united}; whereas I need all documents which contain
any of those tokens.


If anyone could help me out with how this could be done / what the correct
syntax would be, that would be a huge help.

Much thanks
Omer

Re: Need help with query syntax

Posted by Erick Erickson <er...@gmail.com>.
Yep..

On Fri, Aug 11, 2017 at 6:31 AM, OTH <om...@gmail.com> wrote:
> Hi, thanks for sharing the article.
>
> On Fri, Aug 11, 2017 at 4:38 AM, Erick Erickson <er...@gmail.com>
> wrote:
>
>> Omer:
>>
>> Solr does not implement pure boolean logic, see:
>> https://lucidworks.com/2011/12/28/why-not-and-or-and-not/.
>>
>> With appropriate parentheses it can give the same results as you're
>> discovering.....
>>
>> Best
>> Erick
>>
>> On Thu, Aug 10, 2017 at 3:00 PM, OTH <om...@gmail.com> wrote:
>> > Thanks for the help!
>> > That's resolved the issue.
>> >
>> > On Fri, Aug 11, 2017 at 1:48 AM, David Hastings <
>> > hastings.recursive@gmail.com> wrote:
>> >
>> >> type:value AND (name:america^1+name:state^1+name:united^1)
>> >>
>> >> but in reality what you want to do is use the fq parameter with
>> type:value
>> >>
>> >> On Thu, Aug 10, 2017 at 4:36 PM, OTH <om...@gmail.com> wrote:
>> >>
>> >> > Hello,
>> >> >
>> >> > I have the following use case:
>> >> >
>> >> > I have two fields (among others); one is 'name' and the other is
>> 'type'.
>> >> >  'Name' is the field I need to search, whereas, with 'type', I need to
>> >> make
>> >> > sure that it has a certain value, depending on the situation.  Often,
>> >> when
>> >> > I search the 'name' field, the search query would have multiple
>> tokens.
>> >> > Furthermore, each query token needs to have a scoring weight attached
>> to
>> >> > it.
>> >> >
>> >> > However, I'm unable to figure out the syntax which would allow all
>> these
>> >> > things to happen.
>> >> >
>> >> > For example, if I use the following query:
>> >> > select?q=type:value+AND+name:america^1+name:state^1+name:united^1
>> >> > It would only return documents where 'name' includes the token
>> 'america'
>> >> > (and where type==value).  It will totally ignore
>> >> > "+name:state^1+name:united^1", it seems.
>> >> >
>> >> > This does not happen if I omit "type:value+AND+".  So, with the
>> following
>> >> > query:
>> >> > select?q=name:america^1+name:state^1+name:united^1
>> >> > It returns all documents which contain any of the three tokens
>> {america,
>> >> > state, united}; which is what I need.  However, it also returns
>> documents
>> >> > where type != value; which I can't have.
>> >> >
>> >> > If I put "type:value" at the end of the query command, like so:
>> >> > select?q=name:america^1+name:state^1+name:united^1+AND+type:value
>> >> > In this case, it will only return documents which contain the "united"
>> >> > token in the name field (and where type==value).  Again, it will
>> totally
>> >> > ignore "name:america^1+name:state^1", it seems.
>> >> >
>> >> > I tried putting an "AND" between everything, like so:
>> >> > select?q=type:value+AND+name:america^1+AND+name:state^1+
>> >> AND+name:united^1
>> >> > But this, of course, would only return documents which contain all the
>> >> > tokens {america, state, united}; whereas I need all documents which
>> >> contain
>> >> > any of those tokens.
>> >> >
>> >> >
>> >> > If anyone could help me out with how this could be done / what the
>> >> correct
>> >> > syntax would be, that would be a huge help.
>> >> >
>> >> > Much thanks
>> >> > Omer
>> >> >
>> >>
>>

Re: Need help with query syntax

Posted by OTH <om...@gmail.com>.
Hi, thanks for sharing the article.

On Fri, Aug 11, 2017 at 4:38 AM, Erick Erickson <er...@gmail.com>
wrote:

> Omer:
>
> Solr does not implement pure boolean logic, see:
> https://lucidworks.com/2011/12/28/why-not-and-or-and-not/.
>
> With appropriate parentheses it can give the same results as you're
> discovering.....
>
> Best
> Erick
>
> On Thu, Aug 10, 2017 at 3:00 PM, OTH <om...@gmail.com> wrote:
> > Thanks for the help!
> > That's resolved the issue.
> >
> > On Fri, Aug 11, 2017 at 1:48 AM, David Hastings <
> > hastings.recursive@gmail.com> wrote:
> >
> >> type:value AND (name:america^1+name:state^1+name:united^1)
> >>
> >> but in reality what you want to do is use the fq parameter with
> type:value
> >>
> >> On Thu, Aug 10, 2017 at 4:36 PM, OTH <om...@gmail.com> wrote:
> >>
> >> > Hello,
> >> >
> >> > I have the following use case:
> >> >
> >> > I have two fields (among others); one is 'name' and the other is
> 'type'.
> >> >  'Name' is the field I need to search, whereas, with 'type', I need to
> >> make
> >> > sure that it has a certain value, depending on the situation.  Often,
> >> when
> >> > I search the 'name' field, the search query would have multiple
> tokens.
> >> > Furthermore, each query token needs to have a scoring weight attached
> to
> >> > it.
> >> >
> >> > However, I'm unable to figure out the syntax which would allow all
> these
> >> > things to happen.
> >> >
> >> > For example, if I use the following query:
> >> > select?q=type:value+AND+name:america^1+name:state^1+name:united^1
> >> > It would only return documents where 'name' includes the token
> 'america'
> >> > (and where type==value).  It will totally ignore
> >> > "+name:state^1+name:united^1", it seems.
> >> >
> >> > This does not happen if I omit "type:value+AND+".  So, with the
> following
> >> > query:
> >> > select?q=name:america^1+name:state^1+name:united^1
> >> > It returns all documents which contain any of the three tokens
> {america,
> >> > state, united}; which is what I need.  However, it also returns
> documents
> >> > where type != value; which I can't have.
> >> >
> >> > If I put "type:value" at the end of the query command, like so:
> >> > select?q=name:america^1+name:state^1+name:united^1+AND+type:value
> >> > In this case, it will only return documents which contain the "united"
> >> > token in the name field (and where type==value).  Again, it will
> totally
> >> > ignore "name:america^1+name:state^1", it seems.
> >> >
> >> > I tried putting an "AND" between everything, like so:
> >> > select?q=type:value+AND+name:america^1+AND+name:state^1+
> >> AND+name:united^1
> >> > But this, of course, would only return documents which contain all the
> >> > tokens {america, state, united}; whereas I need all documents which
> >> contain
> >> > any of those tokens.
> >> >
> >> >
> >> > If anyone could help me out with how this could be done / what the
> >> correct
> >> > syntax would be, that would be a huge help.
> >> >
> >> > Much thanks
> >> > Omer
> >> >
> >>
>

Re: Need help with query syntax

Posted by Dave <ha...@gmail.com>.
Eric you going to vegas next month? 

> On Aug 10, 2017, at 7:38 PM, Erick Erickson <er...@gmail.com> wrote:
> 
> Omer:
> 
> Solr does not implement pure boolean logic, see:
> https://lucidworks.com/2011/12/28/why-not-and-or-and-not/.
> 
> With appropriate parentheses it can give the same results as you're
> discovering.....
> 
> Best
> Erick
> 
>> On Thu, Aug 10, 2017 at 3:00 PM, OTH <om...@gmail.com> wrote:
>> Thanks for the help!
>> That's resolved the issue.
>> 
>> On Fri, Aug 11, 2017 at 1:48 AM, David Hastings <
>> hastings.recursive@gmail.com> wrote:
>> 
>>> type:value AND (name:america^1+name:state^1+name:united^1)
>>> 
>>> but in reality what you want to do is use the fq parameter with type:value
>>> 
>>>> On Thu, Aug 10, 2017 at 4:36 PM, OTH <om...@gmail.com> wrote:
>>>> 
>>>> Hello,
>>>> 
>>>> I have the following use case:
>>>> 
>>>> I have two fields (among others); one is 'name' and the other is 'type'.
>>>> 'Name' is the field I need to search, whereas, with 'type', I need to
>>> make
>>>> sure that it has a certain value, depending on the situation.  Often,
>>> when
>>>> I search the 'name' field, the search query would have multiple tokens.
>>>> Furthermore, each query token needs to have a scoring weight attached to
>>>> it.
>>>> 
>>>> However, I'm unable to figure out the syntax which would allow all these
>>>> things to happen.
>>>> 
>>>> For example, if I use the following query:
>>>> select?q=type:value+AND+name:america^1+name:state^1+name:united^1
>>>> It would only return documents where 'name' includes the token 'america'
>>>> (and where type==value).  It will totally ignore
>>>> "+name:state^1+name:united^1", it seems.
>>>> 
>>>> This does not happen if I omit "type:value+AND+".  So, with the following
>>>> query:
>>>> select?q=name:america^1+name:state^1+name:united^1
>>>> It returns all documents which contain any of the three tokens {america,
>>>> state, united}; which is what I need.  However, it also returns documents
>>>> where type != value; which I can't have.
>>>> 
>>>> If I put "type:value" at the end of the query command, like so:
>>>> select?q=name:america^1+name:state^1+name:united^1+AND+type:value
>>>> In this case, it will only return documents which contain the "united"
>>>> token in the name field (and where type==value).  Again, it will totally
>>>> ignore "name:america^1+name:state^1", it seems.
>>>> 
>>>> I tried putting an "AND" between everything, like so:
>>>> select?q=type:value+AND+name:america^1+AND+name:state^1+
>>> AND+name:united^1
>>>> But this, of course, would only return documents which contain all the
>>>> tokens {america, state, united}; whereas I need all documents which
>>> contain
>>>> any of those tokens.
>>>> 
>>>> 
>>>> If anyone could help me out with how this could be done / what the
>>> correct
>>>> syntax would be, that would be a huge help.
>>>> 
>>>> Much thanks
>>>> Omer
>>>> 
>>> 

Re: Need help with query syntax

Posted by Erick Erickson <er...@gmail.com>.
Omer:

Solr does not implement pure boolean logic, see:
https://lucidworks.com/2011/12/28/why-not-and-or-and-not/.

With appropriate parentheses it can give the same results as you're
discovering.....

Best
Erick

On Thu, Aug 10, 2017 at 3:00 PM, OTH <om...@gmail.com> wrote:
> Thanks for the help!
> That's resolved the issue.
>
> On Fri, Aug 11, 2017 at 1:48 AM, David Hastings <
> hastings.recursive@gmail.com> wrote:
>
>> type:value AND (name:america^1+name:state^1+name:united^1)
>>
>> but in reality what you want to do is use the fq parameter with type:value
>>
>> On Thu, Aug 10, 2017 at 4:36 PM, OTH <om...@gmail.com> wrote:
>>
>> > Hello,
>> >
>> > I have the following use case:
>> >
>> > I have two fields (among others); one is 'name' and the other is 'type'.
>> >  'Name' is the field I need to search, whereas, with 'type', I need to
>> make
>> > sure that it has a certain value, depending on the situation.  Often,
>> when
>> > I search the 'name' field, the search query would have multiple tokens.
>> > Furthermore, each query token needs to have a scoring weight attached to
>> > it.
>> >
>> > However, I'm unable to figure out the syntax which would allow all these
>> > things to happen.
>> >
>> > For example, if I use the following query:
>> > select?q=type:value+AND+name:america^1+name:state^1+name:united^1
>> > It would only return documents where 'name' includes the token 'america'
>> > (and where type==value).  It will totally ignore
>> > "+name:state^1+name:united^1", it seems.
>> >
>> > This does not happen if I omit "type:value+AND+".  So, with the following
>> > query:
>> > select?q=name:america^1+name:state^1+name:united^1
>> > It returns all documents which contain any of the three tokens {america,
>> > state, united}; which is what I need.  However, it also returns documents
>> > where type != value; which I can't have.
>> >
>> > If I put "type:value" at the end of the query command, like so:
>> > select?q=name:america^1+name:state^1+name:united^1+AND+type:value
>> > In this case, it will only return documents which contain the "united"
>> > token in the name field (and where type==value).  Again, it will totally
>> > ignore "name:america^1+name:state^1", it seems.
>> >
>> > I tried putting an "AND" between everything, like so:
>> > select?q=type:value+AND+name:america^1+AND+name:state^1+
>> AND+name:united^1
>> > But this, of course, would only return documents which contain all the
>> > tokens {america, state, united}; whereas I need all documents which
>> contain
>> > any of those tokens.
>> >
>> >
>> > If anyone could help me out with how this could be done / what the
>> correct
>> > syntax would be, that would be a huge help.
>> >
>> > Much thanks
>> > Omer
>> >
>>

Re: Need help with query syntax

Posted by OTH <om...@gmail.com>.
Thanks for the help!
That's resolved the issue.

On Fri, Aug 11, 2017 at 1:48 AM, David Hastings <
hastings.recursive@gmail.com> wrote:

> type:value AND (name:america^1+name:state^1+name:united^1)
>
> but in reality what you want to do is use the fq parameter with type:value
>
> On Thu, Aug 10, 2017 at 4:36 PM, OTH <om...@gmail.com> wrote:
>
> > Hello,
> >
> > I have the following use case:
> >
> > I have two fields (among others); one is 'name' and the other is 'type'.
> >  'Name' is the field I need to search, whereas, with 'type', I need to
> make
> > sure that it has a certain value, depending on the situation.  Often,
> when
> > I search the 'name' field, the search query would have multiple tokens.
> > Furthermore, each query token needs to have a scoring weight attached to
> > it.
> >
> > However, I'm unable to figure out the syntax which would allow all these
> > things to happen.
> >
> > For example, if I use the following query:
> > select?q=type:value+AND+name:america^1+name:state^1+name:united^1
> > It would only return documents where 'name' includes the token 'america'
> > (and where type==value).  It will totally ignore
> > "+name:state^1+name:united^1", it seems.
> >
> > This does not happen if I omit "type:value+AND+".  So, with the following
> > query:
> > select?q=name:america^1+name:state^1+name:united^1
> > It returns all documents which contain any of the three tokens {america,
> > state, united}; which is what I need.  However, it also returns documents
> > where type != value; which I can't have.
> >
> > If I put "type:value" at the end of the query command, like so:
> > select?q=name:america^1+name:state^1+name:united^1+AND+type:value
> > In this case, it will only return documents which contain the "united"
> > token in the name field (and where type==value).  Again, it will totally
> > ignore "name:america^1+name:state^1", it seems.
> >
> > I tried putting an "AND" between everything, like so:
> > select?q=type:value+AND+name:america^1+AND+name:state^1+
> AND+name:united^1
> > But this, of course, would only return documents which contain all the
> > tokens {america, state, united}; whereas I need all documents which
> contain
> > any of those tokens.
> >
> >
> > If anyone could help me out with how this could be done / what the
> correct
> > syntax would be, that would be a huge help.
> >
> > Much thanks
> > Omer
> >
>

Re: Need help with query syntax

Posted by David Hastings <ha...@gmail.com>.
type:value AND (name:america^1+name:state^1+name:united^1)

but in reality what you want to do is use the fq parameter with type:value

On Thu, Aug 10, 2017 at 4:36 PM, OTH <om...@gmail.com> wrote:

> Hello,
>
> I have the following use case:
>
> I have two fields (among others); one is 'name' and the other is 'type'.
>  'Name' is the field I need to search, whereas, with 'type', I need to make
> sure that it has a certain value, depending on the situation.  Often, when
> I search the 'name' field, the search query would have multiple tokens.
> Furthermore, each query token needs to have a scoring weight attached to
> it.
>
> However, I'm unable to figure out the syntax which would allow all these
> things to happen.
>
> For example, if I use the following query:
> select?q=type:value+AND+name:america^1+name:state^1+name:united^1
> It would only return documents where 'name' includes the token 'america'
> (and where type==value).  It will totally ignore
> "+name:state^1+name:united^1", it seems.
>
> This does not happen if I omit "type:value+AND+".  So, with the following
> query:
> select?q=name:america^1+name:state^1+name:united^1
> It returns all documents which contain any of the three tokens {america,
> state, united}; which is what I need.  However, it also returns documents
> where type != value; which I can't have.
>
> If I put "type:value" at the end of the query command, like so:
> select?q=name:america^1+name:state^1+name:united^1+AND+type:value
> In this case, it will only return documents which contain the "united"
> token in the name field (and where type==value).  Again, it will totally
> ignore "name:america^1+name:state^1", it seems.
>
> I tried putting an "AND" between everything, like so:
> select?q=type:value+AND+name:america^1+AND+name:state^1+AND+name:united^1
> But this, of course, would only return documents which contain all the
> tokens {america, state, united}; whereas I need all documents which contain
> any of those tokens.
>
>
> If anyone could help me out with how this could be done / what the correct
> syntax would be, that would be a huge help.
>
> Much thanks
> Omer
>