python – Haystack Multiple Indices – 索引相同,即使有不同的search_indexes
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – Haystack Multiple Indices – 索引相同,即使有不同的search_indexes,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1728字,纯文字阅读大概需要3分钟。
内容图文
![python – Haystack Multiple Indices – 索引相同,即使有不同的search_indexes](/upload/InfoBanner/zyjiaocheng/744/145e18521f1f481caa052b1b61352490.jpg)
我有以下搜索
class ProductIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
destination = indexes.FacetIntegerField(
model_attr='hotel__destination__id')
country = indexes.FacetIntegerField(model_attr='hotel__country__id')
hotel_class = indexes.FacetCharField(model_attr='hotel__hotel_class')
hotel_type = indexes.FacetIntegerField(model_attr='hotel__hotel_type__id')
def get_model(self):
return Product
def index_queryset(self, using=True):
return self.get_model().objects.all()
class DestinationIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
content_auto = indexes.EdgeNgramField(model_attr="foo")
并在settings.py中进行以下设置
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE':
'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
},
'autocomplete': {
'ENGINE':
'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'autcomplete',
}
}
但是当我说rebuild_indexes时,两个索引变得相同,它们根据两个索引类进行索引.但我希望使用ProductIndex索引默认索引,并使用目标索引索引自动完成.
有任何想法吗?
解决方法:
您可以使用键EXCLUDED_INDEXES排除索引:
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE':
'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
'EXCLUDED_INDEXES': ['my_destination_app.search_indexes.DestinationIndex'],
},
'autocomplete': {
'ENGINE':
'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'autcomplete',
'EXCLUDED_INDEXES': ['my_product_app.search_indexes.ProductIndex'],
}
}
内容总结
以上是互联网集市为您收集整理的python – Haystack Multiple Indices – 索引相同,即使有不同的search_indexes全部内容,希望文章能够帮你解决python – Haystack Multiple Indices – 索引相同,即使有不同的search_indexes所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。