开发者

Mysql fulltext boolean ignore phrase

开发者 https://www.devze.com 2023-03-12 01:34 出处:网络
I\'m trying to come up with a mysql boolean search that matches \"monkey\" but ignores / doesn\'t take into account an matches of \"monkey business\".

I'm trying to come up with a mysql boolean search that matches "monkey" but ignores / doesn't take into account an matches of "monkey business".

Something like the following is the general idea but it negates the value. I need it to not match rows with "monkey business" unless they also have "monkey" without "business" after it elsewhere in the text.

SELECT * FROM table
MATCH (title) against ('+monkey ~"monkey business"' IN BOOLEAN MODE);

Is it possible? Thanks in advance for any help you can give! I realise this could be done with better search engines开发者_StackOverflow, at the moment fulltext is all I can use.


I tested this and it works:

SELECT * FROM table
WHERE MATCH (title) against ('+monkey' IN BOOLEAN MODE)
AND NOT MATCH (title) against ('+"monkey business"' IN BOOLEAN MODE);

p.s I also tried the boolean negation operator:

AND MATCH (title) against ('-"monkey business"' IN BOOLEAN MODE)

but it didn't work.

0

精彩评论

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

关注公众号