Fixed issue #49.

This commit is contained in:
Parziphal 2014-01-21 20:16:33 -05:00
parent 5776745bb8
commit 685a3230f8

View File

@ -96,29 +96,35 @@ class CommentController extends ApplicationController
public function search() public function search()
{ {
$query = Comment::order('id desc'); $query = Comment::order('id desc');
// $conds = $cond_params = $search_terms = array(); $search_query = explode(' ', $this->params()->query);
if ($this->params()->query) { $search_terms = array();
$keywords = array();
foreach (explode(' ', $this->params()->query) as $s) { foreach ($search_query as $s) {
if (!$s) continue; if (!$s) {
continue;
if (strpos($s, 'user:') === 0 && strlen($s) > 5) {
list($search_type, $param) = explode(':', $s);
if ($user = User::where(['name' => $param])->first()) {
$query->where('user_id = ?', $user->id);
} else {
$query->where('false');
}
continue;
}
$search_terms[] = $s;
} }
if (strpos($s, 'user:') === 0 && strlen($s) > 5) {
list($search_type, $param) = explode(':', $s);
if ($user = User::where(['name' => $param])->first()) {
$query->where('user_id = ?', $user->id);
} else {
$query->where('false');
}
continue;
}
$search_terms[] = $s;
}
if ($search_terms) {
$query->where('body LIKE ?', '%' . implode('%', $search_terms) . '%'); $query->where('body LIKE ?', '%' . implode('%', $search_terms) . '%');
// $options['conditions'] = array_merge(array(implode(' AND ', $conds)), $cond_params); } else {
} else # MI: this query makes no sense, it will return nothing.
$query->where('false'); $query->where('false');
}
$this->comments = $query->paginate($this->page_number(), 30); $this->comments = $query->paginate($this->page_number(), 30);