python - 使用 zc.buildout 从 Django 添加到 solr 索引时出现问题

标签 python django solr buildout django-haystack

我正在尝试让 Apache Solr 在我的 zc.buildout 环境中运行。

我定义了一个简单的模型:

class NewsItem(models.Model):
    title = models.CharField(blank=False, max_length=255, help_text=u"Title of this news item")
    slug = models.SlugField(blank=False, help_text=u"Slug will be automatically generated from the title")
    article = models.TextField(help_text=u"The body text of this news item")
    created_on = models.DateTimeField(auto_now_add = True)
    updated_on = models.DateTimeField(auto_now = True)
    published = models.BooleanField(default=True)

    def __unicode__(self):
        return self.title

搜索索引.py:

import datetime
from haystack.indexes import *
from haystack import site
from appname.models import *


class NewsItemIndex(RealTimeSearchIndex):
    text = CharField(document=True, use_template=True)

    def get_queryset(self):
        """Used when the entire index for model is updated."""
        return NewsItem.objects.all()


site.register(NewsItem, NewsItemIndex)

还有一个 search_sites.py定义:

import haystack
haystack.autodiscover()

设置文件包含:

HAYSTACK_SITECONF = 'appname.search_sites'
HAYSTACK_SEARCH_ENGINE = 'solr'
HAYSTACK_SOLR_URL = 'http://127.0.0.1:8983/solr'
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 30
HAYSTACK_INCLUDE_SPELLING = True

“haystack”列在 INSTALLED_APPS 中,pysolr 列在 setup.py 的“install_requires”中(由 bu​​ildout 提供)

我的 buildout.cfg 包含 solr-files , solr , solr-confsupervisor .

我添加了 ${buildout:directory}/solr-conf[mkdir]路径。

buildout.cfg 中的 supervisor 和 solr 部分如下所示:

[supervisor]
recipe = collective.recipe.supervisor
port = localhost:9001
user = admin
password = admin
plugins =
   superlance

# solr security settings: see
# http://docs.codehaus.org/display/JETTY/Connectors+slow+to+startup
programs =
   10 solr     (startsecs=10) java [-Djava.security.egd=file:/dev/urandom -jar start.jar] ${buildout:parts-directory}/solr true

eventlisteners =
   SolrHttpOk TICK_60 ${buildout:bin-directory}/httpok [-p solr -t 20 http://localhost:8983/solr/]


[solr-files]
recipe = hexagonit.recipe.download
url = ftp://mir1.ovh.net/ftp.apache.org/dist/lucene/solr/1.3.0/apache-solr-1.3.0.tgz
md5sum = 23774b077598c6440d69016fed5cc810
strip-top-level-dir = true

[solr]
recipe = collective.recipe.solrinstance
solr-location = ${buildout:parts-directory}/solr-files
host = localhost
port = 8983

unique-key = uniqueID
default-search-field = text

index =
   name:uniqueID type:string indexed:true stored:true required:true
   name:text type:string indexed:true stored:true required:false omitnorms:false multivalued:true

[solr-conf]
recipe = iw.recipe.cmd
on_install = true
on_update = true
cmds =
   cp -v ${buildout:directory}/solr-conf/jetty.xml ${solr:jetty-destination}
   cp -v ${buildout:directory}/solr-conf/schema.xml ${solr:schema-destination}
   cp -v ${buildout:directory}/solr-conf/stopwords_fr.txt ${solr:schema-destination}

[solr-rebuild]
recipe = iw.recipe.cmd
on_install = true
on_update = true

# since solr is not started by solr-instance but supervisord, solr-instance has
# no pid file and thinks that solr is down. Thus we must run it with
# solr-instance to be able to "solr-instance purge"
cmds =
   ${buildout:bin-directory}/supervisorctl stop solr
   cp -v ${buildout:directory}/solr-conf/schema.xml ${solr:schema-destination}
   ${buildout:bin-directory}/solr-instance start
   COUNT=15; echo "Waiting $COUNT s"; sleep $COUNT
   ${buildout:bin-directory}/solr-instance purge
   time ${buildout:bin-directory}/${django:control-script} rebuild_index
   ${buildout:bin-directory}/solr-instance stop
   ${buildout:bin-directory}/supervisorctl start solr

当我运行 $ bin/buildout install solr-rebuild ,我得到以下输出:

`/appname/solr-conf/schema.xml' -> `/appname/parts/solr/solr/conf/schema.xml'
Solr started with pid 16023
Waiting 15 s
SimplePostTool: version 1.2
SimplePostTool: WARNING: Make sure your XML documents are encoded in UTF-8, other encodings are not currently supported
SimplePostTool: POSTing args to http://localhost:8983/solr/update..
SimplePostTool: COMMITting Solr index changes..

WARNING: This will irreparably remove EVERYTHING from your search index.
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.
All documents removed.
Indexing 1 news items.
Failed to add documents to Solr: [Reason: ERROR:unknown field 'django_ct']
0.32user 0.05system 0:02.82elapsed 13%CPU (0avgtext+0avgdata 57872maxresident)k
160inputs+8outputs (3major+4257minor)pagefaults 0swaps
Solr stopped successfully.

同样,运行$ bin/django rebuild_index$ bin/buildout update_index提示“django_ct”:

Failed to add documents to Solr: [Reason: ERROR:unknown field 'django_ct']

(我要尝试的一件事是将 solr 更新到最新版本。如果这样做,将会报告......)

我不确定下一步要看哪里.. 搜索谷歌、群组和 stackoverflow 并没有让我超越这一点。 提前致谢!

最佳答案

好的,问题解决了。更新到 Solr 1.4.1(奇怪的是,在那之后重新启动)就成功了。

关于python - 使用 zc.buildout 从 Django 添加到 solr 索引时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3685975/

相关文章:

python - Ajax调用不调用Django中的 View 函数

java - Solr:得分完全匹配高于部分匹配

python - 通过 Geodjango 中的几何交集关联两个模型

Python 像浅网格一样写入和读取 csv 文档?

python - 无法从 pipelinev virtualenv 导入 pyspark,因为它找不到 py4j

django-hstore DictionaryField 返回字符串而不是字典

python - Python 中的剪贴板问题

java - 改造 : response 500, 内部服务器错误

php - 在 Apache-Solr 中搜索部分单词

search - 关于数据结构/查询功能的elasticsearch vs solr