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.

movie_directors: id, name, has_oscar, ...<br />

To filter movies by directors that have won an Oscar using a <strong>Solr</strong> join on the movie_directors collection, you<br />

can send the following filter query to the movies collection:<br />

fq={!join from=id fromIndex=movie_directors to=director_id}has_oscar:true<br />

Notice that the query criteria of the filter ( has_oscar:true) is based on a field in the collection specified using<br />

fromIndex. Keep in mind that you cannot return fields from the fromIndex collection using join queries, you<br />

can only use the fields for filtering results in the "to" collection (movies).<br />

Next, let's understand how these collections need to be deployed in your cluster. Imagine the movies collection<br />

is deployed to a four node <strong>Solr</strong>Cloud cluster and has two shards with a replication factor of two. Specifically, the<br />

movies collection has replicas on the following four nodes:<br />

node 1: movies_shard1_replica1<br />

node 2: movies_shard1_replica2<br />

node 3: movies_shard2_replica1<br />

node 4: movies_shard2_replica2<br />

To use the movie_directors collection in <strong>Solr</strong> join queries with the movies collection, it needs to have a replica<br />

on each of the four nodes. In other words, movie_directors must have one shard and replication factor of four:<br />

node 1: movie_directors_shard1_replica1<br />

node 2: movie_directors_shard1_replica2<br />

node 3: movie_directors_shard1_replica3<br />

node 4: movie_directors_shard1_replica4<br />

At query time, the JoinQParser will access the local replica of the movie_directors collection to perform the<br />

join. If a local replica is not available or active, then the query will fail. At this point, it should be clear that since<br />

you're limited to a single shard and the data must be replicated across all nodes where it is needed, this<br />

approach works better with smaller data sets where there is a one-to-many relationship between the from<br />

collection and the to collection. Moreover, if you add a replica to the to collection, then you also need to add a<br />

replica for the from collection.<br />

For more information about join queries, see the <strong>Solr</strong> Wiki page on Joins. Erick Erickson has also written a blog<br />

post about join performance called <strong>Solr</strong> and Joins, hosted by SearchHub.org.<br />

Lucene Query Parser<br />

The LuceneQParser extends the QParserPlugin by parsing <strong>Solr</strong>'s variant on the Lucene QueryParser<br />

syntax. This is effectively the same query parser that is used in Lucene. It uses the operators q.op, the default<br />

operator ("OR" or "AND") and df, the default field name.<br />

Example:<br />

{!lucene q.op=AND df=text}myfield:foo +bar -baz<br />

For more information about the syntax for the Lucene Query Parser, see the Classic QueryParser javadocs.<br />

Max Score Query Parser<br />

The MaxScoreQParser extends the LuceneQParser but returns the Max score from the clauses. It does this<br />

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

288

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

Saved successfully!

Ooh no, something went wrong!