Zend Lucene 検索を Symfony プロジェクトに統合するために、Jobeet チュートリアルに従っていますが、うまく動作しないようです。config/ProjectConfiguration.class.php に次のコードを追加しました
class ProjectConfiguration extends sfProjectConfiguration
{
static protected $zendLoaded = false;
static public function registerZend()
{
if (self::$zendLoaded)
{
return;
}
set_include_path(sfConfig::get('sf_lib_dir').'/vendor'.PATH_SEPARATOR.get_include_path());
require_once sfConfig::get('sf_lib_dir').'/vendor/Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
self::$zendLoaded = true;
}
このコードを CarTable.class.php にも追加しました
static public function getLuceneIndex()
{
ProjectConfiguration::registerZend();
if (file_exists($index = self::getLuceneIndexFile()))
{
return Zend_Search_Lucene::open($index);
}
return Zend_Search_Lucene::create($index);
}
static public function getLuceneIndexFile()
{
return sfConfig::get('sf_data_dir').'/car.'.sfConfig::get('sf_environment').'.index';
}
最後に、Car.class.php に次のコードを追加しました。
public function updateLuceneIndex()
{
$index = CarTable::getLuceneIndex();
foreach ($index->find('pk:'.$this->getIditem()) as $hit)
{
$index->delete($hit->id);
}
if (!$this->getActivated())
{
return;
}
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Keyword('pk', $this->getIditem()));
$doc->addField(Zend_Search_Lucene_Field::UnStored('title', $this->getTitle(), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::UnStored('features', $this->getFeatures(), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::UnStored('location_city', $this->getLocation_city(), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::UnStored('location_state', $this->getLocation_state(), 'utf-8'));
$index->addDocument($doc);
$index->commit();
}
public function delete(Doctrine_Connection $conn = null)
{
$index = CarTable::getLuceneIndex();
foreach ($index->find('pk:'.$this->getIditem()) as $hit)
{
$index->delete($hit->id);
}
return parent::delete($conn);
}
そしてもちろん、保存機能に次の数行を追加しました。
$conn = $conn ? $conn : $this->getTable()->getConnection();
$conn->beginTransaction();
try
{
$ret = parent::save($conn);
$this->updateLuceneIndex();
$conn->commit();
return $ret;
}
catch (Exception $e)
{
$conn->rollBack();
throw $e;
}
Zend Framework の "library" フォルダーの内容を lib/vendor/Zend フォルダーに抽出しました。
しかし、コマンドを実行するたびに
php symfony doctrine:data-load
それは最後まで実行され、すべてのフィクスチャがロードされますが、データ フォルダーにインデックス ファイルを含むフォルダーが作成されません。何が間違っているのかわかりません。
ここに私の参照があります (Jobeet チュートリアル) http://www.symfony-project.org/jobeet/1_4/Doctrine/en/17
ところで、私は Symfony 1.4 (Doctrine) を使用しています。