2013-07-12 1 views
2

Apache Solr과 상호 작용하기 위해 Solr의 php extension을 사용하고 있습니다. 데이터베이스에서 데이터를 인덱싱하고 있습니다. 외부 파일의 내용 (예 : PDF, PPTX)을 색인화하려고했습니다. 색인에 대한 Apache Solr을 사용한 PDF 파일 내용 색인

논리

은 다음과 같습니다 는 schema.xml 정의 다음과 같은 필드가 가정 :

<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
<field name="created" type="tlong" indexed="true" stored="true" /> 
<field name="name" type="text_general" indexed="true" stored="true"/> 
<field name="filepath" type="text_general" indexed="false" stored="true"/> 
<field name="filecontent" type="text_general" indexed="false" stored="true"/> 

하나의 데이터베이스 항목은/저장된 파일이있을 수도 있고 없을 수도 있습니다.

따라서, 다음과 같은 색인 내 코드입니다 :

$post = stdclass object having the database content 
$doc = new SolrInputDocument(); 
$doc->addField('id', $post->id); 
$doc->addField('name', $post->name); 
.... 
.... 
$res = $client->addDocument($doc); 
$client->commit(); 

다음, 나는 위와 같은 SOLR 문서의 PDF 파일의 내용을 추가 할.

curl 코드 :

$ch = curl_init(' 
http://localhost:8010/solr/update/extract?'); 
curl_setopt ($ch, CURLOPT_POST, 1); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, array('myfile'=>'@'.$post->filepath)); 
$result= curl_exec ($ch); 

하지만, 내가 뭔가를 놓친 것 같아. 나는 documentation를 읽을 수 있지만 나는 1field: filecontent

편집 #에서 기존 SOLR 문서에 추가 한 다음 파일의 내용을 검색하고하는 방법을 알아낼 수 없습니다 : 나는에 literal.id=xyz을 설정하려고하면 을 컬 요청을 수신하면, id=xyz을 갖는 새로운 solr 문서를 생성한다. 나는 새로운 solr 문서가 생성되는 것을 원하지 않는다. pdf의 내용을 이전에 만든 solr 문서의 필드로 인덱싱하여 저장하려고합니다.

$doc = new SolrInputDocument();//Solr document is created $doc->addField('id', 98765);//The solr document created above is assigned an id=`98765` .... .... $ch = curl_init(' http://localhost:8010/solr/update/extract?literal.id=1&literal.name=Name&commit=true'); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, array('myfile'=>'@'.$post->filepath)); $result= curl_exec ($ch); 

나는 위의 SOLR 문서 (id = 98765)는 PDF 파일의 내용이 저장 &을 색인을 생성하는 필드를 갖고 싶어.

그러나 위와 같이 cURL 요청은 id = 1과 함께 다른 새 문서를 만듭니다. 나는 그것을 원하지 않는다.

답변

2

Apache Tika가있는 Solr은 서식있는 문서의 내용을 추출하여 Solr 문서에 다시 추가하는 처리를 수행합니다.

Documentation : -

당신은 당신이 샘플 문서의 텍스트 중 하나에서 검색 할 수 있지만, 당신은 문서를 검색 할 때 텍스트를 볼 수 없을 수 있다는 것을 알 수 있습니다. 이것은 Tika에서 생성 한 "content"필드 이 "text"라는 Solr 필드에 매핑 되었기 때문에 간단히 나타납니다.이 필드는 인덱싱되었지만 저장되지 않은 입니다. 이 작업은 solrconfig.xml의 /update/extract 처리기의 기본 맵 규칙을 통해 수행되며 쉽게 변경하거나 을 재정의 할 수 있습니다. 이 파일의 내용이를 무시 유지하기 위해 다른 속성을 정의하는 경우

<!-- Main body of document extracted by SolrCell. 
    NOTE: This field is not indexed by default, since it is also copied to "text" 
    using copyField below. This is to save space. Use this field for returning and 
    highlighting document content. Use the "text" field to search the content. --> 
<field name="content" type="text_general" indexed="false" stored="true" multiValued="true"/> 

- :

기본의 schema.xml 예를 들어, 저장하고 모든 메타 데이터 및 콘텐츠를 볼 수, 다음을 실행 solrconfig.xml 자체에 기본값은 fmap.content=filecontent입니다.

fmap.content는 = attr_content의 PARAM은 텍스트 내용 대신 attr_content 필드에 추가하는 원인 = 기본 fmap.content 우선합니다.

단일 문서에서 색인을 생성하려는 경우 리터럴 접두어를 사용하십시오. literal.id=1&literal.name=Name (속)는

$ch = curl_init(' 
http://localhost:8010/solr/update/extract?literal.id=1&literal.name=Name&commit=true'); 
curl_setopt ($ch, CURLOPT_POST, 1); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, array('myfile'=>'@'.$post->filepath)); 
$result= curl_exec ($ch); 
+0

내 질문을 이해하지 못했습니다. 인덱싱이 끝났습니다. 검색도 성공적입니다. wiki에있는 curl 명령을 실행할 때 "새로운"Solr 문서로 추가합니다. "curl"http : // localhost : 8983/solr/update/extract? literal.id = doc1 & commit = true "-F"[email protected] "'->이 명령은'id = doc1 '는 tutorial.html의 내용을 색인화하고 커밋합니다. 이전에 정의 된 solr 문서의 html/pdf 내용을 필드에 추가하여 "새"문서가 생성되지 않지만 기존 필드에 필드가 추가되도록하려고합니다. – xan

+0

하나의 Solr 문서에 여러 개의 리치 문서를 추가 하시겠습니까? Solr은 단일 문서로 여러 개의 서식있는 문서를 허용하지 않지만 문서를 함께 압축하여 solr에 공급할 수 있습니다. SOLR-2332를 확인하십시오. 또한 Solr 부분 업데이트를 확인하여 다중 값 필드에 추가되는 solr에 문서를 공급할 수 있습니다. – Jayendra

+0

아니요. 여러 문서가 아닙니다. '$ doc = new SolrInputDocument()'는 새로운 solr 문서를 만든다. 그런 다음 필드에 필드를 추가합니다 ('id','name','title' 등). 이 문서에서는 pdf 파일의 내용을 추가하려고합니다. 그러나 위의 코드에서와 같이 cURL 요청을 실행하면 자체 필드가있는 다른 새로운 solr 문서가 만들어집니다. – xan

관련 문제