There are two stages where documents can be boosted: At index time and at query time.

here we discuss index time boost feature solr.

This is probably the simplest way, because there are not too many options. It is also the most static way of adding boosts, as changing the boost for a documents would require re-indexing it.

Document level boost :
When updating documents using the XMLUpdateRequestHandler, the way to boost a document is to add the optional attribute “boost” to the doc element.

<add>
  <doc boost="2.5">
    <field name="DOC_ID">101</field>
    <field name="FROM">[email protected]</field>
  </doc>
</add>

When updating documents using solrj client , use setDocumentBoost(float boostValue) to the SolrInputDocument.

SolrInputDocument document = new SolrInputDocument();
document.addField("DOC_ID", "101");
document.addField("FROM", "[email protected]");
document.setDocumentBoost(2.5f)
UpdateResponse response = solr.add(document);
 
// Remember to commit your changes!
 
solr.commit();

 

Field Level Boost:

It is also possible to add different boosts to different fields of a document. The only requirement here is that the boosted fields must store the norms (“omitNorms” attribute in the schema must be set to “false”).
When updating documents using the XMLUpdateRequestHandler, the way to boost a field is to add the optional attribute “boost” to the field element.

<add>
  <doc boost="2.5">
    <field name="DOC_ID">101</field>
    <field name="FROM" boost="2.0">[email protected]</field>
  </doc>
</add>

When updating documents using solrj client , use method addField(String fieldName,String fieldValue,float boostValue) to the SolrInputDocument.

SolrInputDocument document = new SolrInputDocument();
document.addField("DOC_ID", "101");
document.addField("FROM", "[email protected]",2.0f);
document.setDocumentBoost(2.5f)
UpdateResponse response = solr.add(document);
 
// Remember to commit your changes!
 
solr.commit();

It’s important to know that the boost (either for a document or for a field) will be considered when calculating the final score for a document given a search. It is not the final score of the document. Boosting documents is not the same as sorting documents.

Refer Solr wiki or lucidworks for more details.

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Yes
No
Tags: , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *