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 hank williams <ha...@hotmail.com> on 2012/12/22 00:45:46 UTC
AND OR query
If I do a free text search for a keyword over all my fields using the query winston churchill
town:*winston churchill* OR label:*winston churchill* OR name:*winston churchill* OR office:*winston churchill*
I get plenty of results. But If I want to filter the searches down to towns. So Winston Chruchill was in the town of dundee, how can I keep doing a free text search over my data but add a mandatory AND?
town:*dundee* OR label:*winston churchill* AND name:*churchill* OR office:*winston churchill*
In the example above I want say town must be 'dundee' AND name must contain 'churchill'; label and office may or may not contain 'winston churchill', but from my original free text search I have no idea to know in which field 'winston churchill' oringated from. By knowing that I want to filter down to town, I can't just say town:*dundee* because this is another query and 'winston churchill' may be a label or may be a name.
Hope this makes sense.
Thanks
Re: Exact Search
Posted by Erick Erickson <er...@gmail.com>.
Well, string types are not analyzed at all, so if the town is "Dundee",
this will not match.
If you haven't seen the admin/analysis page, that's the first place I'd
start. Followed by adding &debugQuery=true and looking at the results.
Best
Erick
On Sat, Dec 22, 2012 at 1:04 PM, hank williams <ha...@hotmail.com> wrote:
> Hi,
> I'm trying to build a facet search, but I'm having some difficulties.
> I can do a free text search over things, but I can build exact queries.
> I know that I have a result that has this data
> <doc> <arr name="label"> <str>iraq treatment of children hong
> kong</str> </arr> <arr name="label_long"> <str>iraq treatment
> of children hong kong</str> </arr> <arr name="name">
> <str>cavendish-bentinck, henry</str> <str>churchill, winston</str>
> <str>ward, john</str> </arr> <arr name="name_long">
> <str>cavendish-bentinck, henry</str> <str>churchill, winston</str>
> <str>ward, john</str> </arr> <arr name="town">
> <str>nottingham south</str> <str>cabinet</str>
> <str>department of state</str> <str>dundee</str>
> <str>stoke-on-trent stoke</str> </arr> <arr name="office">
> <str /> <str>secretary of state for the colonies</str> <str
> /> </arr> <long name="_version_">1422064629033467904</long></doc>
>
> And my schema looks like this
> <field name="id" type="string" indexed="true" stored="true"
> required="true" multiValued="false" /> <field name="name"
> type="text_general" indexed="true" stored="true" multiValued="true"/><field
> name="name_long" type="string" indexed="true" stored="true"
> multiValued="true"/><field name="type" type="string" indexed="true"
> stored="true" multiValued="true"/><field name="label" type="text_general"
> indexed="true" stored="true" multiValued="true"/><field name="label_long"
> type="string" indexed="true" stored="true" multiValued="true"/><field
> name="date" type="date" indexed="true" stored="true"
> multiValued="true"/><field name="town" type="string" indexed="true"
> stored="true" multiValued="true"/><field name="office" type="string"
> indexed="true" stored="true" multiValued="true"/>
> How can I create an exact query with name_long='churchill, winston' AND
> label_long=''iraq treatment of children hong kong' AND town='dundee'
> When I try
> <str name="q">label_long:*iraq treatment of children hong kong* AND
> name_long:*churchill, winston* AND town:*dundee*</str>
> I get zero results.
Exact Search
Posted by hank williams <ha...@hotmail.com>.
Hi,
I'm trying to build a facet search, but I'm having some difficulties.
I can do a free text search over things, but I can build exact queries.
I know that I have a result that has this data
<doc> <arr name="label"> <str>iraq treatment of children hong kong</str> </arr> <arr name="label_long"> <str>iraq treatment of children hong kong</str> </arr> <arr name="name"> <str>cavendish-bentinck, henry</str> <str>churchill, winston</str> <str>ward, john</str> </arr> <arr name="name_long"> <str>cavendish-bentinck, henry</str> <str>churchill, winston</str> <str>ward, john</str> </arr> <arr name="town"> <str>nottingham south</str> <str>cabinet</str> <str>department of state</str> <str>dundee</str> <str>stoke-on-trent stoke</str> </arr> <arr name="office"> <str /> <str>secretary of state for the colonies</str> <str /> </arr> <long name="_version_">1422064629033467904</long></doc>
And my schema looks like this
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> <field name="name" type="text_general" indexed="true" stored="true" multiValued="true"/><field name="name_long" type="string" indexed="true" stored="true" multiValued="true"/><field name="type" type="string" indexed="true" stored="true" multiValued="true"/><field name="label" type="text_general" indexed="true" stored="true" multiValued="true"/><field name="label_long" type="string" indexed="true" stored="true" multiValued="true"/><field name="date" type="date" indexed="true" stored="true" multiValued="true"/><field name="town" type="string" indexed="true" stored="true" multiValued="true"/><field name="office" type="string" indexed="true" stored="true" multiValued="true"/>
How can I create an exact query with name_long='churchill, winston' AND label_long=''iraq treatment of children hong kong' AND town='dundee'
When I try
<str name="q">label_long:*iraq treatment of children hong kong* AND name_long:*churchill, winston* AND town:*dundee*</str>
I get zero results.
Re: AND OR query
Posted by Jack Krupansky <ja...@basetechnology.com>.
Put parentheses around the original query and your new contraint and
separate them with "AND":
(...) AND (...)
Either of those sub-queries could have any complexity of AND and OR.
Or,
Put the constraint query into a filter query: &fq=... , which will limit the
query results as specified.
-- Jack Krupansky
-----Original Message-----
From: hank williams
Sent: Friday, December 21, 2012 6:45 PM
To: solr-user@lucene.apache.org
Subject: AND OR query
If I do a free text search for a keyword over all my fields using the query
winston churchill
town:*winston churchill* OR label:*winston churchill* OR name:*winston
churchill* OR office:*winston churchill*
I get plenty of results. But If I want to filter the searches down to towns.
So Winston Chruchill was in the town of dundee, how can I keep doing a free
text search over my data but add a mandatory AND?
town:*dundee* OR label:*winston churchill* AND name:*churchill* OR
office:*winston churchill*
In the example above I want say town must be 'dundee' AND name must contain
'churchill'; label and office may or may not contain 'winston churchill',
but from my original free text search I have no idea to know in which field
'winston churchill' oringated from. By knowing that I want to filter down to
town, I can't just say town:*dundee* because this is another query and
'winston churchill' may be a label or may be a name.
Hope this makes sense.
Thanks