Executing filter queries

To add a filter query to our existing query, first we need to create a filter query from our Solr query module.

$query = $client->createSelect();
$query->setQuery('cat:book'),
$fquery = $query->createFilterQuery('Availability'),

The string provided as a parameter to the createFilterQuery() function is used as key for the filter query. This key can be used to retrieve the filter query associated with this query. Once the filter query module is available, we can use the setQuery() function to set a filter query for this Solarium query.

In the preceding piece of code, we have created a filter query by the name of Availability. We will set the filter query for key Availability as instock:true and then execute the complete query as follows:

$fquery->setQuery('inStock:true'),
$resultSet = $client->select($query);

Once the resultset is available, it can be iterated over to get and process the results.

Let us check Solr logs and see the query that was sent to Solr.

70981712 [http-bio-8080-exec-8] INFO  org.apache.solr.core.SolrCore  – [collection1] webapp=/solr path=/select params={mm=70%25&tie=0.1&pf2=name^2+author^1.8+series_t^1.3&q.alt=*:*&wt=json&rows=25&defType=edismax&omitHeader=true&pf=series_t^5&fl=id,name,price,author,score,last_modified&start=0&q=cat:book+-author:martin&boost=recip(ms(NOW,last_modified),1,1,1)&fq=inStock:true} hits=19 status=0 QTime=4

We can see the fq parameter inStock:true appended to the parameter list of our Solr query.

The getFilterQuery(string $key) function can be used to retrieve the filter query associated with a Solarium query.

echo $fquery->getFilterQuery('Availability')->getQuery();
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.201.209