solr5.5.0 自定义fieldType

在项目初期如果定义了很多 字段类型fieldType  可以在conf 文件中就添加进去


1:基本信息罗列
   1)配置文件目录罗列
   [wasuser@eciassitapp13 configsets]$ pwd
   /opt/pec/solr/solr-node1/server/solr/configsets
   [wasuser@eciassitapp13 configsets]$ ll
   total 16
   drwxr-xr-x 3 wasuser wasuser 4096 Feb 27 15:38 basic_configs
   drwxr-xr-x 3 wasuser wasuser 4096 Feb 27 15:38 data_driven_schema_configs
   drwxr-xr-x 3 wasuser wasuser 4096 Feb 27 15:38 sample_techproducts_configs
   drwxr-xr-x 3 wasuser wasuser 4096 Mar  1 17:49 test_config

    2)创建collection 命令

    [wasuser@eciassitapp13 solr-node1]$ bin/solr create -h

    Usage: solr create [-c name] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port]
    由此命令可看出  【-d confdir】指定配置文件目录,就是1)中自定义的目录

    3) 在1)中的test_config 文件夹是我从data_driven_schema_configs cp 过来的,其中的 managed-schema 文件增加了
   <fieldType name="text_ik" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
      <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" conf="ik.conf" useSmart="false"/>
      <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" conf="ik.conf" useSmart="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="org.apache.solr.analysis.DStopFilterFactory" conf="stop.conf" ignoreCase="true"/>
      <filter class="org.apache.solr.analysis.DSynonymFilterFactory" expand="true" conf="synonym.conf" ignoreCase="true"/>
    </analyzer>
  </fieldType>

需要增加的字段类型text_ik
  

     4)在text_ik中用到的自定义java 类是在
     mlcsseg-common-5.3.1.jar
     mlcsseg-filter-5.3.1.jar
     mlcsseg-ik-5.3.1.jar
     三个jar 包中


     5)jar包是通过 1)中的 solrconfig.xml 文件指定的路径

2:创建collection 的命令
 
   [wasuser@eciassitapp13 solr-node1]$ bin/solr create -c myCollection 
       -d  test_config  -replicationFactor 2  -shards 2 -n myConf
  


3:增加单个的字段命令

curl -X POST -H 'Content-type:application/json' --data-binary '{
"add-field":{
"name":"sell-by",
"type":"date",
"stored":false }
}' http://10.27.58.42:8983/solr/myCollection/schema


curl -X POST -H 'Content-type:application/json' --data-binary '{
"add-dynamic-field":{
"name":"*_zhn",
"type":"text_ik",
"stored":true,
"indexed":true,
"multiValued":true
}
}' http://10.27.58.42:8983/solr/mycollection/schema
 

你可能感兴趣的:(solr5.5.0 自定义fieldType)