11.05.2016 Views

Apache Solr Reference Guide Covering Apache Solr 6.0

21SiXmO

21SiXmO

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

against the phrase fields. (This will work only for boosting documents, not actually for matching.) However, that<br />

phrase query can have a 'slop,' which is the distance between the terms of the query while still considering it a<br />

phrase match. For example:<br />

q=foo bar<br />

qf=field1^5 field2^10<br />

pf=field1^50 field2^20<br />

defType=dismax<br />

With these parameters, the Dismax Query Parser generates a query that looks something like this:<br />

(+(field1:foo^5 OR field2:foo^10) AND (field1:bar^5 OR field2:bar^10))<br />

But it also generates another query that will only be used for boosting results:<br />

field1:"foo bar"^50 OR field2:"foo bar"^20<br />

Thus, any document that has the terms "foo" and "bar" will match; however if some of those documents have<br />

both of the terms as a phrase, it will score much higher because it's more relevant.<br />

If you add the parameter ps (phrase slop), the second query will instead be:<br />

ps=10 field1:"foo bar"~10^50 OR field2:"foo bar"~10^20<br />

This means that if the terms "foo" and "bar" appear in the document with less than 10 terms between each other,<br />

the phrase will match. For example the doc that says:<br />

*Foo* term1 term2 term3 *bar*<br />

will match the phrase query.<br />

How does one use phrase slop? Usually it is configured in the request handler (in solrconfig).<br />

With query slop ( qs) the concept is similar, but it applies to explicit phrase queries from the user. For example, if<br />

you want to search for a name, you could enter:<br />

q="Hans Anderson"<br />

A document that contains "Hans Anderson" will match, but a document that contains the middle name "Christian"<br />

or where the name is written with the last name first ("Anderson, Hans") won't. For those cases one could<br />

configure the query field qs, so that even if the user searches for an explicit phrase query, a slop is applied.<br />

Finally, edismax contains not only a phrase fields ( pf) parameters, but also phrase and query fields 2 and 3.<br />

You can use those fields for setting different fields or boosts. Each of those can use a different phrase slop.<br />

Using the 'magic fields' _val_ and _query_<br />

If the 'magic field' name _val_ is used in a term or phrase query, the value is parsed as a function.<br />

The <strong>Solr</strong> Query Parser's use of _val_ and _query_ differs from the Lucene Query Parser in the following ways:<br />

If the magic field name _val_ is used in a term or phrase query, the value is parsed as a function.<br />

It provides a hook into FunctionQuery syntax. Quotes are necessary to encapsulate the function when<br />

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

268

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

Saved successfully!

Ooh no, something went wrong!