I have a table of documents numbered by year / series, like this:
13-201 (this would be document 201 in 2013).
I want to do a
MATCH AGAINST full text query for this table, so a user could grab a list of all docs from 2013 using a query like
MATCH (doc_id) AGAINST ('+13-*' IN BOOLEAN MODE)
However, this returns no results. But when I slightly modify in either direction to remove the dash, these queries return results (thought not exactly what I was hoping for:
MATCH (doc_id) AGAINST ('+13*' IN BOOLEAN MODE) MATCH (doc_id) AGAINST ('+13-20*' IN BOOLEAN MODE)
Is the dash an illegal / reserved character in the match syntax? Is there a way to escape it?
EDIT: I realize I could do this query in other ways (such as
LIKE, but I’d like to use the match / against syntax so I can also search other columns if required, like title etc.
You need to enclose the text that includes a minus into parenthesis.
select * from `table` WHERE MATCH (column) AGAINST ('+"13-201"' IN BOOLEAN MODE)
If you don’t, Mysql will treat a dash like an “exclude” command in boolean mode.