简体   繁体   English

尝试使用Haystack和Solr构建架构时出错

[英]Error when trying to build schema with Haystack and Solr

I have been following a tutorial from 'Django by example' that introduces Solr and Haystack and run into a problem. 我一直在关注“ Django的示例”教程,该教程介绍了Solr和Haystack并遇到了问题。 I have made the necessary changes to INSTALLED_APPS in settings.py and also added the following: 我在settings.py中对INSTALLED_APPS进行了必要的更改,还添加了以下内容:

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.solr_backends.SolrEngine',
        'URL': 'http://127.0.0.1:8938/solr/blog'
    }, 
}

then I run 然后我跑

python manage.py build_solr_schema

and I get this error 我得到这个错误

ImportError: No module named 'haystack.backends.solr_backends'

this is my search_indexes.py file 这是我的search_indexes.py文件

   from haystack import indexes
   from .models import Post
   class PostIndex(indexes.SearchIndex, indexes.Indexable):
   text = indexes.CharField(document=True, use_template=True)
   publish = indexes.DateTimeField(model_attr='publish')
   def get_model(self):
       return Post
   def index_queryset(self, using=None):
       return self.get_model().published.all()

when I run django shell Im able to import haystack just fine but when I run the following: 当我运行django shell时,我能够导入干草堆就很好了,但是当我运行以下命令时:

from haystack.query import SearchQuerySet
sqs = SearchQuerySet().all()
sqs.count()

I get the exact same error right after entering the 2nd line. 输入第二行后,我得到了完全相同的错误。

I have tried restarting Solr, still doesn't work. 我尝试重新启动Solr,但仍然无法正常工作。

I have Solr working fine locally and have created a new core within the admin and have all the files setup here and have all the required files copied over from the example folder that comes with the install: 我让Solr在本地运行良好,并在admin中创建了一个新内核,并在此处设置了所有文件,并从安装随附的示例文件夹中复制了所有必需的文件:

/usr/local/opt/solr/server/solr/blog/conf / usr / local / opt / solr / server / solr / blog / conf

what am I missing here? 我在这里想念什么? thanks 谢谢

EDIT: Id like to add that I have installed django-haystack and pysolr with a venv but both show up if I do pip freeze. 编辑:我想补充一点,我已经用venv安装了django-haystack和pysolr,但是如果我做点子冻结,它们都会显示出来。 Solr was installed via Homebrew. Solr是通过Homebrew安装的。

This problem usually occurs when first adding Haystack to your project. 第一次将Haystack添加到您的项目时,通常会出现此问题。

1.Are you using the haystack directory within your django-haystack checkout/install? 1.您是否正在django-haystack签出/安装中使用haystack目录?

2.Is the haystack directory on your PYTHONPATH? 2.您的PYTHONPATH上是否有haystack目录? Alternatively, is haystack symlinked into your project? 或者,是否将干草堆符号链接到您的项目中?

3.Start a Django shell (./manage.py shell) and try import haystack. 3.启动Django shell(./manage.py shell)并尝试导入haystack。 You may receive a different, more descriptive error message. 您可能会收到不同的,更具描述性的错误消息。

4.Double-check to ensure you have no circular imports. 4.仔细检查以确保没有循环进口。 (ie module A tries importing from module B which is trying to import from module A.) (即模块A尝试从模块B导入,而模块B试图从模块A导入。)

so I eventually found that it was just a typo error here 所以我最终发现这只是一个错字

'ENGINE': 'haystack.backends.solr_backends.SolrEngine', 'ENGINE':'haystack.backends.solr_backends.SolrEngine',

this should be 'solr_backend' not plural :| 这应该是'solr_backend'而不是复数:|

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM