Closes #70.
Added the ability to search by multi-word terms using double quotes.
Showing
3 changed files
with
24 additions
and
3 deletions
| ... | @@ -226,7 +226,14 @@ class BookRepo | ... | @@ -226,7 +226,14 @@ class BookRepo |
| 226 | */ | 226 | */ |
| 227 | public function getBySearch($term, $count = 20, $paginationAppends = []) | 227 | public function getBySearch($term, $count = 20, $paginationAppends = []) |
| 228 | { | 228 | { |
| 229 | - $terms = explode(' ', $term); | 229 | + preg_match_all('/"(.*?)"/', $term, $matches); |
| 230 | + if (count($matches[1]) > 0) { | ||
| 231 | + $terms = $matches[1]; | ||
| 232 | + $term = trim(preg_replace('/"(.*?)"/', '', $term)); | ||
| 233 | + } else { | ||
| 234 | + $terms = []; | ||
| 235 | + } | ||
| 236 | + $terms = array_merge($terms, explode(' ', $term)); | ||
| 230 | $books = $this->book->fullTextSearchQuery(['name', 'description'], $terms) | 237 | $books = $this->book->fullTextSearchQuery(['name', 'description'], $terms) |
| 231 | ->paginate($count)->appends($paginationAppends); | 238 | ->paginate($count)->appends($paginationAppends); |
| 232 | $words = join('|', explode(' ', preg_quote(trim($term), '/'))); | 239 | $words = join('|', explode(' ', preg_quote(trim($term), '/'))); | ... | ... |
| ... | @@ -131,7 +131,14 @@ class ChapterRepo | ... | @@ -131,7 +131,14 @@ class ChapterRepo |
| 131 | */ | 131 | */ |
| 132 | public function getBySearch($term, $whereTerms = [], $count = 20, $paginationAppends = []) | 132 | public function getBySearch($term, $whereTerms = [], $count = 20, $paginationAppends = []) |
| 133 | { | 133 | { |
| 134 | - $terms = explode(' ', $term); | 134 | + preg_match_all('/"(.*?)"/', $term, $matches); |
| 135 | + if (count($matches[1]) > 0) { | ||
| 136 | + $terms = $matches[1]; | ||
| 137 | + $term = trim(preg_replace('/"(.*?)"/', '', $term)); | ||
| 138 | + } else { | ||
| 139 | + $terms = []; | ||
| 140 | + } | ||
| 141 | + $terms = array_merge($terms, explode(' ', $term)); | ||
| 135 | $chapters = $this->chapter->fullTextSearchQuery(['name', 'description'], $terms, $whereTerms) | 142 | $chapters = $this->chapter->fullTextSearchQuery(['name', 'description'], $terms, $whereTerms) |
| 136 | ->paginate($count)->appends($paginationAppends); | 143 | ->paginate($count)->appends($paginationAppends); |
| 137 | $words = join('|', explode(' ', preg_quote(trim($term), '/'))); | 144 | $words = join('|', explode(' ', preg_quote(trim($term), '/'))); | ... | ... |
| ... | @@ -201,7 +201,14 @@ class PageRepo | ... | @@ -201,7 +201,14 @@ class PageRepo |
| 201 | */ | 201 | */ |
| 202 | public function getBySearch($term, $whereTerms = [], $count = 20, $paginationAppends = []) | 202 | public function getBySearch($term, $whereTerms = [], $count = 20, $paginationAppends = []) |
| 203 | { | 203 | { |
| 204 | - $terms = explode(' ', $term); | 204 | + preg_match_all('/"(.*?)"/', $term, $matches); |
| 205 | + if (count($matches[1]) > 0) { | ||
| 206 | + $terms = $matches[1]; | ||
| 207 | + $term = trim(preg_replace('/"(.*?)"/', '', $term)); | ||
| 208 | + } else { | ||
| 209 | + $terms = []; | ||
| 210 | + } | ||
| 211 | + $terms = array_merge($terms, explode(' ', $term)); | ||
| 205 | $pages = $this->page->fullTextSearchQuery(['name', 'text'], $terms, $whereTerms) | 212 | $pages = $this->page->fullTextSearchQuery(['name', 'text'], $terms, $whereTerms) |
| 206 | ->paginate($count)->appends($paginationAppends); | 213 | ->paginate($count)->appends($paginationAppends); |
| 207 | 214 | ... | ... |
-
Please register or sign in to post a comment