django haystack嗖嗖地搜索

时间:2016-07-15 06:16:37

标签: python django django-haystack whoosh

我正在尝试使用haystack-whoosh创建多个查询 我在命令提示符下面收到错误:

   C:\Users\varun\Desktop\Project\mysite>python manage.py rebuild_index
C:\Python34\lib\importlib\_bootstrap.py:321: RemovedInDjango110Warning: django.core.context_processors is deprecated in favor of django.template.context_processors.
  return f(*args, **kwds)

WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y
Removing all documents from your index because you said so.
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "C:\Python34\lib\site-packages\haystack\management\commands\rebuild_index.py", line 32, in handle
    call_command('clear_index', **options)
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 119, in call_command
    return command.execute(*args, **defaults)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "C:\Python34\lib\site-packages\haystack\management\commands\clear_index.py", line 53, in handle
    backend.clear(commit=self.commit)
  File "C:\Python34\lib\site-packages\haystack\backends\whoosh_backend.py", line 232, in clear
    self.setup()
  File "C:\Python34\lib\site-packages\haystack\backends\whoosh_backend.py", line 119, in setup
    self.content_field_name, self.schema = self.build_schema(connections[self.connection_alias].get_unified_index().all_searchfields())
  File "C:\Python34\lib\site-packages\haystack\utils\loading.py", line 342, in all_searchfields
    self.build()
  File "C:\Python34\lib\site-packages\haystack\utils\loading.py", line 237, in build
    self.collect_fields(index)
  File "C:\Python34\lib\site-packages\haystack\utils\loading.py", line 245, in collect_fields
    raise SearchFieldError("All 'SearchIndex' classes must use the same '%s' fieldname for the 'document=True' field. Offending index is '%s'." % (self.document_field, index))
haystack.exceptions.SearchFieldError: All 'SearchIndex' classes must use the same 'text' fieldname for the 'document=True' field. Offending index is '<personal.search_indexes.PostIndex object at 0x00000000056DFCA8>'.

settings.py

HAYSTACK_CONNECTIONS = {
     'autocomplete': {
        'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
        'PATH': 'C:\\Users\\varun\\Desktop\\Project\\mysite\\personal\\templates\\search\\indexes,
        'STORAGE': 'file',
        'POST_LIMIT': 128 * 1024 * 1024,
        'INCLUDE_SPELLING': True,
        'BATCH_SIZE': 100,
        'EXCLUDED_INDEXES': ['thirdpartyapp.search_indexes.BarIndex'],
    },
}

HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'

而我的search_indexes.py读取

import datetime
from haystack import indexes
from Post.models import Post

class PostIndex(indexes.SearchIndex,indexes.Indexable):
    from1 = models.CharField(document=True,use_template=True)
    type_of_truck = models.CharField(max_length=20)
    date = models.DateField()
    slug = models.SlugField(unique=True)
    weight = models.DecimalField( max_digits=5, decimal_places=2)
    Material_Name = models.CharField(max_length=20)
    To = models.CharField(max_length=20)
    Number_Of_Truck = models.CharField(max_length=20)
    Time = models.TimeField()
    Volume = models.CharField(max_length=20)
    Material_Type = models.CharField(max_length=20)

    content_auto = indexes.EdgeNgramField(model_attr='from1')

    def get_model(self):
        return Post
    def index_queryset(self,using=None):
            """used when entire index for model is updated."""
        return self.get.model().objects.all()   

models.py

class Post(models.Model):

    id = models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')
    user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1)
    from1 = models.CharField(max_length=20)
    type_of_truck = models.CharField(max_length=20)
    date = models.DateField()
    slug = models.SlugField(unique=True)
    weight = models.DecimalField( max_digits=5, decimal_places=2)
    Material_Name = models.CharField(max_length=20)
    To = models.CharField(max_length=20)
    Number_Of_Truck = models.CharField(max_length=20)
    Time = models.TimeField()
    Volume = models.CharField(max_length=20)
    Material_Type = models.CharField(max_length=20)
    #updated = models.DateTimeField(auto_now=True, auto_now_add=False)
    timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)

POST_TEXT

{{object.from1}}
{{object.To}}
{{object.Material_Type}}

虽然我刚刚在views.py中添加了“from haystack.query import SearchQuerySet” 因为早先我的搜索查询工作但我一次只能搜索单个查询,而我想创建具有多个过滤器的查询

请帮助我收到错误的原因

0 个答案:

没有答案