]> BookStack Code Mirror - bookstack/commitdiff
Found the source of the issue, not sure how to fix 72/head
authorNick Walke <redacted>
Fri, 4 Mar 2016 08:33:57 +0000 (02:33 -0600)
committerNick Walke <redacted>
Fri, 4 Mar 2016 08:33:57 +0000 (02:33 -0600)
app/Entity.php
app/Repos/PageRepo.php

index 42323628ac8c3f09319ac34aa681a6580ff34339..122aa2aa2dfc8472f189bdf0d8f894fd4fe5b5ae 100644 (file)
@@ -100,10 +100,14 @@ abstract class Entity extends Model
      */
     public static function fullTextSearchQuery($fieldsToSearch, $terms, $wheres = [])
     {
-        $termString = '';
-        foreach ($terms as $term) {
-            $termString .= htmlentities($term) . '* ';
+        foreach ($terms as $key => $term) {
+            $term = htmlentities($term);
+            if (preg_match('/\s/', $term)) {
+                $term = '"' . $term . '"';
+            }
+            $terms[$key] = $term . '*';
         }
+        $termString = "'" . implode(' ', $terms) . "'";
         $fields = implode(',', $fieldsToSearch);
         $termStringEscaped = \DB::connection()->getPdo()->quote($termString);
         $search = static::addSelect(\DB::raw('*, MATCH(name) AGAINST('.$termStringEscaped.' IN BOOLEAN MODE) AS title_relevance'));
@@ -113,9 +117,8 @@ abstract class Entity extends Model
         foreach ($wheres as $whereTerm) {
             $search->where($whereTerm[0], $whereTerm[1], $whereTerm[2]);
         }
-
         // Load in relations
-        if (static::isA('page'))  {
+        if (static::isA('page')) {
             $search = $search->with('book', 'chapter', 'createdBy', 'updatedBy');
         } else if (static::isA('chapter')) {
             $search = $search->with('book');
index fa5f7dd01f50579cfcc1ecd4a567b36385287d0b..bfaff79ae3ce22fec0bd00f9f63a6e1b2e9b6df6 100644 (file)
@@ -208,7 +208,9 @@ class PageRepo
         } else {
             $terms = [];
         }
-        $terms = array_merge($terms, explode(' ', $term));
+        if (!empty($term)) {
+            $terms = array_merge($terms, explode(' ', $term));
+        }
         $pages = $this->page->fullTextSearchQuery(['name', 'text'], $terms, $whereTerms)
             ->paginate($count)->appends($paginationAppends);