]> BookStack Code Mirror - bookstack/commitdiff
Closes #70.
authorNick Walke <redacted>
Thu, 3 Mar 2016 03:38:23 +0000 (21:38 -0600)
committerNick Walke <redacted>
Thu, 3 Mar 2016 03:38:23 +0000 (21:38 -0600)
Added the ability to search by multi-word terms using double quotes.

app/Repos/BookRepo.php
app/Repos/ChapterRepo.php
app/Repos/PageRepo.php

index d8a24c099734d6a24a757130d842fc14e7445c05..4b45a1a0b92920fd688d8ebffa06b6546bee7b78 100644 (file)
@@ -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), '/')));
index bba6cbe7a134c6ac66843376bda7f279f89b46c6..a3ed0a83738f37355b6f8b053d66d26e8f31f838 100644 (file)
@@ -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), '/')));
index f028a1fccfa642890a9fc1f9aa4e8aec73cdd0c6..fa5f7dd01f50579cfcc1ecd4a567b36385287d0b 100644 (file)
@@ -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);