1
votes

SOLVED

Looks like working when you're very tired is not the same as working after you had a good night's sleep. The problem was with the files inside the prod.dev.index. They were missing. I recreated them and it worked.


I'm using symfony 1.4 with doctrine and Zend Lucene Search integrated. It was working pefect when I first installed it following the Jobeet tutorial. I uploaded the project to another server via svn, and there it doesn't work at all. Now it's not even working in my localhost.

I guess it must be something related to the cache or the indexes, but could anyone help me here? I'm stuck.

Update

Sorry I didn't give more info. I guess it was late at night and I was very tired.

The permissions are OK, the files are in the server after commit, and everything seems ok. Now I noticed that when I want to add a new item it gives me the error:

500 | Internal Server Error | Zend_Search_Lucene_Exception Index doesn't exists in the specified directory.

In my data/ folder I have the podcast.dev.index and podcast.prod.index folders created by lucene before.

The code of my PodcastTable.class.php file is:

 public static function getLuceneIndex() {

    ProjectConfiguration::registerZend();

    if (file_exists($index = PodcastTable::getLuceneIndexFile())) {
        return Zend_Search_Lucene::open($index);
    } else {
        return Zend_Search_Lucene::create($index);
    }
}

public static function getLuceneIndexFile() {
    return sfConfig::get('sf_data_dir') . '/podcast.' . sfConfig::get('sf_environment') . '.index';
}

public function getForLuceneQuery($query, $execute = true) {
    $hits = self::getLuceneIndex()->find($query);

    $pks = array();
    foreach ($hits as $hit) {
        $pks[] = $hit->pk;
    }

    if (empty($pks)) {
        return array();
    }

    $q = $this->createQuery('p')
                    ->where('p.is_published = 1')
                    ->andWhereIn('p.podcast_id', $pks)
                    //->limit(Doctrine_Core::getTable('Configuracion')->getPodcastsPerPage())
                    ->orderBy('p.podcast_id desc');
    if (!$execute){
        return $q;
    }
    return $q->execute();
}

And in the Podcast.class.php file:

public function save(Doctrine_Connection $conn = null) {
    // ...
        $ret = parent::save($conn);

        $this->updateLuceneIndex();

         return $ret;
}

public function delete(Doctrine_Connection $conn = null) {
    $index = PodcastTable::getLuceneIndex();

    if ($hit = $index->find('pk:' . $this->getPodcastId())) {
        $index->delete($hit->id);
    }

    return parent::delete($conn);
}

public function updateLuceneIndex() {
    $index = PodcastTable::getLuceneIndex();

    // remove an existing entry
    if ($hit = $index->find('pk:' . $this->getPodcastId())) {
        $index->delete($hit->podcastId);
    }

    $isActive = $this->getIsPublished();

    // don't index expired and non-activated jobs
    if (!$isActive) {
        return;
    }

    $doc = new Zend_Search_Lucene_Document();

    // store job primary key URL to identify it in the search results
    $doc->addField(Zend_Search_Lucene_Field::UnIndexed('pk', $this->getPodcastId()));

    // index job fields
    $doc->addField(Zend_Search_Lucene_Field::UnStored('name', $this->getPodcastName(), 'utf-8'));
    $doc->addField(Zend_Search_Lucene_Field::UnStored('description', $this->getPodcastDescription(), 'utf-8'));
    $doc->addField(Zend_Search_Lucene_Field::UnStored('image', $this->getImagePath(), 'utf-8'));        

    // add job to the index
    $index->addDocument($doc);
    $index->commit();
}

It used to work before but now it doesn't anymore.

1
We need more information than "doesn't work". What doesn't work and what does? Anything in the logs? Are file permissions ok?Maerlyn

1 Answers

0
votes

Without any further information I would suggest that the Zend Framework you installed during the tutorial was not kept within SVN ... Its pretty simple to re-install ...

  • Just download the Zend Framework from here

  • Unzip it to the lib/vendor/Zend/ directory on your server

  • To use the search you only need to keep the following files/folders :

    • Exception.php
    • Loader/
    • Autoloader.php
    • Search/