- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
您如何制作一个抽象的 SearchIndex 类,类似于 Django 让您制作抽象基础模型的方式?
我有几个 SearchIndexes,我想提供相同的基本字段(object_id、时间戳、重要性等)。目前,我正在复制所有这些代码,所以我正在尝试创建一个“BaseIndex”,并让所有真正的索引类都继承自它。
我试过了:
class BaseIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
object_id = indexes.IntegerField()
timestamp = indexes.DateTimeField()
class Meta:
abstract = True
class PersonIndex(BaseIndex):
...other fields...
但这给了我错误:
NotImplementedError: You must provide a 'model' method for the '<myapp.search_indexes.BaseIndex object at 0x18a7328>' index.
然后我尝试了:
class BaseIndex(object):
text = indexes.CharField(document=True, use_template=True)
object_id = indexes.IntegerField()
timestamp = indexes.DateTimeField()
class PersonIndex(BaseIndex, indexes.SearchIndex, indexes.Indexable):
first_name = indexes.CharField()
middle_name = indexes.CharField()
last_name = indexes.CharField()
但是这些给我错误:
SearchFieldError: The index 'PersonIndex' must have one (and only one) SearchField with document=True.
如何从自定义 SearchIndex 子类继承?
最佳答案
只是不要将 indexes.Indexable
作为您不想编制索引的任何内容的父元素。
所以修改你的第一个例子。
class BaseIndex(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
object_id = indexes.IntegerField()
timestamp = indexes.DateTimeField()
class Meta:
abstract = True
class PersonIndex(BaseIndex, indexes.Indexable):
...other fields...
关于python - 如何制作一个抽象的 Haystack SearchIndex 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16900067/
我有一个排序数组,如下所示: var array = [ 10, 10, 10, 8, 7, 6, 6, 6, 6 ]; 我想找到11的插入索引。鉴于此数组按降序排序,插入索引应为0。 有没有一种方法
我在Amazon Product API中使用SearchIndex =“ All”,但未得到任何结果。当指定类别时,我会得到结果。 有谁知道此搜索索引是否有任何限制? 谢谢 最佳答案 由于没有可查看
您如何制作一个抽象的 SearchIndex 类,类似于 Django 让您制作抽象基础模型的方式? 我有几个 SearchIndexes,我想提供相同的基本字段(object_id、时间戳、重要性等
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 8 年前。 Improve t
我目前正在使用亚马逊广告 API,我了解如何指定 SearchIndex 以按索引/部门定制结果。 (搜索索引 = 全部、书籍、玩具、厨房等) 在搜索结果中,他们列出了符合 api docs 的产品组
我收到以下错误,我完全不知道从哪里开始。我读过它可能是线程或其他东西,但在我的代码中只有一次 DocumentIndex 以 document 作为模型,没有继承它和声明是: class Docume
我有一个 iOS 应用程序,我必须在其中实现两个用户之间的简单聊天。我在应用程序注册期间将用户注册到 Firebase。一切都很好。但是,当我必须启动聊天线程时,我正在使用搜索索引搜索用户,但出现以下
我有一个 SearchIndex 子类,我已经为 itd 定义了一个 prepare 方法。 在上述准备方法中,我将两个条目添加到 prepared_data 字典中,这些条目具有列表作为值。稍后,当
我正在尝试使用 haystack-whoosh 创建多个查询,我的最后一个问题是通过放置双反斜杠解决的,但现在出现了一个新错误。我在命令提示符中收到以下错误: C:\Users\varun\De
我是一名优秀的程序员,十分优秀!