Example #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;
 }