Solr学习经验 Solr坑

对于DataImport的使用方式 以及导入失败的解决方案

对于solr的DataImport 其实就是调用数据库连接执行sql进行数据的写入,以便后期来进行数据的查询。

使用方式:
	1 打开solr的客户端页面 http://xxx:8983/solr/。
	2 建立core目录。
	3点击core所对应的DataImport。
	4点击Execute。
即可导入成功。

当如果requests前面打了绿色的对勾说明执行成功了。当时经常会出现数据没有导入进去。也就是说Fetched,Processed字段的值都为0。如何解决呢?

如果出现上述的问题,其实和我们查看普通的web项目一样。去solr的安装目录下找到logs,进入logs,查看solr.log,就可以很方便的定位错误信息。

其实大部分的错误,可能都是网络不通导致的,或者是数据库用户没有外部访问权限导致的。	

Solr检索配置

域配置

   <field name="originId" type="pint" indexed="true" stored="true"/>
   <field name="searchTitle" type="text_general" indexed="true" stored="true" multiValued="false"/>
   <field name="searchContent" type="text_general" indexed="true" stored="true" multiValued="false"/>
   <field name="createTime" type="pdate" indexed="true" stored="true" multiValued="false"/>
   <field name="searchType" type="string" indexed="true" stored="true"/>
   <field name="originModule" type="string" indexed="false" stored="true"/>
   <field name="img" type="string" indexed="false" stored="true"/>
   <field name="icoImg" type="string" indexed="false" stored="true"/>

indexed :是否建立索引 如果true 那么就会将所导入的数据中此字段来建立索引
type :字段类型
sotred :存储(往那里存储?)
multiValued :(是否可以多值?)

域的作用 : 其实就是相当于自定义一个字段的类型,当我们新建一个字段类型的时候,相应的会通过java的一个类来进行处理对应的字段,例如我们常用的分词器,我们可以进行声明一个需要进行分词的文本格式的字段,如下:

<fieldType name="text_ik" class="solr.TextField">   
       <analyzer type="index" isMaxWordLength="false" class="org.wltea.analyzer.lucene.IKAnalyzer"/>   
       <analyzer type="query" isMaxWordLength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"/>   
</fieldType>

通过上面的配置方式,我们就可以是使用name为text_ik的字段类型了,当然具体的ik分词器配置这里不做讲解。

数据导入的db-data-config.xml

在每一个core的文件夹中都会有一个db-data.config.xml文件,此文件就是为了进行数据导入来使用的,具体配置如下:

<dataConfig>
	// 配置数据源 
    <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://xxxx?characterEncoding=UTF-8" user="xxx" password="xxx" />

        <document name="xxx">
                <entity name="product" query="SELECT CONCAT('product', id) as id, id AS originId, product_name AS searchTitle, product_desc AS searchContent, create_time AS createTime, product_video_image as img, product_icon as icoImg,'product' AS searchType, '产品' as originModule FROM geec_products where status = 6 AND category_id not in (select id from geec_products_category where p_id = 10048 or id = 10051)">
                </entity>
                <entity name="solution" query="SELECT CONCAT('solution', id) as id, id AS originId, solution_name AS searchTitle, intro AS searchContent, create_time AS createTime, solution_video_image as img, 'solution' AS searchType, '解决方案' as originModule FROM geec_trade_solutions_list where status = 6">
                </entity>
                <entity name="case" query="SELECT CONCAT('case', id) as id, id as originId, case_name as searchTitle, case_desc as searchContent, create_time as createTime, 'other' as searchType, '客户>案例' as originModule FROM geec_success_case where status = 6">
                </entity>
                <entity name="article" query="SELECT CONCAT('article', id) as id, id as originId, article_title as searchTitle, article_remark as searchContent, create_time as createTime, 'other' as searchType, '新闻' as originModule FROM geec_article where status = 6">
                </entity>
                <entity name="exhibition" query="SELECT CONCAT('exhibition', id) as id, id as originId, exhibition_name as searchTitle, exhibition_desc as searchContent, create_time as createTime, 'other' as searchType, '展会' as originModule FROM geec_exhibition where status = 1">
                </entity>
        </document>

</dataConfig>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值