tpwd / ke_search

Search Extension for TYPO3 Content Management System, including faceting search functions.
https://extensions.typo3.org/extension/ke_search/
GNU General Public License v3.0
8 stars 31 forks source link

Add possibility to search via 'LIKE' #148

Closed ste101 closed 1 year ago

ste101 commented 1 year ago

With match against it is not possible to search with leading wildcard. Also ft_min_word_len is mostly set to 4 which isn't acceptable for everything.

I made a quick and dirty hack and it is working well:

         // add boolean where clause for searchwords
         if ($this->pObj->wordsAgainst != '') {
-            $where .= ' AND MATCH (' . $this->getMatchColumns() . ') AGAINST (';
-            $where .= $wordsAgainstQuoted . ' IN BOOLEAN MODE) ';
+            //$where .= ' AND MATCH (' . $this->getMatchColumns() . ') AGAINST (';
+            //$where .= $wordsAgainstQuoted . ' IN BOOLEAN MODE) ';
+            foreach($this->pObj->swords AS $sword) {
+                $where .= " AND content LIKE " . $databaseConnection->quote("%" . $sword . "%", \PDO::PARAM_STR);
+            }
         }
christianbltr commented 1 year ago

Using LIKE instead of MATCH AGAINST has some major drawbacks, e.g. you will lose relevancy ranking, the possibility to use modifiers ("+", "-") and it is less performant in bigger indexes.

Also for the disadvantages of using MATCH AGAINST which you mentioned there are already solutions (which are not always possbile to use, I admit):

There might be some use cases for switching to LIKE but I doubt that it would get much use when it would be implemented as a general feature. So for now I'm closing this.