By grouping results (“Field Collapsing”), the relevant data is not part of ten “result” element, it’s part of the “grouped” element/object. In XML it looks like this:
<pre><lst name="grouped"></pre>
The question is: how to access those grouped information by using the solr extension?
The problem is located in the Yii solr extension (which is a wrapper for the phpSolrClient) CSolrComponent.php at the get function:
public function get($query, $offset = 0, $limit = 30, $additionalParameters=array()) {
$response = $this->_solr->search($query, $offset, $limit, $additionalParameters);
if ( $response->response->numFound > 0) {
return($response);
}
}
As you can see, the function only returns the array, if numFound is >0. By using the feature FieldCollapsing from solr 3.3+, there is no response object, so numFound will not be > 0.
So we have to add an additional check, if grouping is "active". In that case $response->grouped is set.
By adding this check to the if statement, the get function works with FieldCollapsing as well.
public function get($query, $offset = 0, $limit = 30, $additionalParameters=array()) {
$response = $this->_solr->search($query, $offset, $limit, $additionalParameters);
if ( ($response->response->numFound > 0) or isset($response->grouped) ) {
return($response);
}
}