YiiSolr is a Yii extension that provides a wrapper for the pecl solr library (http://www.php.net/manual/en/book.solr.php) to make fast searching with Yii really easy. The wrapper allows the use of familiar Yii constructs such as models, data providers etc with a solr index.
Requirements ¶
Tested with Yii 1.18 but should work with any recent version
Usage ¶
Please see the github page for usage examples
Unable to use this extension
Could you please eloborate more on how to set up.
I have configured the aliases path and solr component. And also i have started the solr. I have indexed my database using solr. Now i want to use this extension to fetch the records. But initial set up was problem. When i do the phpunit test as mentioned it throws me below mentioned 6errors.
E....................EEEEE Time: 4 seconds, Memory: 23.50Mb There were 6 errors: 1) ASolrConnectionTest::testClientOptions InvalidArgumentException: You must not expect the generic exception class. 2) ASolrSearchableTest::testBasics CDbException: CDbConnection failed to open the DB connection. /var/www/framework/db/CDbConnection.php:388 /var/www/framework/db/CDbConnection.php:331 /var/www/framework/db/CDbConnection.php:468 /var/www/framework/db/schema/sqlite/CSqliteSchema.php:129 /var/www/framework/db/schema/sqlite/CSqliteSchema.php:112 /var/www/framework/db/schema/CDbSchema.php:104 /var/www/framework/db/ar/CActiveRecord.php:2263 /var/www/framework/db/ar/CActiveRecord.php:379 /var/www/framework/db/ar/CActiveRecord.php:394 /var/www/framework/db/ar/CActiveRecord.php:78 /var/www/tdp/protected/packages/solr/tests/ASolrSearchableTest.php:121 3) ASolrSearchableTest::testGetIsModified Trying to get property of non-object /var/www/framework/db/ar/CActiveRecord.php:78 /var/www/tdp/protected/packages/solr/tests/ASolrSearchableTest.php:121 4) ASolrSearchableTest::testFind Trying to get property of non-object /var/www/framework/db/ar/CActiveRecord.php:78 /var/www/tdp/protected/packages/solr/tests/ASolrSearchableTest.php:121 5) ASolrSearchableTest::testDelete Trying to get property of non-object /var/www/framework/db/ar/CActiveRecord.php:78 /var/www/tdp/protected/packages/solr/tests/ASolrSearchableTest.php:121 6) ASolrSearchableTest::testPopulateFromSolr Trying to get property of non-object /var/www/framework/db/ar/CActiveRecord.php:78 /var/www/tdp/protected/packages/solr/tests/ASolrSearchableTest.php:121 FAILURES! Tests: 26, Assertions: 2824, Errors: 6.
And after adding the configuration to the config file. and i use the following code in my controller it shows an error
code:
$criteria = new ASolrCriteria; $criteria->query = "name:test"; // lucene query syntax $docs = ASolrDocument::model()->findAll($criteria);
Error:
include(ASolrCriteria.php): failed to open stream: No such file or directory
Thanks in advance.
Import the extension
You have to import the extension components, so in your config/main.php:
'import' => array('packages.solr.*')
For the tests to work, you must have SQLite installed as well as the example index that comes with Solr. I will try and improve this in future to make it easier to run the tests
How to add fields & also it fetches only 10 records
Hi,
How can add fields. It is not accepting any other name for example
$doc = new ASolrDocument; $doc->id = 123; $doc->name = "test document"; $doc->city = ""; $doc->save(); $doc->getSolrConnection()->commit();
Error
It fetches only 10 records even if i using findAll($criteria); If i manually search from solr it fetches more than 10 records. Can you please tell me how to fetch all records.
I have modified the function query in ASolrDocument to fetch all the records.
if(!$all) { $criteria->setLimit(1); } else { $criteria->setLimit(99999); }
Accessing SolrParams
phpnode,
How would I incorporate SolrParams class so I can add individual params like:
SolrParams::addParam('q.op', 'OR');
Thanks in advance
ASolrCriteria extends SolrQuery which in turn extends SolrParams
So you can just do
$criteria->addParam("foo","bar")
Adding fields
Addenum: For any others new to Solr you need to add your custom fields in the solr config/schema.xml file. Then everything should work fine.
Has anyone figured out the adding new fields to a document for indexing? This will blow up with the error: ERROR: [doc=1] unknown field 'creator'.
$ia_doc = new ASolrDocument(); $ia_doc->id = $doc['id']; $ia_doc->name = $doc['Title']; $ia_doc->creator = $doc['Creator'];
ASolrDocument::setAttributes() and ASolrDocument::add() also return this error.
Thanks,
Dean
Remote Solr server
Will this work with a remote Solr instance? I am assuming I can just specify an alternative host in the config, but I want to make sure before I hassle my webhost to install the PECL Solr package.
Thanks
Re: Will this work with a remote Solr instance?
A. Yes, configure the host settings for the connection in your main config.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.