Using the following query, let us look for all the books in our index and return the top five results in JSON format:
http://localhost:8080/solr/collection1/select/?q=cat:book&rows=5&wt=json
As seen earlier, we can form a query URL and use cURL to fire the query via PHP. Decode the JSON response and use it as result.
Let us look at the Solarium code to execute select
queries on Solr. Create a select
query from the Solarium client as follows:
$query = $client->createSelect();
Create a query to search for all books:
$query->setQuery('cat:book');
Suppose we show three results per page. So on the second page, we will start from four and display the next three results.
$query->setStart(3)->setRows(3);
Set which fields should be returned using the following code:
$query->setFields(array('id','name','price','author'));