Solr--MySql数据源

Solr--MySql数据源的配置 弄了半天终于弄好了记录下步骤如下:

1:在solr应用目录下创建 core0目录 目录结构如下:

/home/solr_home/core0
├── conf
│   ├── dataimport.properties
│   ├── db-data-config.xml #数据源 使用的是mysql数据愿
│   ├── schema.xml 
│   └── solrconfig.xml
└── data
    ├── index #索引文件目录
    └── tlog

2:编辑solrconfig.xml 文件 配置 mysql 驱动及solr-dataimporthanderz

在config 下面加入 :

<lib dir="/home/solr_home/lib/dist/" regex="solr-dataimporthandler-.*\.jar" />
<lib dir="/home/solr_home/lib/driver/" regex=".*\.jar" /> <!-- mysql驱动-->

<dataDir>${solr.core0.data.dir:/home/solr_home/core0/data}</dataDir> <!-- 索引目录-->

加入数据源文件:

<!-- Mysql Dataimport-->
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> 
    <lst name="defaults"> 
          <str name="config">db-data-config.xml</str> 
    </lst> 
</requestHandler> 

2:编辑db-data-config.xml

<dataConfig> 
        <dataSource type="JdbcDataSource"
                    driver="com.mysql.jdbc.Driver"
                    url="jdbc:mysql://192.168.0.8:3306/liujijun"
                    user="root"
                    password="gc7232275"/> 
            <document name="gc_company"> 
                        <entity name="gccompany" pk="cid" query="select cid,companyname,username from gc_company"> 
                             <field column="cid" name="cid" /> 
                             <field column="companyname" name="companyname" /> 
                             <field column="username" name="username"/> 
                       </entity> 
           </document>
</dataConfig>

3:schem.xml内容如下:

<?xml version="1.0" ?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<schema name="example core zero" version="1.1">
  <types>
   <fieldtype name="string"  class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
   <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
   <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
  </types>

 <fields>  
  <!-- general -->
  <field name="cid"        type="int"   indexed="true"  stored="true"  multiValued="false" required="true"/>
  <field name="companyname"      type="string"   indexed="true"  stored="true"  multiValued="false" />
  <field name="username"      type="string"   indexed="true"  stored="true"  multiValued="false" />
  <field name="_version_" type="long"     indexed="true"  stored="true"/>
 </fields>

 <!-- field to use to determine and enforce document uniqueness. -->
 <uniqueKey>cid</uniqueKey>

 <!-- field for the QueryParser to use when an explicit fieldname is absent -->
 <defaultSearchField>companyname</defaultSearchField>

 <!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
 <solrQueryParser defaultOperator="OR"/>
</schema>

期间遇到一个问题就是 没有在schema.xml中加入要索引的字段 索引没有办法生成索引文件!

下面要研究的是 索引的及时更新和删除、 中文分词、solrcloud、性能优化方面。

几乎把solr的英文稳定给看了一遍,虽然头大但是一遍下来solr明白了,英文也提高了!!

你可能感兴趣的:(Solr--MySql数据源)