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

北战南征 提交于 2019-12-12 10:48:50

问题


I am trying to implement Haystack with whoosh.

I keep getting this error although everything seems to be configured fine. I get the error:

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

...when I try to do ./manage.py rebuild_index

configuration:

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

There are successfully created whoosh/mysite_index directories in the root folder of my project.

*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)

Thanks


回答1:


the problem is in your HAYSTACK_SITECONF. It must be the path to your search_sites file. Fix this and it should work.




回答2:


Make sure your site_indexes.py is in an app that you have registered in the INSTALLED_APPS in settings.py



来源:https://stackoverflow.com/questions/15270347/haystack-exceptions-searchbackenderror-no-fields-were-found-in-any-search-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!