开发者

PHP/MYSQL - Need a better way to go about this FULLTEXT search query

开发者 https://www.devze.com 2023-03-31 06:10 出处:网络
I am currently busy creating a search function that queries a user input string against certain row in a mysql table.

I am currently busy creating a search function that queries a user input string against certain row in a mysql table.

This is what the code looks like so far:

$space_separated = implode(" ", $keywords_array);

$dataQuery = "SELECT id, `desc`, price1, pack, measure, quantity
              FROM products
              WHERE MATCH (`desc`)
              AGAINST ('".$space_separated."' IN BOOLEAN MODE)";

It is not quite providing the desired functionality. I am aware that in boolean mode, i forfeight the use of scoring. But my problem is that this code does return partial matches on any set word.

An example of this would be if a user was searching for "chocolate" and they searched "olate", no match will be returned. How would I work around this?

@Mark

Were you suggesting this?

$dataQuery = "SELECT id, `desc`, price1, pack, measure, quantity
              FROM products
              WHERE MATCH (`desc`)
              AGAINST ('".$space_separated."' IN BOOLEAN MODE)
              OR MATCH (`desc`)
              AGAIN开发者_StackOverflow中文版ST ('".$space_separated."')";


FULLTEXT searched for whole words only. You can specify a wildcard * behind a part of the word, but not before. So choco* will match chocolate', but*olate` will not.

Also, default matching uses or for comparison. If you want to match all keywords, add a + before each keyword.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号