Exemple #1
0
 public static function getInstance()
 {
     if (!Search::$instance) {
         Search::$instance = new Search();
     }
     return Search::$instance;
 }
Exemple #2
0
 public static function newInstance()
 {
     if (!self::$instance instanceof self) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Exemple #3
0
 public static function newInstance($expired = false)
 {
     if (!self::$instance instanceof self) {
         self::$instance = new self($expired);
     }
     return self::$instance;
 }
 function getContentBody()
 {
     return '';
     $search = Input::instance()->get('search', '');
     $r = Search::instance()->search($search);
     return View::factory('search/results', $r)->render();
 }
Exemple #5
0
 public function get_keyword()
 {
     $keyword = $this->param('keyword', NULL, TRUE);
     $modules = $this->param('modules', NULL);
     $driver = $this->param('driver', NULL);
     $data = Search::instance($driver)->find_by_keyword($keyword, FALSE, $modules);
     $this->response($data);
 }
Exemple #6
0
 public function addurl()
 {
     // use a local file for purpose of demo.
     $filename = MODPATH . "kosearch" . DIRECTORY_SEPARATOR . "examples" . DIRECTORY_SEPARATOR . "kohana_home.html";
     // Note: the Search class is responsible for loading the Zend libraries, so as we
     // want to instantiate Zend_Search_Lucene_Document_Html prior to calling singleton,
     // we must first call Search::instance()->load_search_libs();
     Search::instance()->load_search_libs();
     $doc = Zend_Search_Lucene_Document_Html::loadHTMLFile($filename, TRUE, "utf-8");
     Search::instance()->addDocument($doc);
     $this->index('Kohana page successfully added &darr;&nbsp;<a href="#form2" title="scroll down">scroll down</a>&nbsp;&darr;');
 }
Exemple #7
0
 /**
  * 
  * @param Database_Query $query
  */
 protected function _search_by_keyword(Database_Query $query, $only_title = FALSE)
 {
     if ($this->search_key === NULL or trim($this->search_key) == '') {
         return $query;
     }
     $keyword = $this->_ctx->get($this->search_key);
     if (empty($keyword)) {
         return $query;
     }
     $ids = Search::instance()->find_by_keyword($keyword, $only_title, 'ds_' . $this->ds_id, NULL);
     $ids = Arr::get($ids, 'ds_' . $this->ds_id);
     if (!empty($ids)) {
         return $query->where('d.id', 'in', array_keys($ids));
     }
     return $query;
 }
Exemple #8
0
 /**
  * 
  * @return integer
  */
 public function count_total()
 {
     $keyword = $this->keyword();
     $this->_total = Search::instance()->count_by_keyword($keyword, FALSE, $this->modules());
     return $this->_total;
 }
Exemple #9
0
 /**
  * Метод используется для поиска по документам по ключевому слову.
  * 
  * Ключевое слово передается в качестве $_GET запроса с ключем "keyword"
  * 
  * @param Database_Query $query
  * @return Database_Query
  */
 public function search_by_keyword(Database_Query $query)
 {
     $keyword = Request::initial()->query('keyword');
     if (empty($keyword)) {
         return $query;
     }
     if ($this->_section->is_indexable()) {
         $ids = Search::instance()->find_by_keyword($keyword, FALSE, 'ds_' . $this->_section->id(), NULL);
         $ids = Arr::get($ids, 'ds_' . $this->_section->id());
         if (!empty($ids)) {
             $query->where('d.id', 'in', array_keys($ids));
         } else {
             $query->where('d.id', '=', 0);
         }
     } else {
         $query->where_open()->where('d.id', 'like', '%' . $keyword . '%')->or_where('d.header', 'like', '%' . $keyword . '%')->where_close();
     }
     return $query;
 }
	private function get_search_result()
	{
		if(!isset($this->search_result))
		{
        global $container;
        $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
        $posts = $repository->getActivePosts();
			
			$this->search_result = Search::instance()
				->setQuery($this->query)
				->setResult($posts)
				->setWeight(self::$SEARCH_WEIGHTS)
				->perform();
		}
		return $this->search_result;
	}
Exemple #11
0
 /**
  * Удаление документов из поискового индекса
  * 
  * @param array $ids
  * @return \Datasource_Section
  */
 public function remove_from_index(array $ids = NULL)
 {
     if (!$this->is_indexable()) {
         return $this;
     }
     Search::instance()->remove_from_index('ds_' . $this->id(), $ids);
 }
Exemple #12
0
 /**
  * 
  * @return integer
  */
 public function count_total()
 {
     $keyword = $this->_ctx->get($this->search_key);
     $this->_total = Search::instance()->count_by_keyword($keyword, FALSE, 'pages');
     return $this->_total;
 }
Exemple #13
0
    foreach ($parts as $id => $content) {
        $part = ORM::factory('page_part', (int) $id);
        if ((bool) $part->is_indexable) {
            $indexable_content .= ' ' . $part->content;
        }
        if ($content == $part->content) {
            continue;
        }
        $part->values(array('content' => $content))->save();
    }
    if (in_array($page->status_id, Model_Page_Front::get_statuses())) {
        Search::instance()->add_to_index('pages', $page->id, $page->title, $indexable_content, '', array('uri' => $page->get_uri()));
    } else {
        Search::instance()->remove_from_index('pages', $page->id);
    }
});
Observer::observe('update_search_index', function () {
    $pages = ORM::factory('page')->find_all();
    foreach ($pages as $page) {
        $indexable_content = '';
        $parts = ORM::factory('page_part')->where('page_id', '=', $page->id)->where('is_indexable', '=', 1)->find_all();
        foreach ($parts as $part) {
            $indexable_content .= ' ' . $part->content;
        }
        Search::instance()->add_to_index('pages', $page->id, $page->title, $indexable_content, '', array('uri' => $page->get_uri()));
    }
});
// Чистка кеша частей страниц при редактирвании или удалении страницы
Observer::observe(array('page_add_after_save', 'page_edit_after_save', 'page_delete'), function ($page) {
    Cache::instance()->delete_tag('page_parts');
});