布尔匹配/反对中MySQL REGEXP的使用 [英] MySQL REGEXP usage within Boolean Match/Against

查看:112
本文介绍了布尔匹配/反对中MySQL REGEXP的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下MySQL查询:

I have the following MySQL query:

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

此处的"regexp"查找完整单词"科罗拉多(带有或不带有结尾"s").

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

我实际上只选择具有("denver")AND("colorado"或"colorados")的那些行.但是我不能为REGEXP加上"+"号.我尝试过但得到0个结果,尽管表中有符合要求的行.

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.

关于使用REGEXP如何使"+"在其中工作的任何想法? 我是从PHP脚本中构建此代码的,其中"denver"和"colorado"是我用来构建select语句的变量的值.

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.

我的PHP/MySQL脚本看起来像这样:

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

推荐答案

我认为不可能将正则表达式和MATCH ...结合使用.您需要使用语法来编写布尔表达式.

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.

尝试这样的事情:

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

这篇关于布尔匹配/反对中MySQL REGEXP的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆