问题
I can search for rows with both foo
and bar
in the col1
/col2
using match against:
SELECT col1, col2
FROM some_table
WHERE MATCH (col1,col2)
AGAINST ('+foo +bar' IN BOOLEAN MODE);
But suppose I want to search for the exact phrase "foo.bar" (with a full-stop in the middle). On the docs page for Boolean Full-Text Searches, it doesn't mention full-stop being an operator, so I thought I could use:
AGAINST ('+foo.bar' IN BOOLEAN MODE);
However, this returns the same results as:
AGAINST ('+foo.couldBeAnything' IN BOOLEAN MODE);
AGAINST ('+foo' IN BOOLEAN MODE);
AGAINST ('+foo.*' IN BOOLEAN MODE); #Note you would expect this to look for instances of foo. followed by something, rather than just the same as foo
.
Why isn't this working as I expect? and how can I match against for foo.bar
?
回答1:
I don't have a fulltext table readily available to test this out, but I believe this should work:
SELECT col1, col2
FROM some_table
WHERE MATCH (col1,col2)
AGAINST ('+\"foo.bar\"' IN BOOLEAN MODE);
回答2:
To make this work, you need to suround your literal by a double quote: "bar.foo", because the point is probably equivalent to or operator.
来源:https://stackoverflow.com/questions/12076780/match-against-foo-bar-with-a-full-stop-period