Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I used lucene search with Symfony and here is how I use it:</p> <pre><code>// Called when an object is saved public function save(Doctrine_Connection $conn = null) { $conn = $conn ? $conn : $this-&gt;getTable()-&gt;getConnection(); $conn-&gt;beginTransaction(); try { $ret = parent::save($conn); $this-&gt;updateLuceneIndex(); $conn-&gt;commit(); return $ret; } catch (Exception $e) { $conn-&gt;rollBack(); throw $e; } } public function updateLuceneIndex() { $index = $this-&gt;getTable()-&gt;getLuceneIndex(); // remove existing entries foreach ($index-&gt;find('pk:' . $this-&gt;getId()) as $hit) { $index-&gt;delete($hit-&gt;id); } $doc = new Zend_Search_Lucene_Document(); // store job primary key to identify it in the search results $doc-&gt;addField(Zend_Search_Lucene_Field::UnIndexed('pk', $this-&gt;getId())); // index job fields $doc-&gt;addField(Zend_Search_Lucene_Field::unStored('title', Utils::stripAccent($this-&gt;getTitle()), 'utf-8')); $doc-&gt;addField(Zend_Search_Lucene_Field::unStored('summary', Utils::stripAccent($this-&gt;getSummary()), 'utf-8')); // add job to the index $index-&gt;addDocument($doc); $index-&gt;commit(); } // Called when an object is deleted public function delete(Doctrine_Connection $conn = null) { $index = $this-&gt;getTable()-&gt;getLuceneIndex(); foreach ($index-&gt;find('pk:' . $this-&gt;getId()) as $hit) { $index-&gt;delete($hit-&gt;id); } return parent::delete($conn); } </code></pre> <p>And here is how I get my index:</p> <pre><code>public static function getInstance() { return Doctrine_Core::getTable('Work'); } static public function getLuceneIndexFile() { return sfConfig::get('sf_data_dir') . '/indexes/work.' . sfConfig::get('sf_environment') . '.index'; } static public function getLuceneIndex() { ProjectConfiguration::registerZend(); if (file_exists($index = self::getLuceneIndexFile())) { return Zend_Search_Lucene::open($index); } else { return Zend_Search_Lucene::create($index); } } </code></pre> <p>Hope it will help you ;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload