Search code examples
mysqlmatch-against

Full-stop/period operator in match against


I can search for all rows with foo in the col1/col2 using match against:

SELECT col1, col2
FROM some_table
WHERE MATCH (col1,col2)
      AGAINST ('foo' IN BOOLEAN MODE);

But suppose I want to search for all rows with foo. (i.e. foo with a full-stop as the next character). On the docs page for Boolean Full-Text Searches, it doesn't mention full-stop being an operator, so I thought I could use either of these:

AGAINST ('foo.' IN BOOLEAN MODE);
AGAINST ('"foo."' IN BOOLEAN MODE);
AGAINST ('"foo\."' 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);

.

What is the . operator in this context? and how can I match-against foo.?

Note: I first asked this question about match-against foo.bar which led me to ask this follow up.


Solution

  • Full-stop, or indeed any punctuation, is treated like a space in a FULL-TEXT SEARCH, unfortunately this means there is no way to search for punctuation. The reasoning behind this is that text search is for finding "words" (which don't include punctuation).

    To do such a search against punctuation, you could match against regular expressions, e.g. by using preg_match.