solr学习二(ExtractingRequestHandler)

通过ExtractingRequestHandler,slor能够读取word、pdf等文件,并用于全文搜索。废话少说,进入主题: 
    solr服务端是配出来的: 
    solrconfig.xml: 
    <requestHandler name="/update/extract" 
                  startup="lazy" 
                  class="solr.extraction.ExtractingRequestHandler" > 
    <lst name="defaults"> 
      <!-- All the main content goes into "text"... if you need to return 
           the extracted text or do highlighting, use a stored field. --> 
      <str name="fmap.content">filestream</str> 
      <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> 
    <lst name="date.formats"> 
          <str>yyyy-MM-dd</str> 
        </lst> 
    </requestHandler> 
   fmap.content是tika读取文件存放的位置,filestream是在schema.xml中的Field,该Field最好是stored="false",因为根据文章内容建立索引后无需将文章保存。 
    <str name="lowernames">true</str>建议去掉,不然Field中的字段都必须是小写!!(官网坑爹 ) 
    <lst name="date.formats">制定格式为yyyy-MM-dd,Field只能接受yyyy-MM-dd格式的字符串。 

    schema.xml: 
    要全文搜索的文本,我都是用了 
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100"> 
      <analyzer type="index"> 
        <tokenizer class="solr.StandardTokenizerFactory"/> 
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" /> 
        <!-- in this example, we will only use synonyms at query time 
        <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/> 
        --> 
        <filter class="solr.LowerCaseFilterFactory"/> 
      </analyzer> 
      <analyzer type="query"> 
        <tokenizer class="solr.StandardTokenizerFactory"/> 
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" /> 
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/> 
        <filter class="solr.LowerCaseFilterFactory"/> 
      </analyzer> 
</fieldType> 
必须有的几个Field(name自定义): 
<field name="id" type="string" indexed="true" 
   stored="true" required="true"/> 
<uniqueKey>id</uniqueKey> 
solrconfig.xml中配置的filestream: 
<field name="filestream" type="text_general" indexed="true" stored="true" 
omitNorms="true"/> 
也可以配置日期格式: 
<field name="releasetime" type="date" indexed="true" stored="true" /> 


    对于dynamicField,我的理解是为metadata准备的,metadata是tika中获取的文件的信息,如: 
[Revision-Number, 2, Last-Author, 微软用户, Template, Normal.dot, Page-Count, 1, subject, , Application-Name, Microsoft Office Word, Author, 微软用户, Word-Count, 5, xmpTPg:NPages, 1, Edit-Time, 600000000, Creation-Date, 2012-02-14T02:30:00Z, Character Count, 32, stream_size, 24064, Company, 微软中国, Content-Type, application/msword, Keywords, , Last-Save-Date, 2012-02-14T02:31:00Z 

    当然,metadata也可以不用默认的属性,自己配存什么属性。

posted on 2017-10-30 15:22  cxhfuujust  阅读(336)  评论(0编辑  收藏  举报

导航