我已经将我的模块索引到 flex 搜索,但是它引发了错误:
All 'SearchIndex' classes must use the same 'text' fieldname for the 'document=True' field.
Offending index is '<advertisement.search_indexes.ProductIndex object at 0x7f42f57e4db8>'.
我在下面给出了我的代码:
模版
class Product(models.Model):
user = models.ForeignKey(User)
photo = models.ImageField(upload_to='static/img',blank=True)
category = models.ForeignKey(Category,null=False)
subcategory = models.ForeignKey(SubCategory,null=False)
title = models.CharField(max_length=200)
condition = models.CharField(max_length=25,choices=condition,default='used')
description = models.TextField(max_length=20, verbose_name="Describe what makes your ad unique:*")
price = models.FloatField(default='$',help_text=".00")
addtype = models.CharField(max_length=25,choices=STATE_CHOICES,default="seller")
you_are = models.CharField(max_length=20,choices=you,default="individual")
you_name = models.CharField(max_length=20)
you_email = models.CharField(max_length=30)
you_phone = models.CharField(max_length=12)
timestamp = models.DateTimeField(auto_now=True)
city=models.ForeignKey(City)
locality=models.ForeignKey(Locality)
cars=models.OneToOneField(Cars,null=True,blank=True)
mobile = models.OneToOneField(Mobiles,null=True,blank=True)
tablets = models.OneToOneField(Tablets,null=True,blank=True)
access = models.OneToOneField(Access,null=True,blank=True)
def __unicode__(self):
return self.title
表格
class ProductSearchForm(SearchForm):
def no_query_found(self):
return self.searchqueryset.all()
search_index.py
lass ProductIndex(indexes.SearchIndex, indexes.Indexable):
title = indexes.CharField(document=True,model_attr='title')
timestamp = indexes.DateTimeField(model_attr='timestamp')
def get_model(self):
return Product
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.filter(timestamp__lte=timezone.now())
note_text.txt
{{ object.title }}
{{ object.price }}
{{ object.description }}
最佳答案
在search_index.py中替换该行
标题= indexs.CharField(document = True,model_attr ='title')
与
文字= indexs.CharField(document = True,model_attr ='title')
这应该使它工作
关于python - Python项目中的Elasticsearch,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28212007/