Question

I'm using Solr with Sunspot (ruby) and due to other constraints i have to use the Lucene parser instead of the DisMax parser. I need to be able to search using username as well as first_name fields at the same time.

If i were using DisMax i can specify qf="username+first_name" but using only the lucene parser I am only able to set df (default field) and it will not allow me to specify more than one field.

How can I search multiple fields using the lucene parser?

Update: Answer: just use the q parameter

adjust_solr_params do |params|
   params[:defType] = "lucene"      
   params[:q] = "username:\"#{params[:q]}\" OR first_name:\"#{params[:q]}\""
 end
Was it helpful?

Solution

To expand on Karussell's comment, the default field is just that, the default. You can explicitly specify however many fields you want, it's only if you don't specify one that the default comes into play.

So a query like username:foo first_name:bar will find documents with a username of "foo" and a first_name of "bar."

OTHER TIPS

You can use copy fields instructions in your schema to create a "catch all" field from all the fields you want to search on. You then set df to that field.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top