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 :
http://sujitpal.blogspot.in/2011/02/solr-custom-search-requesthandler.html
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>
<str name=”pf2″>
title^5 brand^1.5 scs_brand_txt^1.5 category^1.5
</str>
<str name=”ps”>2</str>
<str name=”mm”>1&lt;100% 3&lt;75%</str>
<str name=”tie”>0.1</str>
</lst>
</requestHandler>
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

http://localhost:8983/solr/collection1/select/?qt=productSearch&q=samsung+red&debugQuery=true

3 use a rank function inside the handler
<requestHandler name =”productSearchHandler”>
// complex function
<str name=”boost”>
product(
sum(map(scale(item_price1,0,1),0,1,1),map(scale(item_price2,0,1),1,0.1)),
product(sum(1,div(log(sub(366,min(map(available_days,0,0,366),365))),60)),product(sum(1,product(is_new,0.01)),sum(1,product(map(strdist(“N”,is_renewed,edit),1,1,0,1),0.025)))))
</str>
// another example … simple function
<str name=”boost”>product(precomputed_price_boost,if(exists(new_boost),new_boost,1.0))</str>
</requestHandler>

4 More example of custom Scoring Function :

http://wiki.apache.org/solr/FunctionQuery#General_Example
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:
q=boxname:findbox+_val_:”product(product(x,y),z)”
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

&fl=*,score
…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…

http://localhost:8983/solr/select/?q=boxname:findbox+_val_:”div(weight,product(product(x,y),z))”&fl=boxname,x,y,z,weight,score

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).
<add>
<doc boost=”2.5″>
<field name=”employeeId”>05991</field>
<field name=”office” boost=”2.0″>Bridgewater</field>
</doc>
</add>

Boost by document Age

Advertisements