solr的基本操作及整合springboot

2020-06-03 00:00:00 数据 字段 专区 商品 希望

一、在solr中插入数据

{

"id": 536563,

"tb_item_cid": 560,

"tb_item_cname": "手机",

"tb_item_title": "new2 - 阿尔卡特 (OT-927) 炭黑 联通3G手机 双卡双待",

"tb_item_sell_point": "清仓!仅北京,武汉仓有货!"

}


在solr中插入的数据,这些数据的字段都需要在solr中进行“注册”,被“注册”过的字段,就可以支持分词,因此这些数据就可以被查询。

1.在solr中“注册”字段

1)搜索出来以后的数据是什么样的,这样的数据才会存入到solr中

搜索出来的数据主需要有部分字段,

因此,通过设计一个专门用于存放solr中的数据的模型(javabean),来先获取这样的所有的数据,然后再存到solr里。

2)设计javabean


商品id

商品名称

商品实际售价

商品图片

商品描述


3)根据javabean中的属性设计sql语句

SELECT

a.pid as id,

a.pname as t_product_name,

a.sale_price as t_product_sale_price,

a.pimage as t_product_pimage,

b.pdesc as t_product_pdesc

FROM

t_product a

LEFT JOIN t_product_desc b

ON a.pid = b.`pid`


4)在solr中注册字段


编辑ik配置文件: managed_schema

<field name="t_product_name" type="text_ik" indexed="true" stored="true"/>

<field name="t_product_sale_price" type="pfloat" indexed="true" stored="true"/>

<field name="t_product_pimage" type="text_general" indexed="true" stored="true"/>

<field name="t_product_pdesc" type="text_ik" indexed="true" stored="true"/>

让配置文件在容器中生效

# 复制到容器

docker cp managed-schema solr:/opt/solr/server/solr/ik_core/conf


# 重启容器

docker-compose restart



5)在solr的浏览器客户端中插入数据



6)查询数据



7)删除数据

根据查询结果删除




根据id来删除








二、在springboot中使用solr实现增删改查

1.添加依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>

yml:

spring:

  data:

    solr:

      host: http://192.168.2.143:8983/solr/ik_core

相关文章