mirror of
https://code.castopod.org/adaures/castopod
synced 2025-05-24 11:02:00 +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');
|
$query = $this->request->getGet('q');
|
||||||
|
|
||||||
if ($query !== null && $query !== '') {
|
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())
|
$episodes = (new EpisodeModel())
|
||||||
->where('podcast_id', $this->podcast->id)
|
->where('podcast_id', $this->podcast->id)
|
||||||
->where("MATCH (title, description_markdown) AGAINST ('{$query}')");
|
->where("MATCH (title, description_markdown) AGAINST ('{$query}')");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$episodes = (new EpisodeModel())
|
$episodes = (new EpisodeModel())
|
||||||
->where('podcast_id', $this->podcast->id)
|
->where('podcast_id', $this->podcast->id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user