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 renderSearchStats() { $this->template->title = __('Search statistics'); searchlog::init(SEARCHLOG_DIR); $this->template->stats = searchlog::stats(); }
/** * Initialize * @var string */ public static function init($dir) { parent::init($dir); self::$stats = metatable::open($dir . DIRECTORY_SEPARATOR . '.stats', metatable::READWRITE | metatable::AUTOCLOSE); }