MySQL 布尔匹配短语无效
MySQL boolean match phrase does not work
我使用全文布尔匹配https://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html
有效
匹配 bear
,跳过其余部分:
+bear
有效
匹配 bear
或 teddy
,跳过其余部分:
+(bear teddy)
不起作用
我的预期行为是 bear
或 teddy
或 me and my
,跳过其余部分。它不会那样工作,因为我没有得到结果。
+(bear teddy '"me and my"')
怎样才能得到预期的结果?
我认为您误解了文档。 me and my
只需要用双引号括起来,而不是像你所做的那样用单引号和双引号括起来。所以你的查询应该看起来像
SELECT * FROM table WHERE MATCH(column) AGAINST('+(bear teddy "me and my")' IN BOOLEAN MODE)
考虑这个例子:
CREATE TABLE table1 (txt VARCHAR(512));
INSERT INTO table1 VALUES('here is a bear'), ('this is a teddy'),
('nothing to see here'), ('only me'), ('me and someone else'), ('oh my'),
('me and my children'), ('a teddy bear'), ('me and my teddy bear'),
('love me'), ('what about me and my life');
ALTER TABLE table1 ADD FULLTEXT idx(txt);
SELECT * FROM table1 WHERE MATCH(txt) AGAINST('+(bear teddy "me and my")' IN BOOLEAN MODE)
输出:
txt
here is a bear
this is a teddy
me and my children
a teddy bear
me and my bear
what about me and my life
如果我将查询更改为
SELECT * FROM table1 WHERE MATCH(txt) AGAINST('+(bear teddy "me and all my")' IN BOOLEAN MODE)
我丢失了 "me and my children" 值,但保留了 "me and my teddy bear",因为它包含 "teddy" 和 "bear"。
txt
a teddy bear
me and my teddy bear
here is a bear
this is a teddy
在 none 个案例中,选择了仅包含单词 "me"、"and" 或 "my" 之一的值。
我使用全文布尔匹配https://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html
有效
匹配 bear
,跳过其余部分:
+bear
有效
匹配 bear
或 teddy
,跳过其余部分:
+(bear teddy)
不起作用
我的预期行为是 bear
或 teddy
或 me and my
,跳过其余部分。它不会那样工作,因为我没有得到结果。
+(bear teddy '"me and my"')
怎样才能得到预期的结果?
我认为您误解了文档。 me and my
只需要用双引号括起来,而不是像你所做的那样用单引号和双引号括起来。所以你的查询应该看起来像
SELECT * FROM table WHERE MATCH(column) AGAINST('+(bear teddy "me and my")' IN BOOLEAN MODE)
考虑这个例子:
CREATE TABLE table1 (txt VARCHAR(512));
INSERT INTO table1 VALUES('here is a bear'), ('this is a teddy'),
('nothing to see here'), ('only me'), ('me and someone else'), ('oh my'),
('me and my children'), ('a teddy bear'), ('me and my teddy bear'),
('love me'), ('what about me and my life');
ALTER TABLE table1 ADD FULLTEXT idx(txt);
SELECT * FROM table1 WHERE MATCH(txt) AGAINST('+(bear teddy "me and my")' IN BOOLEAN MODE)
输出:
txt
here is a bear
this is a teddy
me and my children
a teddy bear
me and my bear
what about me and my life
如果我将查询更改为
SELECT * FROM table1 WHERE MATCH(txt) AGAINST('+(bear teddy "me and all my")' IN BOOLEAN MODE)
我丢失了 "me and my children" 值,但保留了 "me and my teddy bear",因为它包含 "teddy" 和 "bear"。
txt
a teddy bear
me and my teddy bear
here is a bear
this is a teddy
在 none 个案例中,选择了仅包含单词 "me"、"and" 或 "my" 之一的值。