精确单词搜索中允许出现一个字母错误 [英] One Letter mistake allowed in exact word search

查看:110
本文介绍了精确单词搜索中允许出现一个字母错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在实现搜索应用程序

we are implementing a search application

我们通过以下sql查询实现了精确的单词搜索

we have implemented a exact word search by the following sql query

SELECT *
FROM jreviews_content
WHERE jr_produits REGEXP '[[:<:]]ryan[[:>:]]'

现在运作良好,我们在某些字段中还有另一个要求,即在jr_title字段中,如果用户填写了一个丢失的字母或一个字母错误或一个额外的字母,例如,如果用户键入restauran或restaunts或restaurants,则应该结果,但不超过一个字母.

which works well now we have another requirement in some of our field ie in jr_title field if the user fill one missing letter or one letter mistake or one extra letter for example if the user type restauran or restaunts or restaurants then it should give the result but not more than one letter.

推荐答案

这将允许在搜索字符串之前一个字母数字字符,并在之后一个字母数字

This will allow one alphanumerich character before the search string, and one after:

SELECT *
FROM jreviews_content
WHERE jr_produits REGEXP '[[:<:]][[:alnum:]]{0,1}ryan[[:alnum:]]{0,1}[[:>:]]'

如果您想在搜索字符串之前允许一个字母数字字符,或者在搜索字符串之后允许一个字母数字字符,则可以改用此字符:

if you want to allow one alphanumeric character before the search string OR one after, you could use this instead:

SELECT *
FROM jreviews_content
WHERE
  jr_produits REGEXP '[[:<:]][[:alnum:]]{0,1}ryan[[:>:]]'
  OR jr_produits REGEXP '[[:<:]]ryan[[:alnum:]]{0,1}[[:>:]]'

这篇关于精确单词搜索中允许出现一个字母错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆