haystack.exceptions.SearchBackendError:在任何search_index中都找不到任何字段。请在尝试搜索之前更正此问题

时间:2013-03-07 11:45:18

标签: django search django-haystack

我正试图用嗖嗖声来实现Haystack。

我一直收到这个错误,虽然一切似乎都配置得很好。我收到错误:

haystack.exceptions.SearchBackendError: No fields were found in any search_indexes. Please correct this before attempting to search.

...当我尝试 ./ manage.py rebuild_index

配置:

HAYSTACK_SITECONF = 'myproject'
HAYSTACK_SEARCH_ENGINE = 'whoosh'
HAYSTACK_WHOOSH_PATH = cwd + '/whoosh/mysite_index'

在项目的根文件夹中成功创建了 whoosh / mysite_index 目录。

* search_sites.py *

import haystack
haystack.autodiscover()

* search_indexes.py *

from haystack.indexes import *
from haystack import site
from myproject.models import *

class ResearchersIndex(SearchIndex):
    text = CharField(document=True, use_template=True)
    name = CharFIeld(model_attr='name')

class SubjectIndex(SearchIndex):
    short_name = CharField(model_attr='short_name')
    name = CharField(model_attr='name')
    text = CharField(document=True, use_template=True)

class ResearchIndex(SearchIndex):
    text = CharField(document=True, use_template=True)
    abstract = TextField(model_attr='abstract')
    methodology = TextField(model_attr='methodology')
    year = IntegerField(model_attr='year')
    name = CharField(model_attr='name')


class Graph(SearchIndex):
    text = CharField(document=True, use_template=True)
    explanation = TextField(model_attr='explanation')
    type = CharField(model_attr='type')
    name = CharField(model_attr='name')

site.register(Researchers, ResearchersIndex)
site.register(Subject, SubjectIndex)
site.register(Research, ResearchIndex)
site.register(Graph, GraphIndex)

由于

2 个答案:

答案 0 :(得分:1)

问题出在HAYSTACK_SITECONF。它必须是search_sites文件的路径。解决这个问题,它应该可行。

答案 1 :(得分:0)

确保您的site_indexes.py位于您在settings.py

INSTALLED_APPS中注册的应用中