Solr Extension and Solr 3.3+ support

Hi,

I’m using the Yii Solr extension for my application build on Yii (http://www.yiiframework.com/extension/solr/#hh5), which works very well.

I updated Solr to 3.3 (and also 4.0) in order to use the "Field Collapsing" - Feature.

Right now, it looks like, the extension only process the "result" element/object of the response (in XML):

<pre><result name="response" numFound="218" start="0"></pre>

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?

Thank you.

To answer my own question:

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);


      }


    }