用mysql搜索关键字

发布于 2024-11-09 09:04:27 字数 763 浏览 0 评论 0原文

我应该使用什么来使用 mysql 搜索关键字?

我有一个单词,在查询中

wordless
something word something
someword some
else
other
wordother
thingword

我想输出其中包含该单词的所有内容,但输出就像第一个输出的行一样,即以单词作为第一个字母的行,例如

无字 - 将是首先,因为单词是单词“wordless”的第一个字符 以及要输出到第一个输出行的单词other,然后在它们之后输出某些单词某些单词等,每个包含名称单词的单词,但再次首先输出第一个字符处具有该单词的行。

编辑:

SELECT *,MATCH(add_songName) AGAINST('d' IN BOOLEAN MODE) asscoreFROM 歌曲 WHERE MATCH(add_songName) AGAINST('d') ORDER BYscore DESC ,在这里我正在搜索 d 但它给了我一个错误 -

Can't find FULLTEXT index matching the column list   SELECT *,MATCH(add_songName) AGAINST('d' IN BOOLEAN MODE) as `score` FROM songs WHERE MATCH(add_songName) AGAINST('d') ORDER BY `score` DESC

What should I use, to search for a keyword with mysql ?

I have a word and in the query I have

wordless
something word something
someword some
else
other
wordother
thingword

I want to output everything that has the word inside it, but the output to be like first outputed rows to be that rows with word as first letter on them, for example

wordless - will be the first because word are first characters of the word wordless
and the wordother to be outputed to to the first outputed rows, then after them to output something word something and etc, every word that contains the name word, but again to output first that rows that have the word at the first characters.

EDIT:

SELECT *,MATCH(add_songName) AGAINST('d' IN BOOLEAN MODE) asscoreFROM songs WHERE MATCH(add_songName) AGAINST('d') ORDER BYscoreDESC , Here i'm searching for d but it gives me an error -

Can't find FULLTEXT index matching the column list   SELECT *,MATCH(add_songName) AGAINST('d' IN BOOLEAN MODE) as `score` FROM songs WHERE MATCH(add_songName) AGAINST('d') ORDER BY `score` DESC

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤感在游骋 2024-11-16 09:04:27

尝试在MySQL中使用Levenshtein算法。

编辑匹配是衡量两个序列之间差异程度的度量,这里是字符串。默认情况下MySQL没有这个功能,但是你可以自己编写并添加一个。

请看一下这里的代码,并将该代码添加为 MySQL 中的系统函数,请参阅下面的示例,了解如何获取两个字符串的相似度。

请参阅:https://github.com/rakesh-sankar/工具/blob/master/MySQL/Levenshtein.txt

示例:
SELECT column1, LEVENSHTEIN(column1, 'matchme') AS Perfectmatch FROM sometable ORDER BY Perfectmatch DESC

Try to use Levenshtein algorithm in MySQL.

Levenshtein matching is a metric for measuring the amount of difference between two sequence, here it is strings. By default MySQL does not have this function, but you can write and add one.

Please take a look at the code here and add that code as a system function in MySQL, please see the example below on how to get the similarity of two strings.

Please see: https://github.com/rakesh-sankar/Tools/blob/master/MySQL/Levenshtein.txt

Example:
SELECT column1, LEVENSHTEIN(column1, 'matchme') AS perfectmatch FROM sometable ORDER BY perfectmatch DESC

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文