Search code examples
mysqlmatch-against

Match against "foo.bar" (with a full-stop/period)


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?


Solution

  • 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);