在Postgres全文搜索中搜索最接近的正确单词
我的应用程序中有一个搜索功能,用。 我想以“你的意思...?”的方式添加拼写错误的更正。
到目前为止,我已经看到您可以与。这与我想要的完全不匹配,是我想要校正可能的缺陷输入的建议。仅仅获得相似之处,假设我已经知道正确拼写的单词的含义。
Postgres可以这样做吗?一个例子是将“ Borritoh”纠正为“墨西哥卷饼”。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,您只需要一个公认单词的字典。然后,您以相似性或距离为限制1的词典订购识别单词的字典。
如果您构建要点风味的Trigram索引,它将直接支持订购:
但是,如果识别的单词都不相似,这将非常慢。最好使用
%
将其放置在其上不提出任何建议的地面(这可能会比GIST索引做得更好,您应该两种方法都可以尝试这两种方式) 。No, you just need a dictionary of recognized words. You then order your dictionary of recognized words by similarity or distance with a LIMIT 1.
If you build the trigram index of the GiST flavor, it will support ordering directly:
However, this will be pretty slow if none of the recognized words are similar. It might be better to use
%
to put a floor below which it just doesn't make any recommendation (which which will probably be better done with a GIN than GiST index, you should try it both ways).