Yii website's search feature

Hello Yii community,

I want to know if you anybody could give me some pointers in how to implement a content search feature similar to what the Yii website has. I want users to enter words in the search input field and return a list of blog entries and forum posts which contain any of the searched words.

Any help is greatly appreciated,

thank you.

Site search on yiiframework.com is built using solr http://lucene.apache.org/solr/

http://www.yiiframework.com/extension/solr or http://www.php.net/manual/es/book.solr.php

I recommend using Sphinx instead of Solr. It’s much more efficient: http://sphinxsearch.com/

Hi samdark, have you successfully setup sphinx on a linux based system? Is there any extension (.so) around for macosx? or is the PECL the only one available?

I have already been through https://www.ibm.com/developerworks/library/os-php-sphinxsearch/ but a good advice from someone who has successfully integrated this with Yii will be more than helpful.

I am planning to implement this in one of my current projects on a linux server. (I devevop on a macosx snow l. php 5.3 machine)

Thanks in advance

thank you guys for the feedback.

Antonio those links are very helpful.

Has anybody ever tried using "Zend_Search_Lucene"? Does anybody recommend it?

Yes, I did. You can use either PECL, official PHP client or Sphinx Yii extension. I’ve used official PHP client but planning to switch to Yii extension.

I’ve used Sphinx, not SphinxSE which integrates with MySQL.

Can’t recommend it. Same ideas as SOLR but implemented with PHP and a lot slower. Use it only if you can’t set up Sphinx or Solr.

Thanks for pointing me to that extension…

I have successfully installed "sphinx" in my macosx computer. I am so impress with its config easiness and performance that I would like to share it with you.

Once installed Sphinx configuration options are nearly ‘out of the box’ set. Nevertheless, a good look onto its documentation is a must.

Have a world database and cities are the most populated table (2,717,369 rows) and I have tested sphinx against mySQL and the results are quite impressive. For the test I have also used the Yii extension pointed by samdark. I just wanted to check, what it was the response time since I get the search results until I have the rows as returned by SQL. With sphinx implies that you query the DB again providing the returned ids of matched elements but the results are equally amazing:




  // get a reference to the DGSphinxSearch extension

  $search = Yii::app()->search;

  

  // start counter

  $timeStart = microtime(true);

  // searching for any word starting with 'poll'

  $search->select('*')->

  	from('city')->

  	where('@name poll*');


  // search

  $result = $search->search();

  // drop count to check against those returned by mySQL

  echo $result->getTotal().'<br/>';

  // get the id list of the returned matches

  $ids =  $result->getIdList();

  

  // get the records

  $result = Yii::app()->getDb()->createCommand('SELECT city AS name, countryCode, region FROM tbl_city WHERE id IN ('.implode(',',$ids).')')->query();

  	

  echo 'Sphinx execution time: '.(microtime(true)-$timeStart) .' seconds<br/>';

  

  // reset counter

  $timeStart = microtime(true);

  

 // query mySQL DB 

  $result = Yii::app()->getDb()->createCommand('SELECT city as name, region, countryCode From tbl_city WHERE city LIKE "poll%"')->query();

   

   // display time 

   echo 'MySQL query execution time: '.(microtime(true)-$timeStart) .' seconds';




As you can see in the code, I have also included the second query to the calculated time, and this is the result:

Amazing, isnt it?

Hi samdark, can Sphinx search for pdf file?

Hello, everybody. I’m from Russia, and I’m not sure that my English is well, but I’ll try to explain my problem. I hope, You’ll understand me. I’m trying to create web application (site) based on Yii\mongodb\solr. And I’ve got a problem. Mongo works well, but YiiSolrExtension often returns an error: ‘“400” Status: undefined field #my_field#’. I declared fields in Apache_Solr_Document, and I’ve never seen this message again, when I tried to add record. But when I tried to search some rows with a condition, I’ve saw this message again. It tells me that #my_field# (which was declared) is undefined. I’ll be appreciated if anyone could explain me what I’m doing wrong. Thanks

Very good discussion. New knowledges about searching in site thank you ;)

this is nice topic

are solr are really can handle search pdf or word doc text?

yes amazing :D

and nice usage example, cheers!