问题描述
我在 AWS 上使用 Elasticsearch 实例 2.3 版将 \PHPmyadmin\libraries\config.default.PHP
和 elasticsearch==2.4.1
与 django-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 以来已经修复和改进了很多