为什么 Django-Haystack 不提供 apache solr 的结果?

问题描述

我正在使用 apache solr 和 django-haystack 和 pysolr 来实现我网站中的搜索功能。但是我的搜索无法在 haystack 查询集中使用自动完成功能

数据库MysqL

Indexes.py:

from haystack import indexes
from product.models import Product


class ProductIndex(indexes.SearchIndex,indexes.Indexable):
   text = indexes.CharField(document=True,use_template=True)
   title = indexes.CharField(model_attr='title')
   keywords = indexes.CharField(model_attr='keywords')

  title_auto = indexes.EdgeNgramField(model_attr='title')
  keywords_auto = indexes.EdgeNgramField(model_attr='keywords')
  suggestions = indexes.FacetCharField()

  def get_model(self):
     return Product

  def index_queryset(self,using=None):
     return self.get_model().objects.all()

  def prepare(self,obj):
     prepared_data = super(ProductIndex,self).prepare(obj)
     prepared_data['suggestions'] = prepared_data['text']
     return prepared_data

Views.py

def search_view(request):
   search_keyword = request.data['query']
   sqs = SearchQuerySet().autocomplete(keywords_auto=search_keyword)
   print(sqs.count())
   suggestions = [result.title for result in sqs]
   the_data = json.dumps({
      'results': suggestions
   })
   return HttpResponse(the_data,content_type='application/json')

当我测试它时,它给了我空白结果。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)