2、将jdbc驱动和solr安装包中的两个jar放到my_solr指定目录下 | docker cp mysql-connector-java-5.1.10-bin.jar my_solr:/opt/solr-8.5.2/server/solr-webapp/webapp/WEB-INF/lib/ docker cp solr-dataimporthandler-8.5.2.jar my_solr:/opt/solr-8.5.2/server/solr-webapp/webapp/WEB-INF/lib/ docker cp solr-dataimporthandler-extras-8.5.2.jar my_solr:/opt/solr-8.5.2/server/solr-webapp/webapp/WEB-INF/lib/ |
6、data-config.xml 文件,写入如下配置内容,最下边即可 | <dataConfig>
<!--dataSource标签配置数据库相关的信息-->
<dataSource name = "ds_1" type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mytest?characterEncoding=UTF-8"
user="root" password="111111"/>
<document>
<!-- pk属性指定的是manage-schema文件中的uniqueKey标签中的值,即主键 -->
<!-- query获取全部数据的SQL -->
<!-- deltaImportQuery获取增量数据时使用的SQL -->
<!-- deltaQuery获取pk的SQL -->
<!-- parentDeltaQuery是获取父Entity的pk的SQL -->
<!-- 商品表字段以及关联表字段配置 -->
<entity name="goods" dataSource="ds_1" PK="id"
query="SELECT
g.id AS id,
g.`NAME` AS `name`,
g.lesson_length AS lesson_length,
gp.imgUrl AS imgUrl,
g.goods_introduce,
g.org_id,
g.goods_ways,
g.video_length,
g.playway,
g.goods_type_id,
price.price
FROM
goods g
LEFT JOIN goods_picture gp ON g.id = gp.goods_id
LEFT JOIN goods_price price on g.id=price.goods_id
WHERE
g.`status` = 3
AND g.is_display =2">
<!--以下的字段column属性对应数据库中字段名称,name是对应solr这边配置的名称,注意id,默认名称即为id,表示solr这边一条数据的主键,以下三个是要在solr这边中建立索引的字段,比如数据库中有10个字段,我只需要为3个字段建立索引关系,那这里就写3个就好了
如果数据库中的主键不是id,比如是objectId,那上边的query需要为它起一个别名为id即可-->
<field column="id" name="id" />
<!-- 商品名称 -->
<field column="name" name="name" />
<!-- 课时时长 -->
<field column="lesson_length" name="lesson_length" />
<!-- 商品图片 -->
<field column="imgUrl" name="imgUrl" />
<!-- 商品介绍 -->
<field column="goods_introduce" name="goods_introduce" />
<!-- 机构ID -->
<field column="org_id" name="org_id" />
<!-- 商品形式 -->
<field column="goods_ways" name="goods_ways" />
<!-- 商品中的视频总时长 -->
<field column="video_length" name="video_length" />
<!-- 课件形式 -->
<field column="playway" name="playway" />
<!-- 培训项目ID -->
<field column="goods_type_id" name="goods_type_id" />
<!-- 山坡滚价格 -->
<field column="price" name="price" />
<!-- 限时优惠列表 -->
<entity name="discountPrice" query="select discount_price,stime,etime from goods_discount where goods_id = ${goods.id} and device = 1 and `status` = 1 and etime > now() order by stime asc">
<!-- 优惠价 -->
<field name="discount_price" column="discount_price" />
<!-- 限时优惠开始时间 -->
<field name="stime" column="stime" dateTimeFormat="yyyy-MM-dd HH:mm:ss" />
<!-- 显示优惠结束时间 -->
<field name="etime" column="etime" dateTimeFormat="yyyy-MM-dd HH:mm:ss" />
</entity>
<!-- 小节数/时长列表 -->
<entity name="xiaoJieCount" query="select count(1) xiaoJieCount,date_format(date_sub(from_unixtime(SUM(IFNULL(g.attachmenttime,0))), INTERVAL 8 HOUR), '%H:%i:%s') time from
`dpt_e-commerce`.goods_product gp
LEFT JOIN dpt_product.db_product p on lpad(gp.PRODUCTID,12,0)=SUBSTR(p.childIndex FROM 1 FOR 12) AND p.typeId=2
LEFT JOIN dpt_product.courseknowledge e on p.referenceId=e.courseid and e.delflag=0
LEFT JOIN dpt_product.knowledge f on e.knowid=f.knowid
LEFT JOIN dpt_resource.resource g on f.courseresourceid=g.id
where gp.goodsid =${goods.id}">
<!-- 小节 -->
<field name="xiaoJieCounts" column="xiaoJieCounts" />
<!-- 时长 -->
<field name="time" column="time" />
</entity>
<!-- 购买人数 -->
<entity name="buycount" query="select (buycount+buyCountFake) buycount from goods_useroperaterecord where goodsid=${goods.id}">
<field name="buycounts" column="buycounts" />
</entity>
</entity>
</document>
</dataConfig> |
8、再找到同目录下的managed-schema 文件并打开,在里边加入如下内容,需要索引的字段相关配置 | <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> <field name="name" type="text_ik" indexed="true" stored="true"/> <field name="lesson_length" type="pint" indexed="false" stored="true"/> <field name="imgUrl" type="string" indexed="false" stored="true"/> <field name="org_id" type="pint" indexed="true" stored="true"/> <field name="goods_ways" type="pint" indexed="true" stored="true"/> <field name="video_length" type="pint" indexed="false" stored="true"/> <field name="playway" type="pint" indexed="true" stored="true"/> <field name="type" type="pint" indexed="true" stored="true"/> <field name="price" type="pdouble" indexed="false" stored="true"/> <field name="discount_price" type="pdoubles" indexed="false" stored="true" multiValued="true"/> <field name="stime" type="pdates" indexed="false" stored="true" multiValued="true"/> <field name="etime" type="pdates" indexed="false" stored="true" multiValued="true"/> <field name="xiaoJieCounts" type="pint" indexed="false" stored="true"/> <field name="time" type="string" indexed="false" stored="true"/> <field name="buycounts" type="pint" indexed="false" stored="true"/> |