我是 Solr 的新手。我一直在关注http://haystacksearch.org/站点中提供的文档。我的项目在 django 1.4 上。
我遵循的步骤:
1.添加干草堆到已安装的应用程序。
2.修改settings.py
HAYSTACK_SITECONF = 'directory.search_sites'
HAYSTACK_SEARCH_ENGINE = 'solr'
HAYSTACK_SOLR_URL = 'http://127.0.0.1:8983/solr'
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://127.0.0.1:8983/solr'
# ...or for multicore...
# 'URL': 'http://127.0.0.1:8983/solr/mysite',
},
}
3.我的search_indexes.py文件
from haystack import indexes
from app.models import SellerItem
class SellerItemIndex(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr='title')
sub_title = indexes.CharField(model_attr='sub_title')
description = indexes.CharField(model_attr='description')
def get_model(self):
return SellerItem
def index_queryset(self):
"""Used when the entire index for model is updated."""
return self.get_model().objects.filter(pk__gt=0)
4.增加了search_sites.py
import haystack
haystack.autodiscover()
5.添加模板/搜索/索引/selleritem.txt
{{ object.title }}
{{ object.sub_title }}
{{ object.description }}
6.将此添加到urls.py:
(r'^search/', include('haystack.urls')),
7.创建搜索模板
8.用生成的xml替换apache-solr-3.6.0/example/solr/conf中的schema.xml,使用命令:
python manage.py build_solr_schema
启动 solr 服务器时出现这样的错误:
SEVERE: org.apache.solr.common.SolrException: undefined field text
at org.apache.solr.schema.IndexSchema.getDynamicFieldType(IndexSchema.java:1330)
at org.apache.solr.schema.IndexSchema$SolrQueryAnalyzer.getAnalyzer(IndexSchema.java:408)
at org.apache.solr.schema.IndexSchema$SolrIndexAnalyzer.reusableTokenStream(IndexSchema.java:383)
at org.apache.lucene.queryParser.QueryParser.getFieldQuery(QueryParser.java:574)
at org.apache.solr.search.SolrQueryParser.getFieldQuery(SolrQueryParser.java:206)
at org.apache.lucene.queryParser.QueryParser.Term(QueryParser.java:1429)
at org.apache.lucene.queryParser.QueryParser.Clause(QueryParser.java:1317)
at org.apache.lucene.queryParser.QueryParser.Query(QueryParser.java:1245)
at org.apache.lucene.queryParser.QueryParser.TopLevelQuery(QueryParser.java:1234)
at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:206)
at org.apache.solr.search.LuceneQParser.parse(LuceneQParserPlugin.java:79)
at org.apache.solr.search.QParser.getQuery(QParser.java:143)
at org.apache.solr.handler.component.QueryComponent.prepare(QueryComponent.java:105)
at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:165)
at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:129)
at org.apache.solr.core.SolrCore.execute(SolrCore.java:1376)
at org.apache.solr.core.QuerySenderListener.newSearcher(QuerySenderListener.java:59)
at org.apache.solr.core.SolrCore$3.call(SolrCore.java:1182)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
服务器仍然会启动当我做 ./manage.py rebuild_index 并进行搜索时,我得到一个错误日志
Problem accessing /solr/select/. Reason:undefined field text
我错过了什么?以前有人遇到过同样的问题吗?
谢谢