djulb
djulb

Reputation: 395

SOLR: Search for a value in multiple fields

I am looking for a way of querying for values in multiple fields. Basically i am building a simple search engine where user can type ie. "Java How to XML JSON" and it will search for these values in 3 different fields categories, tags, description.

I read on some blog I should query all fields q=*:* and then filter based on those fields for example fq=categories:java,xml,how,to,json description:java,xml,how,to,json tags:java,xml,how,to,json

This works :| But it seems incorrect to just copy paste values like this.

Is there a correct way of doing this? I have been researching this for some time but i havent found a solution.

Any help is appreciated, Thank you

Upvotes: 1

Views: 551

Answers (1)

MatsLindh
MatsLindh

Reputation: 52902

You can use defType=edismax to get the extended dismax handler. This is meant to handle user typed queries (i.e. what you'd type in). You can then use qf (query fields) to tell the edismax handler which fields you want to search (and an optional weight for each field):

q=Java How to XML JSON&defType=edismax&qf=categories^5 tags description

.. will search each part of the string "Java How to XML JSON" in all the fields, and any hits in the categories field will be weighted five times higher than hits in the other two fields.

Upvotes: 2

Related Questions