<field name="id" type="number" indexed="true" stored="true" required="true" />
<field name="title" type="text_en" indexed="true" stored="true"/>
<field name="submit_date" type="date" indexed="true" stored="false" />
<field name="rating" type="number" indexed="true" stored="false" />
I won't go into detail too much about this schema, but it refers to a document with an ID, a title, a submit date, and a rating, which will be relevant to other examples in this article.
{!boost b=recip(ms(NOW/HOUR,submit_date),3.16e-11,1,1)}
There are many things going on in this one boost query, so I'll break it down from the inside out:
(title:test)
and
fl to:
submit_date,title, score
You will get results like this:
<result name="response" numFound="xxxx" start="0" maxScore="6.8792486">
<doc>
<date name="submit_date">2000-04-04T18:31:01Z</date>
<str name="title">testing</str>
<float name="score">6.8792486</float></doc>
<doc>
<date name="submit_date">2000-03-24T23:37:50Z</date>
<str name="title">testing</str>
<float name="score">6.8792486</float></doc>
<doc>
.
.
.
As you can see, the top results that Solr is returning are from the year 2000. If I added the boost in the example above,
q will be:
{!boost b=recip(ms(NOW/HOUR,submit_date),3.16e-11,1,1)}(title:test)
and that query returns:
<result name="response" numFound="xxxxx" start="0" maxScore="6.8649974">
<doc>
<date name="submit_date">2014-11-04T23:45:05Z</date>
<str name="title">test</str>
<float name="score">6.8649974</float></doc>
<doc>
<date name="submit_date">2014-10-31T17:20:54Z</date>
<str name="title">TEST</str>
<float name="score">6.7861075</float></doc>
<doc>
.
.
.
These results are a lot more recent, which could be useful in cases where you would want to give newer content a higher boost than older content.
{!boost b=rating}{!boost b=recip(ms(NOW/HOUR,submit_date),3.16e-11,1,1)}(title:test)
{!boost b=div(1,rating)}
the
score will be infinite if the
rating of a particular document is 0 (zero). So when you test your query in the Solr Admin interface, you might get something that looks like this:
<result name="response" numFound="xxxx" start="0" maxScore="Infinity">
<doc>
<str name="title">Words</str>
<int name="rating">0</int>
<float name="score">Infinity</float></doc>
<doc>
<str name="title">Different Words</str>
<int name="rating">0</int>
<float name="score">Infinity</float></doc>
<doc>
.
.
.
When the score of one or more documents are infinite, you cannot determine the order documents are returned. A useful function to use in this case would be the
scale function:
scale(x,minTarget,maxTarget)
where the return value of the function is between
minTarget and
maxTarget depending on the relative value of
x to other documents, so our original boost would be changed to:
{!boost b=div(1,scale(rating,1,2)}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)