2013-02-21 3 views
1

HTML 파일의 메타 태그를 추출하고이를 tika 통합으로 solr로 색인하려고합니다. 나는 Tika와 함께 메타 태그를 추출 할 수 없으며 solr에 표시 할 수 없습니다.HTML 파일에서 메타 태그를 추출하고 SOLR 및 TIKA에서 색인을 생성하는 방법

내 HTML 파일은 다음과 유사합니다. 내의 schema.xml 파일에서이

<dataConfig> 
<dataSource name="bin" type="BinFileDataSource" /> 
    <document> 
    <entity name="f" dataSource="null" rootEntity="false" 
     processor="FileListEntityProcessor" 
     baseDir="/path/to/html/files/" 
     fileName=".*html|xml" onError="skip" 
     recursive="false"> 

     <field column="fileAbsolutePath" name="path" /> 
     <field column="fileSize" name="size"/> 
     <field column="file" name="filename"/> 

     <entity name="tika-test" dataSource="bin" processor="TikaEntityProcessor" 
     url="${f.fileAbsolutePath}" format="text" onError="skip"> 

     <field column="product_id" name="product_id" meta="true"/> 
     <field column="assetid" name="assetid" meta="true"/> 
     <field column="title" name="title" meta="true"/> 
     <field column="type" name="type" meta="true"/> 
     <field column="first" name="first" meta="true"/> 
     <field column="category" name="category" meta="true"/>  
     </entity> 
    </entity> 
</document> 
</dataConfig> 

같은

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<meta name="product_id" content="11"/> 
<meta name="assetid" content="10001"/> 
<meta name="title" content="title of the article"/> 
<meta name="type" content="0xyzb"/> 
<meta name="category" content="article category"/> 
<meta name="first" content="details of the article"/> 

<h4>title of the article</h4> 
<p class="link"><a href="#link">How cite the Article</a></p> 
<p class="list"> 
    <span class="listterm">Length: </span>13 to 15 feet<br> 
    <span class="listterm">Height to Top of Head: </span>up to 18 feet<br> 
    <span class="listterm">Weight: </span>1,200 to 4,300 pounds<br> 
    <span class="listterm">Diet: </span>leaves and branches of trees<br> 
    <span class="listterm">Number of Young: </span>1<br> 
    <span class="listterm">Home: </span>Sahara<br> 
</p> 
</p> 

내 데이터-config.xml 파일을 보면 나는 다음과 같은 필드를 추가했습니다.

<field name="product_id" type="string" indexed="true" stored="true"/> 
<field name="assetid" type="string" indexed="true" stored="true" /> 
<field name="title" type="string" indexed="true" stored="true"/> 
<field name="type" type="string" indexed="true" stored="true"/> 
<field name="category" type="string" indexed="true" stored="true"/> 
<field name="first" type="text_general" indexed="true" stored="true"/> 

내 solrconfing.xml 파일에 다음 코드를 추가했습니다.

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler" /> 
<lst name="defaults"> 
    <str name="config">/path/to/data-config.xml</str> 
</lst> 

사람은 SOLR 및 티카에있는 HTML 파일과 인덱스 그들로부터 그 메타 태그를 추출하는 방법을 알 수 있습니까? 귀하의 도움을 주시면 감사하겠습니다.

답변

1

나는 meta = "true"라고 생각하는 것이 의미한다고 생각하지 않습니다. 일반적으로 콘텐츠가 아닌 인 것을 말합니다. 그래서, content-type 등 아마도 http-equiv 매핑됩니다.

그 외의 경우 실제 내용을 추출해야합니다. format = "xml"을 사용하고 XPathEntityProcessor를 사용하여 내부 엔티티를 배치하고 경로를 매핑하면됩니다. 그렇다면 AFAIK, DIH는 DefaultHtmlMapper를 사용하기 때문에 막히기 때문에 제한적입니다. 'DefaultHtmlMapper'는 'class'및 'id'속성의 대부분과 'div'와 같은 것들을 건너 뜁니다. 소스 코드에서 직접 list of allowed elements and attributes을 읽을 수 있습니다.

솔직히 말해서 SolrJ 클라이언트를 소유하고 Tika를 직접 관리하는 것이 더 쉬운 방법입니다. 그런 다음 HTML과 관련없는 IdentityHtmlMapper를 사용하도록 설정할 수 있습니다.

+0

감사 :

그래서, 여기에 수정 solrconfig.xml입니다. 나는 SolrJ 클라이언트가 자바 애플리케이션 용이라고 생각한다. 내 응용 프로그램은 PHP에서이고 SolPHP 클라이언트를 사용하고 있습니다. SolPHP에서 제가 할 수있는 일이 있습니까? –

+0

Tika가 자바에 있습니다. 설정을 통해서만 맵퍼를 설정할 수 있는지 확실하지 않습니다. 그러나 Tika를 모두 건너 뛰고 PHP에서 HTML을 파싱하고 최종 문서를 직접 Solr에게 보내면 더 쉽습니다. –

+0

당신은 solrJ의 작동 방식과 기존의 solr와 어떻게 통합 할 수 있는지 자세히 설명해 주시겠습니까? –

1

사용중인 Solr 버전은 무엇입니까? Solr 4.0 이상을 사용하는 경우 tika이 내장되어 있습니다.

 <!-- Solr Cell Update Request Handler 

     http://wiki.apache.org/solr/ExtractingRequestHandler 

    --> 
    <requestHandler name="/update/extract" 
        startup="lazy" 
        class="solr.extraction.ExtractingRequestHandler" > 
    <lst name="defaults"> 
     <str name="lowernames">true</str> 
     <str name="uprefix">ignored_</str> 

     <!-- capture link hrefs but ignore div attributes --> 
     <str name="captureAttr">true</str> 
     <str name="fmap.a">links</str> 
     <str name="fmap.div">ignored_</str> 
    </lst> 
    </requestHandler> 

이제 기본적으로 SOLR에 당신이 위에서 볼 수 있듯이 : 티카는 다음과 같이 solrconfig.xml에 구성된 'SOLR - 세포''ExtractingRequestHandler' 클래스를 사용하여 SOLR와 통신 구성에서 schema.xml에 선언되지 않은 HTML 문서에서 추출 된 필드는 'ignored_' 접두어가 붙습니다. 즉, 'ignored_ *'schema.xml 내의 동적 필드에 매핑됩니다. 로 읽는 기본의 schema.xml은 다음과 같습니다

 <!-- some trie-coded dynamic fields for faster range queries --> 
    <dynamicField name="*_ti" type="tint" indexed="true" stored="true"/> 
    <dynamicField name="*_tl" type="tlong" indexed="true" stored="true"/> 
    <dynamicField name="*_tf" type="tfloat" indexed="true" stored="true"/> 
    <dynamicField name="*_td" type="tdouble" indexed="true" stored="true"/> 
    <dynamicField name="*_tdt" type="tdate" indexed="true" stored="true"/> 

    <dynamicField name="*_pi" type="pint" indexed="true" stored="true"/> 
    <dynamicField name="*_c" type="currency" indexed="true" stored="true"/> 

    <dynamicField name="ignored_*" type="ignored" multiValued="true"/> 
    <dynamicField name="attr_*" type="text_general" indexed="true" stored="true" multiValued="true"/> 

    <dynamicField name="random_*" type="random" /> 

    <!-- uncomment the following to ignore any fields that don't already match an existing 
     field name or dynamic field, rather than reporting them as an error. 
     alternately, change the type="ignored" to some other type e.g. "text" if you want 
     unknown fields indexed and/or stored by default --> 
    <!--dynamicField name="*" type="ignored" multiValued="true" /--> 

</fields> 

그리고 다음은 유형을 처리하는 '무시'하는 방법 입니다 :

<!-- since fields of this type are by default not stored or indexed, 
    any data added to them will be ignored outright. --> 
<fieldtype name="ignored" stored="false" indexed="false" multiValued="true" class="solr.StrField" /> 

그래서 티카에 의해 추출 된 메타 데이터 에 넣어 디폴트로 ' ' 필드가 Solr-Cell에 의해 무시되고 색인 및 저장을 위해 무시되는 이유가 있습니다. 따라서, 인덱스저장에 metadatas 당신은 "uprefix = attr_" 또는 알려진 metadatas에 대한 '이 특정 필드 또는 동적 필드 만들기'당신이 원하는대로 그들을 치료 변경하십시오. 당신의 조언을

<!-- Solr Cell Update Request Handler 

     http://wiki.apache.org/solr/ExtractingRequestHandler 

    --> 
    <requestHandler name="/update/extract" 
        startup="lazy" 
        class="solr.extraction.ExtractingRequestHandler" > 
    <lst name="defaults"> 
     <str name="lowernames">true</str> 
     <str name="uprefix">attr_</str> 

     <!-- capture link hrefs but ignore div attributes --> 
     <str name="captureAttr">true</str> 
     <str name="fmap.a">links</str> 
     <str name="fmap.div">ignored_</str> 
    </lst> 
    </requestHandler>