1 Simplest form of query boosting :

(Query without boosting ) : http://localhost:8983/solr/collection1/select?q=indication:*skin*
(Query with boosting ) : http://localhost:8983/solr/collection1/select?q=indication:*skin*&defType=edismax&bq=indication:*Herpes*^0.5

Read about the request parameters being used : fl, qf,pf2,ps,mm and tie here: http://wiki.apache.org/solr/DisMaxQParserPlugin.

Note that : The ranking terms will only change the sorting order, not the number of documents found by a query. All documents containing a ranking term will be sorted before all documents without it.

For example, if you want all documents with HDTV to sort before all documents without it, use a very high boost:
widescreen AND HDTV^100

2. Create your own scoring function :
You can define your own scoring functions in the file solrconfig.xml. For eg.
<requestHandler name=”productSearch”>
<lst name=”defaults”>
<str name=”echoParams”>all</str>
<str name=”defType”>edismax</str>
<str name=”rows”>10</str>
<str name=”fl”>title, brand, scs_brand, label, vendor, category,score</str>
<str name=”qf”>
title^5 brand^1.5 scs_brand_txt^1.5 category^1.5
<str name=”pf2″>
title^5 brand^1.5 scs_brand_txt^1.5 category^1.5
<str name=”ps”>2</str>
<str name=”mm”>1&lt;100% 3&lt;75%</str>
<str name=”tie”>0.1</str>
The above creates a new handler for your scoring functions. This ensures that you are not messing up with other scoring functions.
You can change the scoring function just by changing qt in the url.
For example :

To query using the above scoring function: use the following url

Query: red samsung


3 use a rank function inside the handler
<requestHandler name =”productSearchHandler”>
// complex function
<str name=”boost”>
// another example … simple function
<str name=”boost”>product(precomputed_price_boost,if(exists(new_boost),new_boost,1.0))</str>

4 More example of custom Scoring Function :

General Example

To give more idea about the use of the function query, suppose index stores dimensions in meters x, y,z of some hypothetical boxes with arbitrary names stored in field boxname. Suppose we want to search for box matching name findbox but ranked according to volumes of boxes, the query params would be:
Although this will rank the results based on volumes but in order to get the computed volume you will need to add parameter…
>> http://wiki.apache.org/solr/FunctionQuery

…where score will contain the resultant volume.

Suppose you also have a field containing weight of the box as ‘weight’, then to sort by the density of the box and return the value of the density in score you query should be…


Rank using Term Proximity concept – how close certain terms are inside a document.

Use the concept of – http://wiki.apache.org/solr/SolrRelevancyCookbook#Ranking_Terms

It may be desirable to boost the score of documents with query terms that appear closer together. This is not done by default in Lucene, but there are Lucene Span queries that do this. Unfortunately, these queries are relatively new and don’t have any support in the query parser (only a Java API currently exists).

One way to get term proximity effects with the current query parser is to use a phrase query with a very large slop.
Phrase queries with slop will score higher when the terms are closer together.

without term proximity
term proximity using phrase queries
foo AND bar
“foo bar”~1000000
foo OR bar
foo OR bar OR “foo bar”~1000000^10
“foo bar” “baz bing”
+(“foo bar” “baz bing”) “foo baz”~1000000

Index time boosting
Document level boosting – while indexing – by calling document.setBoost() before a document is added to the index.
Document’s Field level boosting – while indexing – by calling field.setBoost() before adding a field to the document (and before adding the document to the index).
<doc boost=”2.5″>
<field name=”employeeId”>05991</field>
<field name=”office” boost=”2.0″>Bridgewater</field>

Boost by document Age