欢迎投稿

今日深度:

Solr开发,

Solr开发,


本文章仅供参考,没有提供完整的教程,着重点在搭建过程中可能遇到的各类问题,详细的教程网上有很多,可以多看看。
好文参考:Solr7.4.0应用部署Demo

服务部署

复制conf文件

修改data-config.xml文件

分为两种类型:

数据库

数据库的配置相对简单,可以同时配置多张表,写在document字段下即可,此处存在一个问题,id字段一般为uniqueKey,多张表的id字段可能出现重复的情况,可以如下配置id字段,在后面拼接表名,解决重名的问题。

<?xml version="1.0" encoding="utf-8"?>
<dataConfig>
    <!--dataSource标签配置数据库相关的信息-->
    <dataSource name = "db_source" type="JdbcDataSource"   
    driver="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@//127.0.0.1:1521/orcl"   
    user="11" password="11"/>  
    <document>
        <!--以下的dataSource指定上边的dataSource标签中的name属性,并不是必须要加的,除非你配置了多个数据源,这里我是一个数据源,所以,下边的dataSource属性是可以去掉的,另外,pk属性指定的是manage-schema文件中的uniqueKey标签中的值,即主键-->
        <entity name="tableName" transformer="ClobTransformer" dataSource="db_source"  PK="id"
        query="SELECT concat(id,'_tableName') id,title,author,CONTENT FROM tableName">
        <!--以下的字段column属性对应数据库中字段名称,name是对应solr这边配置的名称,注意id,默认名称即为id,表示solr这边一条数据的主键,以下三个是要在solr这边中建立索引的字段,比如数据库中有10个字段,我只需要为3个字段建立索引关系,那这里就写3个就好了
          如果数据库中的主键不是id,比如是objectId,那上边的query需要为它起一个别名为id即可-->
            <field column="id"  name="id" />
            <field column="title"  name="title" />
            <field column="author" name="author" />
            <field column="CONTENT" name="content" clob="true"/>
        </entity>
    </document>
</dataConfig>
本地文件

对富文本格式进行递归解析(设置recursivetrue),使用TikaEntityProcessor对文件进行解析,注意需要复制一堆架包到lib目录下,可以参考相关教程,一般来说在solr-7.5.0\contribsolr-7.5.0\dist目录下,主要添加了分词器架包以及tika解析文件的各类架包

  • 参考项目solr7.4 配置ikanalyzer和自带的中文分词器
  • ik-analyzer-solr7插件地址
<?xml version="1.0" encoding="utf-8"?>
<dataConfig>
    <dataSource type="BinFileDataSource"/>
    <document>
    <!-- 使用tika索引文件
        processor:FileListEntityProcessor
        dataSource:设置为空
        recursive:是否递归索引文件夹-->
        <entity name="file" processor="FileListEntityProcessor" dataSource="null" baseDir="fill your own file path here" fileName=".*.(doc)|(pdf)|(txt)|(docx)" rootEntity="false" recursive="true">
            <field column="file" name="fileName" />
            <field column="fileAbsolutePath" name="fileAbsolutePath" />
            <field column="fileDir" name="fileDir" />
            <entity name="files" processor="TikaEntityProcessor" url="${file.fileAbsolutePath}" format="text" onError="skip">
                <field column="Author" name="author" meta="true" />
                <field column="title" name="title" meta="true" />
                <field column="dc:format" name="format" meta="true" />
                <field column="text" name="text" />
            </entity>
        </entity>
    </document>
</dataConfig>
<field name="fileName" type="string" indexed="true" stored="true" multiValued="false" required="true"/>
<field name="fileAbsolutePath" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="fileDir" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="author" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="title" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="format" type="text_ik" indexed="true" stored="true" multiValued="false"/>
<field name="text" type="text_ik" indexed="true" stored="true" multiValued="false"/>

<!--  uniqueKey需要注意,后面文件导入的时候可能出现问题-->
<uniqueKey>fileName</uniqueKey>

<!-- The StrField type is not analyzed, but indexed/stored verbatim. -->
<fieldType name="string" class="solr.StrField" sortMissingLast="true" />
<fieldType name="plong" class="solr.LongPointField" docValues="true"/>
<!-- solr自带中文分词器-->
<fieldType name="text_smartcn" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
        <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>
    </analyzer>
</fieldType>

<!-- ik 中文分词器 -->
<fieldType name="text_ik" class="solr.TextField">
    <analyzer type="index">
        <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false" conf="ik.conf"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true" conf="ik.conf"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

文件上传

使用update/extract方法上传富文本

可能存在的问题

www.htsjk.Com true http://www.htsjk.com/solr/32692.html NewsArticle Solr开发, 本文章仅供参考,没有提供完整的教程,着重点在搭建过程中可能遇到的各类问题,详细的教程网上有很多,可以多看看。 好文参考:Solr7.4.0应用部署Demo 服务部署 复制con...
相关文章
    暂无相关文章
评论暂时关闭