@@ -75,6 +75,11 @@ class SearchController{
75
75
*/
76
76
private string $ queryEnd = '' ;
77
77
78
+ /**
79
+ * @var array Search words.
80
+ */
81
+ private array $ wordList = [];
82
+
78
83
/**
79
84
* Initializes SearchController constructor
80
85
*
@@ -87,6 +92,16 @@ public function __construct(string $algorithm = self::OR)
87
92
$ this ->queryStart = self ::LIKE ;
88
93
$ this ->queryEnd = self ::OR ;
89
94
}
95
+
96
+ /**
97
+ * Get the search word list
98
+ *
99
+ * @return array Return word list.
100
+ */
101
+ public function getWordList (): array
102
+ {
103
+ return (array ) $ this ->wordList ;
104
+ }
90
105
91
106
/**
92
107
* Set database search table columns.
@@ -155,6 +170,12 @@ public function setQuery(string $query): self
155
170
{
156
171
$ this ->searchQuery = strtolower (htmlspecialchars ($ query , ENT_QUOTES , "UTF-8 " ));
157
172
173
+ if (strpos ($ this ->searchQuery , " " ) !== false ){
174
+ $ this ->wordList = explode (" " , $ this ->searchQuery );
175
+ }else {
176
+ $ this ->wordList = [$ this ->searchQuery ];
177
+ }
178
+
158
179
return $ this ;
159
180
}
160
181
@@ -193,10 +214,9 @@ public function setEnd(string $end): self
193
214
*/
194
215
public function split (): void
195
216
{
196
- if (is_string ($ this ->searchQuery ) && strpos ( $ this -> searchQuery , " " ) !== false ) {
197
- $ this ->searchQuery = explode ( " " , $ this ->searchQuery ) ;
217
+ if (count ($ this ->wordList ) > 1 ) {
218
+ $ this ->searchQuery = $ this ->wordList ;
198
219
}
199
- //$this->searchQuery = [$this->searchQuery];
200
220
}
201
221
202
222
/**
0 commit comments