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.

Some streaming functions act as stream sources to originate the stream flow. Other streaming functions act as<br />

stream decorators to wrap other stream functions and perform operations on the stream of tuples. Many streams<br />

functions can be parallelized across a worker collection. This can be particularly powerful for relational algebra<br />

functions.<br />

Streaming Requests and Responses<br />

<strong>Solr</strong> has a /stream request handler that takes streaming expression requests and returns the tuples as a JSON<br />

stream. This request handler is implicitly defined, meaning there is nothing that has to be defined in solrconfi<br />

g.xml.<br />

The /stream request handler takes one parameter, expr, which is used to specify the streaming<br />

expression. For example, this curl command encodes and POSTs a simple search() expression to the /strea<br />

m handler:<br />

curl --data-urlencode 'expr=search(enron_emails,<br />

q="from:1800flowers*",<br />

fl="from, to",<br />

sort="from asc",<br />

qt="/export")'<br />

http://localhost:8983/solr/enron_emails/stream<br />

Details of the parameters for each function are included below.<br />

For the above example the /stream handler responded with the following JSON response:<br />

{"result-set":{"docs":[<br />

{"from":"1800flowers.133139412@s2u2.com","to":"lcampbel@enron.com"},<br />

{"from":"1800flowers.93690065@s2u2.com","to":"jtholt@ect.enron.com"},<br />

{"from":"1800flowers.96749439@s2u2.com","to":"alewis@enron.com"},<br />

{"from":"1800flowers@1800flowers.flonetwork.com","to":"lcampbel@enron.com"},<br />

{"from":"1800flowers@1800flowers.flonetwork.com","to":"lcampbel@enron.com"},<br />

{"from":"1800flowers@1800flowers.flonetwork.com","to":"lcampbel@enron.com"},<br />

{"from":"1800flowers@1800flowers.flonetwork.com","to":"lcampbel@enron.com"},<br />

{"from":"1800flowers@1800flowers.flonetwork.com","to":"lcampbel@enron.com"},<br />

{"from":"1800flowers@shop2u.com","to":"ebass@enron.com"},<br />

{"from":"1800flowers@shop2u.com","to":"lcampbel@enron.com"},<br />

{"from":"1800flowers@shop2u.com","to":"lcampbel@enron.com"},<br />

{"from":"1800flowers@shop2u.com","to":"lcampbel@enron.com"},<br />

{"from":"1800flowers@shop2u.com","to":"ebass@enron.com"},<br />

{"from":"1800flowers@shop2u.com","to":"ebass@enron.com"},<br />

{"EOF":true,"RESPONSE_TIME":33}]}<br />

}<br />

Note the last tuple in the above example stream is {"EOF":true,"RESPONSE_TIME":33}. The EOF indicates<br />

the end of the stream. To process the JSON response, you'll need to use a streaming JSON implementation<br />

becausestreaming expressions are designed to return the entire result set which may have millions of records. In<br />

your JSON client you'll need to iterate each doc (tuple) and check for the EOF tuple to determine the end of<br />

stream.<br />

The org.apache.solr.client.solrj.io package provides Java classes that compile streaming<br />

expressions into streaming API objects. These classes can be used to execute streaming expressions from<br />

inside a Java application. For example:<br />

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

407

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

Saved successfully!

Ooh no, something went wrong!