- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为 Joomla/Virtuemart 中的产品搜索模块处理 MySQL 搜索查询。我实际上正在尝试将现有的 MySQL 查询从使用 MATCH/AGAINST 修改为使用 RLIKE,但我修改后的查询出现错误..
这是使用 MATCH/AGAINST 的原始查询,没有错误:
$searchstring = " +search* +string* +test*";
$query ="SELECT p.virtuemart_product_id, l.product_name from #__virtuemart_products AS p, #__virtuemart_products_".VMLANG." AS l WHERE MATCH(product_name,customtitle) AGAINST ('".$searchstring."' IN BOOLEAN MODE) AND p.published = '1' AND p.virtuemart_product_id = l.virtuemart_product_id LIMIT 0,".$prods." union (select p.virtuemart_product_id, l.product_name from #__virtuemart_products AS p, #__virtuemart_products_".VMLANG." as l where MATCH(product_sku) AGAINST ('".$searchstring."' IN BOOLEAN MODE) and p.published = '1' and p.virtuemart_product_id = l.virtuemart_product_id LIMIT 0,".$prods.")";
这是我使用 RLIKE 更改的查询:
$searchstring = "search|string|test";
$query ="SELECT p.virtuemart_product_id, l.product_name from #__virtuemart_products AS p, #__virtuemart_products_".VMLANG." AS l WHERE product_name,customtitle RLIKE '".$searchstring."' AND p.published = '1' AND p.virtuemart_product_id = l.virtuemart_product_id LIMIT 0,".$prods." union (select p.virtuemart_product_id, l.product_name from #__virtuemart_products AS p, #__virtuemart_products_".VMLANG." as l where product_sku RLIKE '".$searchstring."' and p.published = '1' and p.virtuemart_product_id = l.virtuemart_product_id LIMIT 0,".$prods.")";
我不知道为什么 RLIKE 搜索查询不起作用。我希望有人能指出我在这里做错了什么..
最佳答案
您的查询中有这个奇怪的表达式:
WHERE product_name, customtitle RLIKE '".$searchstring."'
首先尝试使用 concat()
将它们组合起来:
(SELECT p.virtuemart_product_id, l.product_name
from #__virtuemart_products p join
#__virtuemart_products_".VMLANG." l
on p.virtuemart_product_id = l.virtuemart_product_id
WHERE concat(product_name, customtitle) RLIKE '".$searchstring."' AND
p.published = '1'
LIMIT 0,".$prods."
)
union
(select p.virtuemart_product_id, l.product_name
from #__virtuemart_products p join
#__virtuemart_products_".VMLANG." l
on p.virtuemart_product_id = l.virtuemart_product_id
where product_sku RLIKE '".$searchstring."' and
p.published = '1'
LIMIT 0,".$prods.
)
您还可以分别比较每一个:
WHERE (product_name RLIKE '".$searchstring."' OR
customtitle RLIKE '".$searchstring."'
) AND . . .
请注意,我还修复了 join
语法以使用显式联接。
关于php - 高级 MySQL 搜索查询 - 使用 RLIKE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22404259/
NOT RLIKE '^[aeiou].*[aeiou]$' 与 RLIKE '^[^aeiou].*[^aeiou]$' 有何不同 ? 我正在尝试在 hackerrank 上进行 mysql 练习,
SELECT * FROM A, B, C, D WHERE A = 1 AND B RLIKE '^[0-9]' 上面的命令将收集 A =1 和 B 中从数字 0 到 9 的数据。例如,它将收集 1
我有一个这样的表: +-------------+-------------------+----------------+ |id | column1 | c
我在下面的查询中使用 MYSQL RLIKE: SELECT filtering_table_data.Model, case when filtering_table_data.Model R
我有一个疑问 select X from survey where survey_date > date_add(curdate(), interval -90 day) 显示哪些 X 是当前的。但不
从制表符分隔值中导入某些表后,我正在对它们进行一系列更新。数据带有我不喜欢的格式的日期。我将它们作为字符串引入,对其进行操作,使它们与 MySQL 日期的格式相同,然后转换该列。或者有时不是,但我希望
我正在尝试使用 RLIKE 来匹配数据字符串后跟特定字符或字符串结尾 ($) 的位置。我仅使用字符串结尾字符 ($) 或仅使用预期字符,或者实际上是方括号内的任何一组预期字符来获得预期结果,但是一旦我
考虑一个像这样的表datatbl: +----------+ | strfield | +----------+ | abcde | | fgHIJ | | KLmno | +---
我的 table 是这样的: |name | ----------------- |Joseph Jackson | |Aiden Chase | |Luke Benjami
冷酷的人可以解释为什么这会返回 true: SELECT BINARY 'â' RLIKE '[™]'; SELECT BINARY 'é' RLIKE '[©]'; 解决办法是什么?是我的配置错误吗
我正在尝试运行查询来根据表达式删除重复项。我尝试使用的表达方式是这样的。 category-23023 或 category-link-2398 或 category-link-url-5869343
我正在 Col_A 和 Col_B 列上连接表 Table_A 和 Table_B。以下是一些测试样本值。 Table_A, Col_A USA1FullCover USAMainland USA2I
这个问题在这里已经有了答案: Regarding sqldf package/regexp function [duplicate] (1 个回答) 关闭 6 年前。 我有以下 mySQL 查询:
我正在使用 RLIKE 通过 mysql 查找一些电子邮件域。 这是查询: SELECT something FROM table1 WHERE SUBSTRING_INDEX(table1.emai
当我在我的网站上进行搜索时,我想在三列中搜索搜索词组。因为我不希望搜索“John”返回“Johnson”,所以我目前使用带词边界的 RLIKE。但是,我的表有超过 400,000 行,这个查询非常慢。
所以我一直在与 RLIKE 合作,在一个新的应用程序中提取一些数据,并且非常享受它。 迄今为止,我一直在使用 RLIKE 查询返回 3 种类型的结果(文件、目录和所有内容)。 查询(和示例结果)如下:
我有以下查询: SELECT p.partid, pp.partno, p.descr FROM part p, partcreditor pc, partcreditor_partno pp WHE
我有一个名为“奖学金”的表,其中有一个名为“专业”的字段,其中包含与奖学金相关的专业的逗号分隔专业名称。 假设该字段可能包含以下一项(或多项以逗号分隔):商业、农业综合企业、工商管理、国际业务。 如果
我正在尝试使用 RLIKE MySQL 指令进行简单的多词搜索,但是当您插入诸如 ")($*"之类的关键字字符时,我收到 PDO 异常和 MySQL 错误,例如插入 "( “我得到: SQL erro
rlike工作正常,但 not rlike抛出错误: scala> sqlContext.sql("select * from T where columnB rlike '^[0-9]*$'").c
我是一名优秀的程序员,十分优秀!