MySQL REGEXP usage within Boolean Match/Against

让人想犯罪 __ 提交于 2019-12-23 18:31:33

问题


I have the following MySQL query:

SELECT title, description 
FROM some_table 
WHERE MATCH (title,description) AGAINST ('+denver (REGEXP "[[:<:]]colorado[s]*[[:>:]]")' IN BOOLEAN MODE);

the "regexp" here looks for a "complete word" colorado (with or without the ending "s").

I want to actually select only those rows that have ("denver") AND ("colorado" or "colorados"). But I cannot put a "+" for the REGEXP. I tried but got 0 results, although there are rows in the table that match the requirement.

Any ideas on how I can get the "+" to work within against using a REGEXP? I am constructing this from within a PHP script where "denver" and "colorado" are values of variables I use to construct the select statement.

My PHP/MySQL script would look somewhat like this:

SELECT title, description 
FROM some_table 
WHERE MATCH (title,description) AGAINST ('+$var1 (REGEXP "[[:<:]]$var2[s]*[[:>:]]")' IN BOOLEAN MODE);

回答1:


I don't think it's possible to combine regular expressions and MATCH ... IN BOOLEAN MODE. You need to use the syntax for writing boolean expressions.

  • Boolean Full-Text Searches

Try something like this:

SELECT title, description
FROM some_table
WHERE MATCH (title,description)
      AGAINST ('+denver +(colorado colorados)' IN BOOLEAN MODE);


来源:https://stackoverflow.com/questions/10731187/mysql-regexp-usage-within-boolean-match-against

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!