Commit e66bf443 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

fix(search-episodes): add fallback sql query using LIKE for search query with...

fix(search-episodes): add fallback sql query using LIKE for search query with less than 4 characters

fixes #236
parent d4d86712
Loading
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -67,9 +67,19 @@ class EpisodeController extends BaseController
        $query = $this->request->getGet('q');

        if ($query !== null && $query !== '') {
            // Default value for MySQL Full-Text Search's minimum length of words is 4.
            // Use LIKE operator as a fallback.
            if (strlen($query) < 4) {
                $episodes = (new EpisodeModel())
                    ->where('podcast_id', $this->podcast->id)
                    ->like('title', $query)
                    ->orLike('description_markdown', $query)
                    ->orderBy('created_at', 'desc');
            } else {
                $episodes = (new EpisodeModel())
                    ->where('podcast_id', $this->podcast->id)
                    ->where("MATCH (title, description_markdown) AGAINST ('{$query}')");
            }
        } else {
            $episodes = (new EpisodeModel())
                ->where('podcast_id', $this->podcast->id)