gpt4 book ai didi

python - key 错误 : 'id' when trying to index documents to Solr using sunburnt

转载 作者:太空宇宙 更新时间:2023-11-04 01:11:59 25 4
gpt4 key购买 nike

我正在尝试使用 sunburnt 将一些文本文件索引到 Solr。下面是我的代码

solr_url = "http://localhost:8983/solr"      
h = httplib2.Http(cache="/var/tmp/solr_cache")
solr_instance = sunburnt.SolrInterface(url=solr_url, http_connection=h)

for url,title, webpage in webpages:
html_id = hashlib.md5(url).hexdigest()
doc = {"id":html_id, "content":webpage, "title":title}
solr_instance.add(doc)

try:
solr_instance.commit()
except:
print "Could not Commit Changes to Solr, check the log files."
else:
print "Successfully committed changes"

但是当我运行它时,出现以下错误。

  File "/Users/ananya/Desktop/dbms project/code/extractText/ExtractText.py", line 94, in index_to_Solr
solr_instance = sunburnt.SolrInterface(url=solr_url, http_connection=h)

File "/Users/ananya/anaconda/lib/python2.7/site-packages/sunburnt/sunburnt.py", line 166, in __init__
self.init_schema()

File "/Users/ananya/anaconda/lib/python2.7/site-packages/sunburnt/sunburnt.py", line 177, in init_schema
self.schema = SolrSchema(schemadoc, format=self.format)

File "/Users/ananya/anaconda/lib/python2.7/site-packages/sunburnt/schema.py", line 417, in __init__
if self.unique_key else None

KeyError: 'id'

我是 Solr 的新手。请帮我。我是否需要对架构文件进行任何更改?如果是,请告诉我怎么做。

谢谢。

最佳答案

如果您使用的是 Solr 4.8 或更高版本,这是一个 bug against sunburnt 0.6 .

The fork of sunburnt arafalov 有一个补丁为我修复了它。

尝试:

git clone git@github.com:arafalov/sunburnt.git
cd sunburnt
python setup.py install # optionally with --user

关于python - key 错误 : 'id' when trying to index documents to Solr using sunburnt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27165407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com