MYSQL 强制模式匹配

发布于 2025-01-03 08:06:42 字数 598 浏览 1 评论 0原文

我无法确定在选择查询中选择结果时是否可以强制 mysql 将某些指定的字符串视为相同。

例如,我有一列包含单词“trachiotomy”,但由于语言的性质,搜索查询很可能是“trahiotomy”(注意缺少 c)。

有什么方法可以强制查询识别另一个字母的任何模式? 例如,将“ach”字母序列的单词中的任何实例也与“ah”匹配 - 反之亦然。从本质上讲,无论它是如何编写的,都会强制执行它。

另一个例子是 Archon 这个词 - 我也想将它与 Arhon 匹配。 因此,如果用户输入是 Archon,它将与数据库数据 Arhon 匹配,反之亦然。

我对 soundex 进行了一些实验,它确实匹配了一些实例,但似乎由于算法的工作方式,在所需的匹配字符串位于单词开头的情况下,它无法做到这一点。

例如,单词“Chorevo”不能与单词“Horevo”匹配,除非我可以以某种方式强制它认为“chor”等于“hor”,反之亦然。

我正在阅读 REGEXP,看看它是否可以以某种方式匹配。 (类似于 REGEXP 'arch', 'arh')

此时我正在使用全文匹配查询,但如果证明这是一个问题,可以更改它。

我不确定我是否已经说清楚了,但希望能提供任何帮助。

I am having trouble figuring out if its possible to force mysql to consider certain specified strings as identical when choosing results in a select query.

For example i have a column containing the word "trachiotomy", but due to the nature of the language it is very likely that the search query will be "trahiotomy" (notice the c missing).

Is there any way I can force the query to recognize any pattern of letters to another ?
For example to match any instance within words of the "ach" sequence of letters to "ah" also - and vice versa. In essence force it regardless of how it was written.

Another example would be the word Archon - which I would like to match with Arhon as well.
So that if a user input was Archon it would match the database data Arhon and vice versa.

I experimented with soundex a bit and it does match some instances, but it seems that due to the way the algorithm works it cant do it in cases where the desired matched string is in the beginning of the word.

For instance the word "Chorevo" cant match the word "Horevo" unless i can somehow force it to consider that "chor" is equal to "hor" and vice versa in any word.

I am reading into REGEXP to see if it can be matched thus somehow. (something like
REGEXP 'arch', 'arh')

At this point i am using a full text match query, but could change that if that proves to be a problem.

I am not sure I have made this clear but would appreciate any help possible.

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

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

发布评论

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

评论(1

夜清冷一曲。 2025-01-10 08:06:42

这称为语音匹配。 MySQL 在 soundex(str) 函数和 a SOUNDS_LIKE b 子句中实现了一个相对原始的版本(它只是 soundex(a) = soundex( b) 本质上,这种匹配是特定于语言的,并且 MySQL 实现是为英语单词设计的,因此可能不适用于您的情况,

或者您可以研究/编写自己的转换来执行您想要的操作并应用。在保存之前将其添加到数据中数据库(在单独的列或表中)。

This is known as phonetic matching. MySQL implements a relatively primitive version of this in the soundex(str) function and a SOUNDS_LIKE b clause (which is just shorthand for soundex(a) = soundex(b). By nature such matching is language-specific, and the MySQL implementation is designed for English words and thus may not work in your situation.

Alternatively you could research/write your own transformation that does what you want and apply it to the data before saving in the database (in a separate column or table).

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