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.

Grouping Terms to Form Sub-Queries<br />

Lucene/<strong>Solr</strong> supports using parentheses to group clauses to form sub-queries. This can be very useful if you<br />

want to control the Boolean logic for a query.<br />

The query below searches for either "jakarta" or "apache" and "website":<br />

(jakarta OR apache) AND website<br />

This adds precision to the query, requiring that the term "website" exist, along with either term "jakarta" and<br />

"apache."<br />

Grouping Clauses within a Field<br />

To apply two or more Boolean operators to a single field in a search, group the Boolean clauses within<br />

parentheses. For example, the query below searches for a title field that contains both the word "return" and the<br />

phrase "pink panther":<br />

title:(+return +"pink panther")<br />

Comments<br />

C-Style comments are supported in query strings.<br />

Example:<br />

"jakarta apache" /* this is a comment in the middle of a normal query string */ OR<br />

jakarta<br />

Comments may be nested.<br />

Differences between Lucene Query Parser and the <strong>Solr</strong> Standard Query Parser<br />

<strong>Solr</strong>'s standard query parser differs from the Lucene Query Parser in the following ways:<br />

A * may be used for either or both endpoints to specify an open-ended range query<br />

field:[* TO 100] finds all field values less than or equal to 100<br />

field:[100 TO *] finds all field values greater than or equal to 100<br />

field:[* TO *] matches all documents with the field<br />

Pure negative queries (all clauses prohibited) are allowed (only as a top-level clause)<br />

-inStock:false finds all field values where inStock is not false<br />

-field:[* TO *] finds all documents without a value for field<br />

A hook into FunctionQuery syntax. You'll need to use quotes to encapsulate the function if it includes<br />

parentheses, as shown in the second example below:<br />

_val_:myfield<br />

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

Support for using any type of query parser as a nested clause.<br />

inStock:true OR {!dismax qf='name manu' v='ipod'}<br />

Support for a special filter(...) syntax to indicate that some query clauses should be cached in the<br />

filter cache (as a constant score boolean query). This allows sub-queries to be cached and re-used in<br />

other queries.<br />

For example inStock:true will be cached and re-used in all three of the queries below:<br />

q=features:songs OR filter(inStock:true)<br />

q=+manu:Apple +filter(inStock:true)<br />

q=+manu:Apple & fq=inStock:true<br />

This can even be used to cache individual clauses of complex filter queries. In the first query below, 3<br />

items will be added to the filter cache (the top level fq and both filter(...) clauses) and in the<br />

second query, there will be 2 cache hits, and one new cache insertion (for the new top level fq):<br />

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

259

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

Saved successfully!

Ooh no, something went wrong!