Yii 1.1: solr

Solr component
13 followers

This extension is Yii version of Solr-client-Php. It uses Solr-client-Php to communicate with the Solr server

Resources

Documentation

Requirements

  • Yii 1.0 or above

Installation

  • Extract the release file under protected/extensions

Add to protected/config/main.php // autoloading model and component classes

'import'=>array(
        'application.models.*',
               'application.components.*',
              'application.extensions.solr.*',
    )
 
'components'=>array(
       'userSearch'=>array(
            'class'=>'CSolrComponent',
            'host'=>'localhost',
            'port'=>8080,
            'indexPath'=>'/solr/user'
        ),
      'commentSearch'=>array(
            'class'=>'CSolrComponent',
            'host'=>'localhost',
            'port'=>8080,
            'indexPath'=>'/solr/comment'
        ),

Usage

See the following code example:

//To add or update an entry in your index
Yii::app()->commentSearch->updateOne(array('id'=>1,
                            'name'=>'tom',
                            'age'=>22)
                      );
//To add or update many documents
 
Yii::app()->userSearch->updateMany(array('1'=>array('id'=>1,
                                        'name'=>'tom',
                                        'age'=> 25),
                             '2'=>array('id'=>2,
                                        'name'=>'pitt')
                     );
 
//To search in your index
$result= Yii::app()->userSearch->get('name:tom',0,20);
echo "Results number is ".$result->response->numFound;
foreach($result->response->docs as $doc){
   echo "{$doc->name} <br>";
}

See http://code.google.com/p/solr-php-client/ for more functions

Change Log

July 2, 2010

  • Initial release.

Total 4 comments

#7188 report it
Johnny at 2012/03/02 02:26am
Good simple example

Thx very much for sharing this extension.

Since the source code is no longer updated for a long time.

We could apply the latest version of Solr-Client-PHP by self:

Just get the latest version and extract the release file under "phpSolrClient".

#5775 report it
wisp at 2011/11/11 06:04am
Another bug

Hi, I'm very happy with this extension. But I encountered a bug in the 'get' method.

the following condition doesn't work when using grouped fields

if ( $response->response->numFound > 0 ) { return($response); }

I've removed this check and now everything works

#115 report it
rAWTAZ at 2010/09/09 04:20pm
Small bug

Line 65 in the initial release lacks a ; at the end of the line.

#288 report it
tommythunder at 2010/07/18 11:12pm
Simple but great!

Thx. But it will be a good idea if you create a criteria for search

Leave a comment

Please to leave your comment.

Create extension
Downloads