Nick Walke

Found the source of the issue, not sure how to fix

...@@ -100,10 +100,14 @@ abstract class Entity extends Model ...@@ -100,10 +100,14 @@ abstract class Entity extends Model
100 */ 100 */
101 public static function fullTextSearchQuery($fieldsToSearch, $terms, $wheres = []) 101 public static function fullTextSearchQuery($fieldsToSearch, $terms, $wheres = [])
102 { 102 {
103 - $termString = ''; 103 + foreach ($terms as $key => $term) {
104 - foreach ($terms as $term) { 104 + $term = htmlentities($term);
105 - $termString .= htmlentities($term) . '* '; 105 + if (preg_match('/\s/', $term)) {
106 + $term = '"' . $term . '"';
107 + }
108 + $terms[$key] = $term . '*';
106 } 109 }
110 + $termString = "'" . implode(' ', $terms) . "'";
107 $fields = implode(',', $fieldsToSearch); 111 $fields = implode(',', $fieldsToSearch);
108 $termStringEscaped = \DB::connection()->getPdo()->quote($termString); 112 $termStringEscaped = \DB::connection()->getPdo()->quote($termString);
109 $search = static::addSelect(\DB::raw('*, MATCH(name) AGAINST('.$termStringEscaped.' IN BOOLEAN MODE) AS title_relevance')); 113 $search = static::addSelect(\DB::raw('*, MATCH(name) AGAINST('.$termStringEscaped.' IN BOOLEAN MODE) AS title_relevance'));
...@@ -113,9 +117,8 @@ abstract class Entity extends Model ...@@ -113,9 +117,8 @@ abstract class Entity extends Model
113 foreach ($wheres as $whereTerm) { 117 foreach ($wheres as $whereTerm) {
114 $search->where($whereTerm[0], $whereTerm[1], $whereTerm[2]); 118 $search->where($whereTerm[0], $whereTerm[1], $whereTerm[2]);
115 } 119 }
116 -
117 // Load in relations 120 // Load in relations
118 - if (static::isA('page')) { 121 + if (static::isA('page')) {
119 $search = $search->with('book', 'chapter', 'createdBy', 'updatedBy'); 122 $search = $search->with('book', 'chapter', 'createdBy', 'updatedBy');
120 } else if (static::isA('chapter')) { 123 } else if (static::isA('chapter')) {
121 $search = $search->with('book'); 124 $search = $search->with('book');
......
...@@ -208,7 +208,9 @@ class PageRepo ...@@ -208,7 +208,9 @@ class PageRepo
208 } else { 208 } else {
209 $terms = []; 209 $terms = [];
210 } 210 }
211 - $terms = array_merge($terms, explode(' ', $term)); 211 + if (!empty($term)) {
212 + $terms = array_merge($terms, explode(' ', $term));
213 + }
212 $pages = $this->page->fullTextSearchQuery(['name', 'text'], $terms, $whereTerms) 214 $pages = $this->page->fullTextSearchQuery(['name', 'text'], $terms, $whereTerms)
213 ->paginate($count)->appends($paginationAppends); 215 ->paginate($count)->appends($paginationAppends);
214 216
......