Search code examples
solr

Solr search across multiple Fields inside of collection and claculationg score


I need to implement search across multiple fields in solr collection. I saw a solutions, where new field collector is getting introduced, that includes content of all fields from a whole collection, but what to do if I need to calculate score based on in which field was a hit. For example field "name" is twice more important for me then field "e-mail". Is it possible in Solr?


Solution

  • The edismax (and the older dismax) query handler supports giving hits in different fields different weights. You can provide a list of fields to search with the parameter qf and give their relative weights through the field^<weight> syntax:

    q=foo&qf=name^2 email
    

    .. will query for foo in name and email, with name being weighted twice as high.

    You can combine this with a catch-all field (a copyField instruction that copies the content of all fields into a common field to query), where you weigh hits in the specific fields higher than hits in the catch-all field (named _text_ here as that's the default one included):

    q=foo&qf=name^4 email^2 _text_