11.05.2016 Views

Apache Solr Reference Guide Covering Apache Solr 6.0

21SiXmO

21SiXmO

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

In a Sort expression. For example:<br />

sort=div(popularity,price) desc, score desc<br />

Add the results of functions as psuedo-fields to documents in query results. For instance, for:<br />

&fl=sum(x, y),id,a,b,c,score<br />

the output would be:<br />

...<br />

foo<br />

40<br />

0.343<br />

...<br />

Use in a parameter that is explicitly for specifying functions, such as the EDisMax query parser's boost p<br />

aram, or DisMax query parser's bf (boost function) parameter. (Note that the bf parameter actually takes<br />

a list of function queries separated by white space and each with an optional boost. Make sure you<br />

eliminate any internal white space in single function queries when using bf). For example:<br />

q=dismax&bf="ord(popularity)^0.5 recip(rord(price),1,1000,1000)^0.3"<br />

Introduce a function query inline in the lucene QParser with the _val_ keyword. For example:<br />

q=_val_:mynumericfield _val_:"recip(rord(myfield),1,2,3)"<br />

Only functions with fast random access are recommended.<br />

Available Functions<br />

The table below summarizes the functions available for function queries.<br />

Function Description Syntax Examples<br />

abs<br />

and<br />

Returns the absolute value of the<br />

specified value or function.<br />

Returns a value of true if and only if all<br />

of its operands evaluate to true.<br />

abs(x)<br />

abs(-5)<br />

and(not(exists(popularity)),exists(p<br />

rice)): returns true for any document which<br />

has a value in the price field, but does not have<br />

a value in the popularity field<br />

"constant" Specifies a floating point constant. 1.5<br />

def<br />

div<br />

def is short for default. Returns the<br />

value of field "field", or if the field does<br />

not exist, returns the default value<br />

specified. and yields the first value<br />

where exists()==true.)<br />

Divides one value or function by<br />

another. div(x,y) divides x by y.<br />

def(rating,5): This def() function returns<br />

the rating, or if no rating specified in the doc,<br />

returns 5<br />

def(myfield, 1.0): equivalent to if(exist<br />

s(myfield),myfield,1.0)<br />

div(1,y)<br />

div(sum(x,100),max(y,1))<br />

<strong>Apache</strong> <strong>Solr</strong> <strong>Reference</strong> <strong>Guide</strong> <strong>6.0</strong><br />

270

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!