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 Jason Chaffee <jc...@ebates.com> on 2010/02/05 21:10:40 UTC
How to query multiple fields with phrases
I am migrating from lucene to solr and I am not quite sure how do what I
need to.
I need to do a search that will search 3 different fields and combine
the results. First, it needs to not break the phrase into tokens, but
rather treat it is a phrase for one field. The other fields need to be
parsed with their normal analyzers.
In Lucene, I did the following:
1. Ran the query through my custom analyzer and then created a
PhraseQuery and then did a search
2. Used a MultiFieldQueryParser for the other two fields and then did
a search
3. Combined the results of (1) and (2) into a Set and returned them.
How can do the same thing in Solr?
Thanks.
Jason
Re: How to query multiple fields with phrases
Posted by Chris Hostetter <ho...@fucit.org>.
: I need to do a search that will search 3 different fields and combine
: the results. First, it needs to not break the phrase into tokens, but
: rather treat it is a phrase for one field. The other fields need to be
: parsed with their normal analyzers.
your description of your goal is a little vague ... it's certianly
possible to construct an "exact phrase" query w/o tokenizing (assuming
your index contains whole phrases as individual terms), but strictly
speaking then you don't need a PhraseQuery, you just need a TermQuery -
but it's not clear if that's what you mean.
: 1. Ran the query through my custom analyzer and then created a
: PhraseQuery and then did a search
what did your custom analyzer do? how did you construct the PhraseQuery?
(specificly: what did you do differnetly then if you have given
QueryParser your analyzer and an input string that contained a quoted
string)
: 3. Combined the results of (1) and (2) into a Set and returned them.
combined in what way? in what order? what types of scoring was used?
: How can do the same thing in Solr?
it's hard to give you an answer with all the variables left up in the air
-- but my best guess would be that you should just define your three
fields, and give them analyzers that "do what you want" then use the
dismax query parser with all three fields listed in the "qf" param, but
make sure the "q" param is always a quoted string (ie q="your query
string")
-Hoss