solr之搭建企业搜索平台,配置文件

solr版本solr 3.1

              solr有几个配置文件是最重要的。solr.xml,solrconfig.xml,schema.xml,db-data-config.xml

               如果你不使用solr自带的更新索引的功能,想用solrj编程来实现索引更新,那么我可以告诉你db-data-config.xml文件没什么用,一个一个来介绍下这几个配置文件吧。

    看了网上很多大神的blog,然后自己开发经验之后发现这些配置文件都是蛮好理解的。


    1.  solr.xml配置例子:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<solr sharedLib="lib" persistent="true">
    <cores adminPath="/admin/cores">
        <core default="true" instanceDir="db" name="db"/>
        <core default="false" instanceDir="mail" name="mail"/>
        <core default="false" instanceDir="tika" name="tika"/>
    </cores>
</solr>


告诉搜索引擎,db这个文件夹下的配置文件是可用的配置。


2.solrconfig.xml 配置例子

    这个配置文件的东西就多了。先配置最简单的一个也是必须配置的一个。以后祥谈。

  <dataDir>${solr.data.dir:./solr/db/data}</dataDir>


3.db-data-config.xml,即相当于索引对应的数据库是什么,数据库表是什么。

这个是依你的实际情况来看的。

 

 

<dataConfig>  
        <dataSource type="JdbcDataSource" driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://127.0.0.1:1434;DatabaseName=lovo.cn" user="sa" password="xiaozd1!"/>  
    <document name="goodsInfo">  
            <entity name="solrdb" pk="id" query="select  GoodsId,GoodsName  
                                                                                                                                                                                                                                    
                                                                                                    from table
                                                                                                    ;">  
                                                                                                
            <field column="GoodsId" name="id" />  
            <field column="GoodsName" name="GoodsName" />
        </entity>  
    </document>  
</dataConfig> 

 

4.schema.xml 配置文件

主要是告诉搜索引擎建索引的时候哪些字段需要分词,哪些字段是什么类型。使用什么分词器,等等

<fields>
   <!-- Valid attributes for fields:
     name: mandatory - the name for the field
     type: mandatory - the name of a previously defined type from the
       <types> section
     indexed: true if this field should be indexed (searchable or sortable)
     stored: true if this field should be retrievable
     multiValued: true if this field may contain multiple values per document
     omitNorms: (expert) set to true to omit the norms associated with
       this field (this disables length normalization and index-time
       boosting for the field, and saves some memory).  Only full-text
       fields or fields that need an index-time boost need norms.
     termVectors: [false] set to true to store the term vector for a
       given field.
       When using MoreLikeThis, fields used for similarity should be
       stored for best performance.
     termPositions: Store position information with the term vector.  
       This will increase storage costs.
     termOffsets: Store offset information with the term vector. This
       will increase storage costs.
     default: a value that should be used if no value is specified
       when adding a document.
   -->

   <field name="id" type="string" indexed="true" stored="true" required="true" />
   <field name="sku" type="textTight" indexed="true" stored="true" omitNorms="true"/>
<!--   <field name="name" type="textgen" indexed="true" stored="true"/>-->
   <field name="alphaNameSort" type="alphaOnlySort" indexed="true" stored="false"/>
   <field name="manu" type="textgen" indexed="true" stored="true" omitNorms="true"/>
   <field name="cat" type="string" indexed="true" stored="true" multiValued="true"/>
   <field name="features" type="text" indexed="true" stored="true" multiValued="true"/>
   <field name="includes" type="text" indexed="true" stored="true" termVectors="true" termPositions="true" termOffsets="true" />

   <field name="weight" type="float" indexed="true" stored="true"/>
 <!--  <field name="price"  type="float" indexed="true" stored="true"/>-->
   <field name="popularity" type="int" indexed="true" stored="true" />
   <field name="inStock" type="boolean" indexed="true" stored="true" />

   <!--
   The following store examples are used to demonstrate the various ways one might _CHOOSE_ to
    implement spatial.  It is highly unlikely that you would ever have ALL of these fields defined.
    -->
   <field name="store" type="location" indexed="true" stored="true"/>

   <!-- Common metadata fields, named specifically to match up with
     SolrCell metadata when parsing rich documents such as Word, PDF.
     Some fields are multiValued only because Tika currently may return
     multiple values for them.
   -->
<!--   <field name="title" type="text" indexed="true" stored="true" multiValued="true"/>-->
   <field name="subject" type="text" indexed="true" stored="true"/>
   <field name="description" type="text" indexed="true" stored="true"/>
   <field name="comments" type="text" indexed="true" stored="true"/>
   <field name="author" type="textgen" indexed="true" stored="true"/>
   <field name="keywords" type="textgen" indexed="true" stored="true"/>
<!--   <field name="category" type="textgen" indexed="true" stored="true"/>-->
   <field name="content_type" type="string" indexed="true" stored="true" multiValued="true"/>
   <field name="last_modified" type="date" indexed="true" stored="true"/>
   <field name="links" type="string" indexed="true" stored="true" multiValued="true"/>


   <!-- catchall field, containing all other searchable text fields (implemented
        via copyField further on in this schema  -->
   <field name="text" type="text" indexed="true" stored="false" multiValued="true"/>
    
   <!-- catchall text field that indexes tokens both normally and in reverse for efficient
        leading wildcard queries. -->
   <field name="text_rev" type="text_rev" indexed="true" stored="false" multiValued="true"/>

   <!-- non-tokenized version of manufacturer to make it easier to sort or group
        results by manufacturer.  copied from "manu" via copyField -->
   <field name="manu_exact" type="string" indexed="true" stored="false"/>

   <field name="payloads" type="payloads" indexed="true" stored="true"/>

   <!-- Uncommenting the following will create a "timestamp" field using
        a default value of "NOW" to indicate when each document was indexed.
     -->
   <!--
   <field name="timestamp" type="date" indexed="true" stored="true" default="NOW" multiValued="false"/>
     -->
   

   <!-- Dynamic field definitions.  If a field name is not found, dynamicFields
        will be used if the name matches any of the patterns.
        RESTRICTION: the glob-like pattern in the name attribute must have
        a "*" only at the start or the end.
        EXAMPLE:  name="*_i" will match any field ending in _i (like myid_i, z_i)
        Longer patterns will be matched first.  if equal size patterns
        both match, the first appearing in the schema will be used.  -->
   <dynamicField name="*_i"  type="int"    indexed="true"  stored="true"/>
   <dynamicField name="*_s"  type="string"  indexed="true"  stored="true"/>
   <dynamicField name="*_l"  type="long"   indexed="true"  stored="true"/>
   <dynamicField name="*_t"  type="text"    indexed="true"  stored="true"/>
   <dynamicField name="*_txt" type="text"    indexed="true"  stored="true" multiValued="true"/>
   <dynamicField name="*_b"  type="boolean" indexed="true"  stored="true"/>
   <dynamicField name="*_f"  type="float"  indexed="true"  stored="true"/>
   <dynamicField name="*_d"  type="double" indexed="true"  stored="true"/>

   <!-- Type used to index the lat and lon components for the "location" FieldType -->
   <dynamicField name="*_coordinate"  type="tdouble" indexed="true"  stored="false"/>

   <dynamicField name="*_dt" type="date"    indexed="true"  stored="true"/>
   <dynamicField name="*_p"  type="location" indexed="true" stored="true"/>

   <!-- 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="ignored_*" type="ignored" multiValued="true"/>
   <dynamicField name="attr_*" type="textgen" indexed="true" stored="true" multiValued="true"/>

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

</fields>


后面专门再写一下solrconfig和schema.xml的详细配置。这里先只谈一下他们各自的作用。

posted @ 2013-04-23 16:02  Dream-Weaver  阅读(213)  评论(0编辑  收藏  举报