@@ -75,6 +75,11 @@ class SearchController{
7575 */
7676 private string $ queryEnd = '' ;
7777
78+ /**
79+ * @var array Search words.
80+ */
81+ private array $ wordList = [];
82+
7883 /**
7984 * Initializes SearchController constructor
8085 *
@@ -87,6 +92,16 @@ public function __construct(string $algorithm = self::OR)
8792 $ this ->queryStart = self ::LIKE ;
8893 $ this ->queryEnd = self ::OR ;
8994 }
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+ }
90105
91106 /**
92107 * Set database search table columns.
@@ -155,6 +170,12 @@ public function setQuery(string $query): self
155170 {
156171 $ this ->searchQuery = strtolower (htmlspecialchars ($ query , ENT_QUOTES , "UTF-8 " ));
157172
173+ if (strpos ($ this ->searchQuery , " " ) !== false ){
174+ $ this ->wordList = explode (" " , $ this ->searchQuery );
175+ }else {
176+ $ this ->wordList = [$ this ->searchQuery ];
177+ }
178+
158179 return $ this ;
159180 }
160181
@@ -193,10 +214,9 @@ public function setEnd(string $end): self
193214 */
194215 public function split (): void
195216 {
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 ;
198219 }
199- //$this->searchQuery = [$this->searchQuery];
200220 }
201221
202222 /**
0 commit comments