Example #1
0
 /**
  * Init fulltext
  * @param string fulltext directory
  */
 public static function init($dir)
 {
     static $done = FALSE;
     if (!$done) {
         self::$dir = rtrim($dir, DIRECTORY_SEPARATOR);
         $index_dir = self::$dir . DIRECTORY_SEPARATOR . 'index';
         if (!is_dir($index_dir)) {
             self::$index = Zend_Search_Lucene::create($index_dir);
         } else {
             self::$index = Zend_Search_Lucene::open($index_dir);
         }
         if (!file_exists(self::$dir . DIRECTORY_SEPARATOR . self::DIRTY_BITMAP_FILENAME)) {
             if (!@touch(self::$dir . DIRECTORY_SEPARATOR . self::DIRTY_BITMAP_FILENAME)) {
                 return FALSE;
             }
         }
         $done = TRUE;
     }
 }
 public function renderDefault($q, $page = 1)
 {
     try {
         $ids = array();
         foreach (fulltext::index()->find($q) as $hit) {
             $ids[] = $hit->getDocument()->id;
         }
         $this->template->paginator = new Paginator();
         $this->template->paginator->setItemCount(count($ids));
         $this->template->paginator->setItemsPerPage(Environment::getVariable('itemsPerPage', 30));
         $this->template->paginator->setPage($page);
         $this->template->products = mapper::products()->findByIds(array_slice($ids, $this->template->paginator->getOffset(), $this->template->paginator->getLength()));
         $this->template->title = __('Search results for ``%s"', $q);
         $this->template->q = $q;
         Environment::getSession(SESSION_SEARCH_NS)->last = $q;
         searchlog::log($q);
     } catch (Exception $e) {
         $this->template->products = array();
     }
 }
 public function actionOptimizeFulltext()
 {
     adminlog::log(__('Attempt to optimize fulltext'));
     // optimize
     fulltext::index()->optimize();
     adminlog::log(__('Sucessfully optimized fulltext'));
     $this->redirect('fulltext');
     $this->terminate();
 }
Example #4
0
 /**
  * Delete
  */
 public function deleteOne(product $p)
 {
     try {
         dibi::query('DELETE FROM [:prefix:products]', 'WHERE [id] = %i', $p->getId(), 'LIMIT 1');
         dibi::query('DELETE FROM [:prefix:pages]', 'WHERE [nice_name] = %s', $p->getNiceName(), 'LIMIT 1');
         //<fulltext>
         foreach (fulltext::index()->termDocs(new Zend_Search_Lucene_Index_Term($p->getId(), 'id')) as $id) {
             fulltext::index()->delete($id);
         }
         fulltext::dirty($p->getId(), FALSE);
         //</fulltext>
         return TRUE;
     } catch (Exception $e) {
         return FALSE;
     }
 }