2013-09-26 4 views
2

그냥 solr 학습을 시작했습니다. solrpy를 클라이언트로 사용하려고합니다. 내 파이썬 코드는 다음과 같습니다이 내 SOLR의의 schema.xml이 SOLR 배포와 함께 제공되는 기본 스키마입니다 heresolrpy로 Solr 색인 생성 문제

주어진 예에서입니다

import solr 

# create a connection to a solr server 
s = solr.SolrConnection('http://localhost:8983/solr') 

# add a document to the index 
doc = dict(
    id='testid123', 
    title='Lucene in Action', 
    author=['Erik Hatcher', 'Otis Gospodneti'], 
    ) 
s.add(doc, commit=True) 

# do a search 
response = s.query('title:lucene') 
for hit in response.results: 
    print hit['title'] 

. 나는 그것을 조금도 변경하지 않았다. 그것은 "id"로 uniqueKey 필드를 가지고 있습니다. 내 클라이언트 측에서 내 코드를 실행할 때

<uniqueKey>id</uniqueKey> 

그리고 그것은 문자열 유형이다

<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 

아직도 내가 얻을 오류 :

Traceback (most recent call last): 
    File "/Users/user1/Documents/workspace/PyDelight/src/Test.py", line 12, in <module> 
    s.add(doc, commit=True) 
    File "/Library/Python/2.7/site-packages/solrpy-0.9.5-py2.7.egg/solr/core.py", line 678, in add 
    return Solr.add_many(self, [fields], commit=_commit) 
    File "/Library/Python/2.7/site-packages/solrpy-0.9.5-py2.7.egg/solr/core.py", line 326, in wrapper 
    return self._update(content, query) 
    File "/Library/Python/2.7/site-packages/solrpy-0.9.5-py2.7.egg/solr/core.py", line 550, in _update 
    rsp = self._post(selector, request, self.xmlheaders) 
    File "/Library/Python/2.7/site-packages/solrpy-0.9.5-py2.7.egg/solr/core.py", line 639, in _post 
    return check_response_status(self.conn.getresponse()) 
    File "/Library/Python/2.7/site-packages/solrpy-0.9.5-py2.7.egg/solr/core.py", line 1097, in check_response_status 
    raise ex 
solr.core.SolrException: HTTP code=400, reason=Bad Request 

내가 얻을 SOLR 추적 측 오류 :

843169 [qtp1151734776-20] INFO org.apache.solr.update.processor.LogUpdateProcessor ? [collection1] webapp=/solr path=/update params={commit=true} {} 0 0 
843170 [qtp1151734776-20] ERROR org.apache.solr.core.SolrCore ? org.apache.solr.common.SolrException: Document is missing mandatory uniqueKey field: id 

schema.xml 파일/example/solr/collection1/conf

그리고 예제 디렉토리에서 start.jar을 실행하여 solr을 실행하고 있습니다.

어디서 잘못 생각하나요?

답변

2

나는 solrpy를 많이 사용하지 않았지만 아직 설치하지 않았지만 초기 예제에서 사전 대신 attribute = value 쌍으로 호출되기를 원하는 것처럼 보입니다. (난 당신이 게시 된 예는 온라인 0.9.2 문서에서 잘 알고 있지만, GitHub의에서 현재 소스는 의견이있다!) :

add(**params) 
     Add a document. Pass in all document fields as 
     keyword parameters: 
      add(id='foo', notes='bar') 
     You must "commit" for the addition to be saved. 

그래서이 시도 :

s.add(commit=True, **doc)  

과 아마 작동 할거야. 커밋을 풀고 별도로해야 할 수도 있습니다. 잘 모르겠습니다.

나는 솔로 전문가가 아니며 솔로이보다 sunburnt을 사용하여 더 좋은 행운을 얻었습니다. 어쩌면 가치있는 일이지.

편집 : 해당 파일 GitHub의 포인터는 여기에 있습니다 : http://code.google.com/p/solrpy/source/browse/solr/core.py

+0

문제는 매개 변수가 전달 될 수있는 방법을 참이었다. 여전히 '커밋'프로세스에는 몇 가지 문제가 있습니다. 그러나 당신의 제안에 나는 햇볕에 타서 시간을 보낼 것입니다. 그것으로 건너 뛰고 설명서가 훨씬 자세하게 보입니다. 감사 :) – rishi

0

솔트를 사용하지 않았으므로 완전히 잘못 될 수 있습니다. 예를 들어 id에 연결하면 int입니다. int을 작성하고 'testid123'에서 123과 같은 ID로 ID를 변경하고 어떤 일이 발생하는지 확인해보십시오.