MySQL 搜索单词中带有 $ 的精确单词
我一直在试图找到准确的词语,但我的研究对我没有帮助。
我找到的解决方案:
$query .= "WHERE text REGEXP '[[:<:]]($word)[[:>:]]'";
// OR
$query .= "WHERE MATCH(text) AGAINST('$word') ";
但都没有返回我的比赛。
我正在我的数据库中搜索股票代码(例如 $aapl
)。如果您搜索 $ba
,使用 LIKE '%$word%'
将返回 $bac
。
I've been trying to find exact words and my research isn't helping me.
Solutions I've found:
$query .= "WHERE text REGEXP '[[:<:]]($word)[[:>:]]'";
// OR
$query .= "WHERE MATCH(text) AGAINST('$word') ";
but neither are returning my matches.
I'm searching for stock symbols in my db (eg $aapl
). And using LIKE '%$word%'
will return $bac
if you search for $ba
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要使用 MySql 全文搜索 函数来完成您上面描述的内容。
享受!
You will want to use MySql Full Text Search functions to accomplish what you describe above.
Enjoy!
MATCH AGAINST 的工作方式并不完全符合您的想象。
Casey Fulton 可以将其总结为“...如果结果数量小于总表大小的 50%,全文搜索仅[返回]任何内容...”
因此,我正在搜索所有 LIKE 和然后通过正则表达式过滤掉确切的单词。我这样做是为了减少 REGEX 的进程负载。
以下是我的解决方案:
祝你好运。
)) AS regexrows "; $query = "SELECT * FROM $regexrows ";我在 $q 周围放置空格,因为我想匹配句子结构的单词(前面和后面都有一个空格)。
另外,我正在搜索以 $ 开头的“单词”。这是一个问题,这就是我为解决该问题所做的事情:
祝你好运。
MATCH AGAINST doesn't work exactly how you'd think it would.
This can be summarized by Casey Fulton as "...FULLTEXT searches only [return] anything if the number of results is less than 50% of the total table size..."
So instead, I'm searching for all the LIKEs and then filtering out exact words by a REGEX. I'm doing this to cut down on the process load for REGEX.
The following is my solution:
Best of luck.
)) AS regexrows "; $query = "SELECT * FROM $regexrows ";I put spaces around the $q because I want to match a sentence-structured word (which is preceeded and followed by a space).
Also, I'm searching for "words" that start with $. This was an issue and here's what I did to solve that problem:
Best of luck.