Search code examples
solrfieldrelevance

Solr: research in fields with relevance


I'm using Solr 5.4.1 and all documents have the following XML structure:

<?xml version ="1.0" ?>
    <add >
        <doc >
            <field name ="title">US, Qatar Extend Talks OverFormer Taliban Detainees - Wall Street Journal</field>
            <field name ="date">2015-05-31T23:39:45Z</field>
            <field name ="description">The U.S. and Qatari governments have extended talks over the fate of five former Afghan Taliban prisoners ho were released from the Guantanamo Bay prison a year ago in exchange for an American soldier , U.S. officials said Sunday.</field>
        </doc >
</add >

As you can see from the structure, there are the fields title and description.

I would like to do some tests:

1) To search text in both fields as if they were one UNIQUE field.

2) To search text in both fields giving a different relevance weight to each field (e.g. 80% to description and 20% to title).

I know that we can use the parameter qf to specify where to search (fields); but I know that there is also the boolean operator AND to be specified in a parameter q.

Which one of the above mentioned tecniques can I use to do each tests?


Solution

    1. If you want to search both fields as a single field, add a new field (i.e. title_description) and use two copyField instructions to copy the content from both fields into the common field:

    2. You can use qf with description^4 title to give any hits in description four times the weight of any hits in title. This will give you a 80/20 ratio, but remember that scoring is more complex than just simple percent weights between fields - the length of the content, the number of times the term is present, the position between fields (if using phrase boosting), etc.