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.

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

{"count(*)":9158,"to":"pete.davis@enron.com"},<br />

{"count(*)":6244,"to":"tana.jones@enron.com"},<br />

{"count(*)":5874,"to":"jeff.dasovich@enron.com"},<br />

{"count(*)":5867,"to":"sara.shackleton@enron.com"},<br />

{"count(*)":5595,"to":"steven.kean@enron.com"},<br />

{"count(*)":4904,"to":"vkaminski@aol.com"},<br />

{"count(*)":4622,"to":"mark.taylor@enron.com"},<br />

{"count(*)":3819,"to":"kay.mann@enron.com"},<br />

{"count(*)":3678,"to":"richard.shapiro@enron.com"},<br />

{"count(*)":3653,"to":"kate.symes@enron.com"},<br />

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

}<br />

Notice that the result set is an array of tuples with key/value pairs that match the SQL column list. The final tuple<br />

contains the EOF flag which signals the end of the stream.<br />

<strong>Solr</strong> SQL Syntax<br />

<strong>Solr</strong> supports a broad range of SQL syntax.<br />

SQL Parser is Case Insensitive<br />

The SQL parser being used by <strong>Solr</strong> to translate the SQL statements is case insensitive. However, for<br />

ease of reading, all examples on this page use capitalized keywords.<br />

SELECT Statements<br />

<strong>Solr</strong> supports limited and unlimited select queries. The syntax between the two types of queries are identical<br />

except for the LIMIT clause in the SQL statement. However, they have very different execution plans and<br />

different requirements for how the data is stored. The sections below explores both types of queries.<br />

Basic SELECT statement with LIMIT<br />

A limited select query follows this basic syntax:<br />

SELECT fieldA as fa, fieldB as fb, fieldC as fc FROM tableA WHERE fieldC = 'term1<br />

term2' ORDER BY fa desc LIMIT 100<br />

We've covered many syntax options with this example, so let's walk through what's possible below.<br />

WHERE Clause and Boolean Predicates<br />

The WHERE clause allows <strong>Solr</strong>'s search syntax to be injected into the SQL query. In the example:<br />

WHERE fieldC = 'term1 term2'<br />

The predicate above will execute a full text search for the phrase 'term1 term2' in fieldC.<br />

To execute a non-phrase query, simply add parens inside of the single quotes. For example:<br />

WHERE fieldC = '(term1 term2)'<br />

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

429

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

Saved successfully!

Ooh no, something went wrong!