Пример #1
0
 /**
  * 
  * @param string $keyword
  * @param boolean $only_title
  * @param string $modules
  * @param integer $limit
  * @param integer $offset
  * @param boolean $fulltextsearch
  * @return Database_Query
  */
 protected function _get_query(Database_Query $query, $keyword, $only_title = FALSE, $modules = NULL, $limit = 50, $offset = 0)
 {
     $keyword = $this->stem_query($keyword);
     if ($limit !== NULL) {
         $query->limit((int) $limit)->offset($offset);
     }
     if (is_array($modules)) {
         $query->where('search_index.module', 'in', $modules);
     } elseif ($modules !== NULL) {
         $query->where('search_index.module', '=', $modules);
     }
     if ($this->config('full_text_search') === TRUE) {
         $query->where(DB::expr('MATCH(`search_index`.`header`, `search_index`.`content`)'), 'AGAINST', DB::expr("('" . self::match_against_query($keyword) . "' IN BOOLEAN MODE)"));
     } else {
         $words = explode(' ', $keyword);
         $query->where_open();
         $query->where_open();
         foreach ($words as $word) {
             if (!empty($word)) {
                 $query->where('search_index.header', 'like', '%' . $word . '%');
             }
         }
         $query->where_close();
         if ($only_title === FALSE) {
             $query->or_where_open();
             foreach ($words as $word) {
                 if (!empty($word)) {
                     $query->where('search_index.content', 'like', '%' . $word . '%');
                 }
             }
             $query->where_close();
         }
         $query->where_close();
     }
     return $query;
 }
Пример #2
0
 public function search_by_keyword(Database_Query $query)
 {
     $keyword = Request::initial()->query('search');
     if (is_array($keyword)) {
         $fields = array();
         foreach ($keyword as $field => $value) {
             if (in_array($field, $this->fields())) {
                 continue;
             }
             $fields[$field] = $value;
         }
         if (!empty($fields)) {
             $query->where_open();
             foreach ($fields as $field => $value) {
                 $field = Arr::get($this->fields(), $field);
                 $query->and_where(Arr::get($field, 'db_name'), 'like', '%' . $value . '%');
             }
             return $query->where_close();
         }
         return $query;
     } else {
         if (empty($keyword)) {
             return $query;
         }
     }
     $query->where_open()->or_where('d.id', 'like', '%' . $keyword . '%')->or_where('d.header', 'like', '%' . $keyword . '%');
     foreach ($this->fields() as $field) {
         if (Arr::get($field, 'searchable') === FALSE or Arr::get($field, 'db_name') === NULL) {
             continue;
         }
         $query->or_where(Arr::get($field, 'db_name'), 'like', '%' . $keyword . '%');
     }
     return $query->where_close();
 }