Python 如何在pysolr中使用facet
我已经成功地用pysolr构建了一个python搜索应用程序。到目前为止,我使用了两个字段:id和title。现在我想推出两个不同版本的标题;删除停止词后的原文和标题。有什么想法吗?以下代码起作用:Python 如何在pysolr中使用facet,python,pysolr,Python,Pysolr,我已经成功地用pysolr构建了一个python搜索应用程序。到目前为止,我使用了两个字段:id和title。现在我想推出两个不同版本的标题;删除停止词后的原文和标题。有什么想法吗?以下代码起作用: def BuildSolrIndex(solr, trandata): tmp = [] for i, dat in enumerate(trandata): if all(d is not None and len(d) > 0 for d in dat):
def BuildSolrIndex(solr, trandata):
tmp = []
for i, dat in enumerate(trandata):
if all(d is not None and len(d) > 0 for d in dat):
d = {}
d["id"] = dat[0]
d["title"] = dat[1]
tmp.append(d)
solr.add(tmp)
solr.optimize()
return solr
但这一条没有:
def BuildSolrIndex(solr, trandata):
tmp = []
for i, dat in enumerate(trandata):
if all(d is not None and len(d) > 0 for d in dat):
d = {}
d["id"] = dat[0]
d["title_org"] = dat[1]
d["title_new"] = CleanUpTitle(dat[1])
tmp.append(d)
solr.add(tmp)
solr.optimize()
return solr
有什么想法吗
编辑:
以下是例外情况:
Traceback (most recent call last):
...
solr = BuildSolrIndex(solr, trandata)
File "...", line 56, in BuildSolrIndex
solr.add(tmp)
File "build/bdist.linux-x86_64/egg/pysolr.py", line 779, in add
File "build/bdist.linux-x86_64/egg/pysolr.py", line 387, in _update
File "build/bdist.linux-x86_64/egg/pysolr.py", line 321, in _send_request
pysolr.SolrError: [Reason: None]
<response><lst name="responseHeader"><int name="status">400</int><int name="QTime">8</int></lst><lst name="error"><str name="msg">ERROR: [doc=...] unknown field 'title_new'</str><int name="code">400</int></lst></response>
回溯(最近一次呼叫最后一次):
...
solr=BuildSolrIndex(solr,transdata)
BuildSolrIndex中第56行的文件“…”
解决方案添加(tmp)
文件“build/bdist.linux-x86_64/egg/pysolr.py”,第779行,添加
更新中第387行的文件“build/bdist.linux-x86_64/egg/pysolr.py”
文件“build/bdist.linux-x86_64/egg/pysolr.py”,第321行,在发送请求中
pysolr.SolrError:[原因:无]
4008错误:[doc=…]未知字段“title\u new”400
您的Solr schema.xml似乎存在问题,因为异常表明“title\u new”未被识别为有效字段。此答案可能对您有所帮助:
检查以确保schema.xml包含“title\u new”字段,并且在必要时已重新启动Solr服务。如果这不能解决你的问题,回来吧 怎么会让你说它不起作用?你有例外吗?是的,没错。它在这里抛出一个异常:
solr.add(tmp)
什么异常?请编辑您的问题并添加完整的回溯。@Faust问题已更新。谢谢!但是这个模式到底位于哪里?可能就是这个,正确:。/solr-4.6.0/example/solr/collection1/conf/schema.xml
在不知道具体的solr实现的情况下,我不能说:)