计算 MySQL 中某个单词在一行中的出现次数
我正在为我的网站制作一个搜索功能,该功能可以从数据库中查找相关结果.我正在寻找一种计算单词出现次数的方法,但我需要确保单词两侧都有单词边界(所以当我想要rip"时,我不会以triple"结尾).
I'm making a search function for my website, which finds relevant results from a database. I'm looking for a way to count occurrences of a word, but I need to ensure that there are word boundaries on both sides of the word ( so I don't end up with "triple" when I want "rip").
有人有什么想法吗?
人们误解了我的问题:
如何计算在一行中出现的次数?
How can I count the number of such occurences within a single row?
推荐答案
这不是关系型数据库擅长的事情,除非你可以使用全文索引,而且你已经说过你不能,因为你正在使用 InnoDB.我建议选择您的相关行并在您的应用程序代码中进行字数统计.
This is not the sort of thing that relational databases are very good at, unless you can use fulltext indexing, and you have already stated that you cannot, since you're using InnoDB. I'd suggest selecting your relevant rows and doing the word count in your application code.
相关文章