[英]Haystack Django Elasticsearch spelling
I have two problems setting up haystack/django/elasticsearch 我在设置haystack / django / elasticsearch时遇到两个问题
I never get results from index fields, eg indexes.CharField(model_attr='title') doesn't get me results. 我从不从索引字段获得结果,例如,indexs.CharField(model_attr ='title')没有得到我的结果。 Only if I put {{ object.title }} in my txt template I get results for matching titles
只有将{{object.title}}放在txt模板中,我才能获得匹配标题的结果
If my title is 'foo' I never get results for 'fo', while I do have the INCLUDE_SPELLING setting set to True in my backend setting. 如果标题是“ foo”,那么我永远都不会得到“ fo”的结果,而我的后端设置中确实将INCLUDE_SPELLING设置设置为True。
The documentation doesn't state anything special about these cases, my setup is per the haystack documentation, what am I missing? 该文档没有说明有关这些情况的任何特殊信息,我的设置是根据haystack文档进行的,我缺少什么?
My index: 我的索引:
class FooIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr='title') # never gets me results unless I add it to the template
def get_model(self):
return Foo
My settings: 我的设置:
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
'INCLUDE_SPELLING': True,
},
}
1) If you have use_template=True
only index what you put in the template
file so put all the fields you want indexed in there. 1)如果
use_template=True
仅对您在template
文件中放置的内容进行索引,则将要索引的所有字段放在其中。 2) Did you refresh the index after adding INCLUDE_SPELLING
? 2)添加
INCLUDE_SPELLING
后是否刷新了索引?
Make sure you enabled spellcheck component. 确保启用了拼写检查组件。
The first thing to do is create a special field on your SearchIndex class that mirrors the text field, but uses FacetCharField. 要做的第一件事是在SearchIndex类上创建一个特殊的字段,该字段反映文本字段,但使用FacetCharField。 This disables the post-processing that Solr does, which can mess up your suggestions.
这将禁用Solr进行的后处理,这可能会弄乱您的建议。 Something like the following is suggested:
建议类似以下内容:
class MySearchIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
# ... normal fields then...
suggestions = indexes.FacetCharField()
def prepare(self, obj):
prepared_data = super(MySearchIndex, self).prepare(obj)
prepared_data['suggestions'] = prepared_data['text']
return prepared_data
Once this is done, spelling_suggestions method should return the appropriate values. 完成此操作后,spelling_suggestions方法应返回适当的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.