Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to search via 'LIKE' #148

Closed
ste101 opened this issue Mar 1, 2023 · 1 comment
Closed

Add possibility to search via 'LIKE' #148

ste101 opened this issue Mar 1, 2023 · 1 comment

Comments

@ste101
Copy link
Contributor

ste101 commented Mar 1, 2023

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
Copy link
Member

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):

  • In order to search for words shorter than 4 characters you can lower the value in ft_min_word_len(if you have access to the MySQL configuration)
  • In order to use in-word-search ("leading wildcard") you can use ke_search_premium (if the project budget allows it)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants