Need help with query syntax

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
OTH
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Need help with query syntax

OTH
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with query syntax

David Hastings
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 <[hidden email]> 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
>
OTH
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with query syntax

OTH
Thanks for the help!
That's resolved the issue.

On Fri, Aug 11, 2017 at 1:48 AM, David Hastings <
[hidden email]> 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 <[hidden email]> 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
> >
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with query syntax

Erick Erickson
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 <[hidden email]> wrote:

> Thanks for the help!
> That's resolved the issue.
>
> On Fri, Aug 11, 2017 at 1:48 AM, David Hastings <
> [hidden email]> 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 <[hidden email]> 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
>> >
>>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with query syntax

David Hastings
Eric you going to vegas next month?

> On Aug 10, 2017, at 7:38 PM, Erick Erickson <[hidden email]> 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 <[hidden email]> wrote:
>> Thanks for the help!
>> That's resolved the issue.
>>
>> On Fri, Aug 11, 2017 at 1:48 AM, David Hastings <
>> [hidden email]> 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 <[hidden email]> 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
>>>>
>>>
OTH
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with query syntax

OTH
In reply to this post by Erick Erickson
Hi, thanks for sharing the article.

On Fri, Aug 11, 2017 at 4:38 AM, Erick Erickson <[hidden email]>
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 <[hidden email]> wrote:
> > Thanks for the help!
> > That's resolved the issue.
> >
> > On Fri, Aug 11, 2017 at 1:48 AM, David Hastings <
> > [hidden email]> 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 <[hidden email]> 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
> >> >
> >>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with query syntax

Erick Erickson
Yep..

On Fri, Aug 11, 2017 at 6:31 AM, OTH <[hidden email]> wrote:

> Hi, thanks for sharing the article.
>
> On Fri, Aug 11, 2017 at 4:38 AM, Erick Erickson <[hidden email]>
> 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 <[hidden email]> wrote:
>> > Thanks for the help!
>> > That's resolved the issue.
>> >
>> > On Fri, Aug 11, 2017 at 1:48 AM, David Hastings <
>> > [hidden email]> 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 <[hidden email]> 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
>> >> >
>> >>
>>
Loading...