Insert data into SOLr
{ “id”: 536563, “tb_item_cid”: 560, “Tb_item_cname “:” phone “, “Tb_item_title “:” NEW2 – Alcatel (OT-927) Carbon Black Unicom 3G Mobile Phone Dual card dual waiting “, “Tb_item_sell_point “:” Clearance! Only Beijing, Wuhan warehouse goods!” } |
Data inserted in Solr, the fields of the data need to be “registered” in SolR, the “registered” fields can support word segmentation, so the data can be queried.
1. Register in SOLR
1) What is the data after the search, so that such data can be stored in SOLR
The data that comes out of the search needs to have partial fields,
Therefore, by designing a model (Javabean) specifically for storing the data in SOLR, all such data is first captured and then stored in SolR.
2) Design javabeans
Product id
Name of commodity
Actual selling price
Commodity images
Commodity description
3) Design SQL statements according to properties in Javabean
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) Register fields in SOLr
Edit the IK configuration file: 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”/>
Make the configuration file valid in the container
Copy to container
docker cp managed-schema solr:/opt/solr/server/solr/ik_core/conf
# restart container
docker-compose restart
5) Insert data into solr’s browser client
6) Query data
7) Delete data
Delete it based on the query result
Delete by ID
Two, in springboot using solR to achieve add, delete, change and check
1. Add dependencies
<dependency> |
yml:
Spring: data: solr: host: http://192.168.2.143:8983/solr/ik_coreCopy the code
2. Write a javabean
3. Insert data into solr
|
4. Query data in SOLr
1) Ordinary query and encapsulation
|
2) Query and encapsulation with highlighting
|