一、下载jar包
将源文件..solr-8.1.1\dist文件夹下的solr-dataimporthandler*.jar 以及数据库的jar包放置
“…\apache-tomcat-8.5.39\webapps\solr\WEB-INF\lib”目录下
注:用什么数据库,就用什么jar包
我这里用的是postgresql数据库
jar的地址:链接:https://pan.baidu.com/s/15VAAyZpQS1NxAdtM35CSDg 密码:cxjo
二、在..\solr-home\configsets\conf路径下新建data-config.xml配置文件
内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<dataConfig>
<!--mysql-->
<!--<dataSource name="member" type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/fxdevelop" user="postgres" password="66666"/>-->
<!--postgresql-->
<dataSource name="member" type="JdbcDataSource" driver="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/fxdevelop" user="postgres" password="66666"/>
<document>
<entity name="member" pk="id" dataSource="member" query="select code, id, account, secret, member_name, member_type, proxy_code, proxy_code_first,
proxy_code_second, proxy_code_third, proxy_code_reconmmend, mobile, bank_num, bank_addr,
bank_owner_name, id_card_num, proxy_level, qrcode_url, wx_openid, wx_unionid, wx_nick,
wx_head_url, proxy_name, recommend, real_name, source, sale_money, recommend_money,
card_face_path, card_back_path,
to_char(create_time,'yyyymmddhh24miss')create_time,
check_sate,
to_char(three_proxy_apply_time,'yyyymmddhh24miss')three_proxy_apply_time,
to_char(three_proxy_check_time,'yyyymmddhh24miss')three_proxy_check_time,
to_char(two_proxy_apply_time,'yyyymmddhh24miss')two_proxy_apply_time,
to_char(two_proxy_check_time,'yyyymmddhh24miss')two_proxy_check_time,
to_char(one_proxy_apply_time,'yyyymmddhh24miss')one_proxy_apply_time,
to_char(one_proxy_check_time,'yyyymmddhh24miss')one_proxy_check_time,
proxy_level_apply,
is_goods, is_once, wx_ticket, recommend_proxy_count, follower_count,wx_no
from fx_member">
<field column="id" name="id"/>
<field column="code" name="fms_code"/>
<field column="account" name="fms_account"/>
<field column="secret" name="fms_secret"/>
<field column="member_name" name="fms_member_name"/>
<field column="member_type" name="fms_member_type"/>
<field column="proxy_code" name="fms_proxy_code"/>
<field column="proxy_code_first" name="fms_proxy_code_first"/>
<field column="proxy_code_second" name="fms_proxy_code_second"/>
<field column="proxy_code_third" name="fms_proxy_code_third"/>
<field column="proxy_code_reconmmend" name="fms_proxy_code_reconmmend"/>
<field column="mobile" name="fms_mobile"/>
<field column="bank_num" name="fms_bank_num"/>
<field column="bank_addr" name="fms_bank_addr"/>
<field column="bank_owner_name" name="fms_bank_owner_name"/>
<field column="id_card_num" name="fms_id_card_num"/>
<field column="proxy_level" name="fms_proxy_level"/>
<field column="qrcode_url" name="fms_qrcode_url"/>
<field column="wx_openid" name="fms_wx_openid"/>
<field column="wx_unionid" name="fms_wx_unionid"/>
<field column="wx_nick" name="fms_wx_nick"/>
<field column="wx_head_url" name="fms_wx_head_url"/>
<field column="proxy_name" name="fms_proxy_name"/>
<field column="recommend" name="fms_recommend"/>
<field column="real_name" name="fms_real_name"/>
<field column="source" name="fms_source"/>
<field column="sale_money" name="fms_sale_money"/>
<field column="recommend_money" name="fms_recommend_money"/>
<field column="card_face_path" name="fms_card_face_path"/>
<field column="card_back_path" name="fms_card_back_path"/>
<field column="create_time" name="fms_create_time"/>
<field column="check_sate" name="fms_check_sate"/>
<field column="three_proxy_apply_time" name="fms_three_proxy_apply_time"/>
<field column="three_proxy_check_time" name="fms_three_proxy_check_time"/>
<field column="two_proxy_apply_time" name="fms_two_proxy_apply_time"/>
<field column="two_proxy_check_time" name="fms_two_proxy_check_time"/>
<field column="one_proxy_apply_time" name="fms_one_proxy_apply_time"/>
<field column="one_proxy_check_time" name="fms_one_proxy_check_time"/>
<field column="follower_count" name="fms_follower_count"/>
<field column="recommend_proxy_count" name="fms_recommend_proxy_count"/>
<field column="proxy_level_apply" name="fms_proxy_level_apply"/>
<field column="is_goods" name="fms_is_goods"/>
<field column="is_once" name="fms_is_once"/>
<field column="wx_ticket" name="fms_wx_ticket"/>
<field column="wx_no" name="fms_wx_no"/>
</entity>
</document>
</dataConfig>
注:
- <entity>标签中的dataSource值与<dataSource>标签中的name值对应,取名任意;
- query的值为查询语句,返回值不能是“*”,必须是具体的字段值
- 查询出的时间类型建议转换成String,方便后期进行查询,转换的格式必须是“yyyymmddhh24miss”
三、修改solrconfig.xml配置文件
该文件在..\solr-home\configsets\conf路径下,与data-config.xml同级
在<config></config>标签中添加如下代码:
<schemaFactory class="ClassicIndexSchemaFactory"/>
<requestHandler name="/dataimport" class="solr.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
修改listener标签 event="firstSearcher"的内容为:
<listener event="firstSearcher" class="solr.QuerySenderListener">
<arr name="queries">
<lst>
<str name="q">*:*</str>
</lst>
</arr>
</listener>
四、修改managed-schema配置文件
可以将多余的<field/>标签删除
主要修改<dynamicField/>标签的内容
如:(type内容必须与fieldType标签的name值对应)
<dynamicField name="fm_*" type="text_ansj" multiValued="false" indexed="true" stored="true"/>
<dynamicField name="fms_*" type="string" multiValued="false" indexed="true" stored="true"/>
<dynamicField name="fmd_*" type="date" multiValued="false" indexed="true" stored="true"/>
将原fieldType标签,name="currency"替换内容为一下代码:
<fieldType name="currency" class="solr.CurrencyField" precisionStep="8" defaultCurrency="USD" currencyConfig="currency.xml" />
注:在实际项目中进行配置的时候,solr的配置文件地址要写具体的IP,不要写localhost,否则将报错