2

我正在尝试使用 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 很陌生。请帮我。我需要对架构文件进行任何更改吗?如果是,请告诉我如何。

谢谢。

4

1 回答 1

3

如果您使用 Solr 4.8 或更高版本,这是针对 sunburnt 0.6 的错误

arafalov 的 sunburnt的叉子有一个补丁可以为我修复它。

尝试:

git clone git@github.com:arafalov/sunburnt.git
cd sunburnt
python setup.py install # optionally with --user
于 2015-01-29T18:15:45.337 回答