diff --git a/app/Repos/BookRepo.php b/app/Repos/BookRepo.php index d8a24c099..4b45a1a0b 100644 --- a/app/Repos/BookRepo.php +++ b/app/Repos/BookRepo.php @@ -226,7 +226,14 @@ class BookRepo */ public function getBySearch($term, $count = 20, $paginationAppends = []) { - $terms = explode(' ', $term); + preg_match_all('/"(.*?)"/', $term, $matches); + if (count($matches[1]) > 0) { + $terms = $matches[1]; + $term = trim(preg_replace('/"(.*?)"/', '', $term)); + } else { + $terms = []; + } + $terms = array_merge($terms, explode(' ', $term)); $books = $this->book->fullTextSearchQuery(['name', 'description'], $terms) ->paginate($count)->appends($paginationAppends); $words = join('|', explode(' ', preg_quote(trim($term), '/'))); diff --git a/app/Repos/ChapterRepo.php b/app/Repos/ChapterRepo.php index bba6cbe7a..a3ed0a837 100644 --- a/app/Repos/ChapterRepo.php +++ b/app/Repos/ChapterRepo.php @@ -131,7 +131,14 @@ class ChapterRepo */ public function getBySearch($term, $whereTerms = [], $count = 20, $paginationAppends = []) { - $terms = explode(' ', $term); + preg_match_all('/"(.*?)"/', $term, $matches); + if (count($matches[1]) > 0) { + $terms = $matches[1]; + $term = trim(preg_replace('/"(.*?)"/', '', $term)); + } else { + $terms = []; + } + $terms = array_merge($terms, explode(' ', $term)); $chapters = $this->chapter->fullTextSearchQuery(['name', 'description'], $terms, $whereTerms) ->paginate($count)->appends($paginationAppends); $words = join('|', explode(' ', preg_quote(trim($term), '/'))); diff --git a/app/Repos/PageRepo.php b/app/Repos/PageRepo.php index f028a1fcc..fa5f7dd01 100644 --- a/app/Repos/PageRepo.php +++ b/app/Repos/PageRepo.php @@ -201,7 +201,14 @@ class PageRepo */ public function getBySearch($term, $whereTerms = [], $count = 20, $paginationAppends = []) { - $terms = explode(' ', $term); + preg_match_all('/"(.*?)"/', $term, $matches); + if (count($matches[1]) > 0) { + $terms = $matches[1]; + $term = trim(preg_replace('/"(.*?)"/', '', $term)); + } else { + $terms = []; + } + $terms = array_merge($terms, explode(' ', $term)); $pages = $this->page->fullTextSearchQuery(['name', 'text'], $terms, $whereTerms) ->paginate($count)->appends($paginationAppends);