mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-19 13:01:19 +00:00
fix(search-episodes): add fallback sql query using LIKE for search query with less than 4 characters
fixes #236
This commit is contained in:
parent
d4d867121c
commit
e66bf44341
@ -67,9 +67,19 @@ class EpisodeController extends BaseController
|
||||
$query = $this->request->getGet('q');
|
||||
|
||||
if ($query !== null && $query !== '') {
|
||||
$episodes = (new EpisodeModel())
|
||||
->where('podcast_id', $this->podcast->id)
|
||||
->where("MATCH (title, description_markdown) AGAINST ('{$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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user