几天来,我一直在绞尽脑汁试图找到解决方案。我正在尝试制作一个可以处理各种搜索词的“智能”查询。查询运行良好,直到涉及特殊字符,并且我在逗号和破折号等某些字符上使用 REPLACE 方法取得了一些成功。引号和 & 号等其他字符将导致空查询。
这里有几个例子:
我正在搜索的原始名称是“French Is Fun, Book 1 - 1 Year Option”,通过下面的查询,我得到了带有以下搜索词的结果:
1. "French Is Fun"
2. "French Is Fun, book"
3. "French Is Fun, book"
4. "French Is Fun, Book 1"
SELECT * FROM `products` WHERE ( (LOWER(name) LIKE '%french is fun book%' OR
LOWER(replace(name, ' ','')) LIKE '%french is fun book%' OR
LOWER(replace(name, ' ','')) LIKE '%french is fun book%' OR
LOWER(replace(name, '-','')) LIKE '%french is fun book%')
但是,当原始标题中有一个与号,如下所示:“全球历史和地理:文明的发展 - 1 年选项” - 当我尝试这些不同的搜索词时,我得到一个空查询:
1. "Global History & Geography"
2. "Global History Geography"
我试过这个无济于事
SELECT * FROM `products` WHERE
(LOWER(name) LIKE '%global history geograph%' OR
LOWER(replace(name, ' ','')) LIKE '%global history geography%' OR
LOWER(replace(name, ' ','')) LIKE '%global history geography%' OR
LOWER(replace(name, ',','')) LIKE '%global history geography%' OR
LOWER(replace(name, '&','')) LIKE '%global history geography%' OR
LOWER(replace(name, '-','')) LIKE '%global history geography%');
我还尝试在&符号中添加转义字符,但没有帮助:
SELECT * FROM `products` WHERE
(LOWER(name) LIKE '%global history geography%' OR
LOWER(replace(name, ' ','')) LIKE '%global history geography%' OR
LOWER(replace(name, ' ','')) LIKE '%global history geography%' OR
LOWER(replace(name, ',','')) LIKE '%global history geography%' OR
LOWER(replace(name, '\&','')) LIKE '%global history geography%' OR
LOWER(replace(name, '-','')) LIKE '%global history geography%');
名称中的逗号也会返回空结果。作为演示,原名是这样的:
“Amsco 的 AP 微积分 AB/BC 为大学先修考试做准备 - 1 年选项”
此尝试始终返回空查询:
SELECT * FROM `products` WHERE
( (LOWER(name) LIKE '%amscos ap calculus%' OR
LOWER(replace(name, ' ','')) LIKE '%amscos ap calculus%' OR
LOWER(replace(name, '\'','')) LIKE '%amscos ap calculus%' OR
LOWER(replace(name, ',','')) LIKE '%amscos ap calculus%' OR
LOWER(replace(name, '-','')) LIKE '%amscos ap calculus%')
) AND ( (`products`.`type` = 'Rental' ) );
有任何想法吗?