Django Haystack文档说:
**Warning**
When you choose a document=True field, it should be consistently named across all of your SearchIndex classes to avoid confusing the backend. The convention is to name this field text.
There is nothing special about the text field name used in all of the examples. It could be anything; you could call it pink_polka_dot and it won’t matter. It’s simply a convention to call it text.
但我不明白这意味着什么。这是他们的示例模型:
import datetime from haystack import index from myapp.models import 注意
class NoteIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
author = indexes.CharField(model_attr='user')
pub_date = indexes.DateTimeField(model_attr='pub_date')
def get_model(self):
return Note
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now())
我引用的文本是指我的模型主字段并说我应该将其称为“文本”还是 search_indexes.py 中定义的类?
如果是 search_indexes.py 中的类,在上面的示例中它附加到的字段名称在哪里?它没有model_attr!
text = indexes.CharField(document=True, use_template=True)
如果对于我的实际应用程序模型,我应该如何重构一个包含许多应用程序的项目,以将它们的主要文本字段称为“文本”!
请指教。谢谢。