微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

带有 Elasticsearch 的 django-haystack:如何使模糊单词相似性搜索起作用?

如何解决带有 Elasticsearch 的 django-haystack:如何使模糊单词相似性搜索起作用?

我在 AWS 上使用 Elasticsearch 实例 2.3 版将 \PHPmyadmin\libraries\config.default.PHPelasticsearch==2.4.1django-haystack==3.0 结合使用。

我正在尝试实现“您是说……?”使用相似性搜索

我有这个模型:

Django==2.2

以下索引:

class EquipmentBrand(SafeDeleteModel):
    name = models.CharField(
        max_length=128,null=False,blank=False,unique=True,)

我是这样搜索的:

class EquipmentBrandindex(SearchIndex,Indexable):
    text = fields.EdgeNgramField(document=True,model_attr="name")

    def index_queryset(self,using=None):
        return self.get_model().objects.all()

    def get_model(self):
        return EquipmentBrand

results = SearchQuerySet().models(EquipmentBrand).filter(content=AutoQuery(q)) 为“示例品牌”时,这些是我的实际结果:

name

我正在尝试使最后一个示例起作用,即如果单词相似,则查找该项目。

我的目标是在出现拼写错误时从数据库中推荐项目。

我缺少什么才能完成这项工作?

谢谢!

解决方法

我认为您不想使用 EdgeNgramField。 “边缘”n-gram,来自Elasticsearch Docs

emits N-grams of each word where the start of the N-gram is anchored to the beginning of the word.

它用于自动完成。它只匹配作为目标前缀的字符串。因此,当目标文档包含“example”时,搜索工作将是“e”、“ex”、“exa”、“exam”、...

"Exmple" 不是这些字符串之一。尝试使用普通的 NgramField。

另外,请考虑升级。自 ES 2.4.1 以来已经修复和改进了很多

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。