solr (1): introduction and configuration

I. Brief Introduction

1.1. What is solr?

Solr is a top-level open source project under Apache, developed in Java, and is a full-text search server based on Lucene. Solr provides a richer query language than Lucene, implements configurability and scalability, and optimizes index and search performance.

Solr is a full-text retrieval server, which only needs configuration to realize full-text retrieval service.

II. Configuration

1. In solr, the default is Chinese parser, which needs to be manually configured. Configure a FieldType to specify a Chinese parser in FieldType.

2. Fields in Solr must be defined before they are used.

2.1. Configure Chinese parser

1. Use IK-Analyzer. Upload the analyzer folder to the server.

  

2. Add the jar package of the analyzer to the solr project

[root@localhost IK Analyzer 2012FF_hf1]# cp IKAnalyzer2012FF_u1.jar /opt/tomcat/webapps/solr/WEB-INF/lib

3. You need to copy the extended dictionary and stop-word dictionary and configuration files needed by IKAnalyr to the classpath of the solr project

[root@localhost WEB-INF]# cd /opt/tomcat/webapps/solr/WEB-INF/
[root@localhost WEB-INF]# mkdir classes
[root@localhost WEB-INF]# cd /opt/tar/IK\ Analyzer\ 2012FF_hf1/
[root@localhost IK Analyzer 2012FF_hf1]# cp IKAnalyzer.cfg.xml ext_stopword.dic mydict.dic /opt/tomcat/webapps/solr/WEB-INF/classes/
[root@localhost IK Analyzer 2012FF_hf1]#

Note: The character set of the extended dictionary and the stop word dictionary must be utf-8. windows Notepad Editor cannot be used.

4. Configure fieldType. You need to configure it in solrhome/collection1/conf/schema.xml

[root@localhost IK Analyzer 2012FF_hf1]# vi /opt/solr/solrhome/collection1/conf/schema.xml

At the end, add the following:

<fieldType name="text_ik" class="solr.TextField">
    <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>
</fieldType>

2.2. Configuration field

Business field criteria:

 1. Do you need to search on this field when searching? For example: the name of the commodity, the selling point of the commodity, the description of the commodity.

 2. Need this field be used for subsequent business? For example: commodity id.

For example: commodity id, commodity title, selling point, price, commodity picture, commodity classification name, commodity description

Business fields in Solr:

1. ID --"commodity id, other fields and corresponding fields refer to this.

[root@localhost IK Analyzer 2012FF_hf1]# vi /opt/solr/solrhome/collection1/conf/schema.xml

At the end, add the following:

<field name="item_title" type="text_ik" indexed="true" stored="true"/>
<field name="item_sell_point" type="text_ik" indexed="true" stored="true"/>
<field name="item_price"  type="long" indexed="true" stored="true"/>
<field name="item_image" type="string" indexed="false" stored="true" />
<field name="item_category_name" type="string" indexed="true" stored="true" />
<field name="item_desc" type="text_ik" indexed="true" stored="false" />
<field name="item_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/>
<copyField source="item_title" dest="item_keywords"/>
<copyField source="item_sell_point" dest="item_keywords"/>
<copyField source="item_category_name" dest="item_keywords"/>
<copyField source="item_desc" dest="item_keywords"/>

2. Restart tomcat

Test whether the participle is easy to use:

Testing business fields is useful:

1. Adding test data

  

2. Query

Query conditions:

 Check all: *:*

 According to the specified field (field), check: field name: field value, such as item_title: test

The returned domain:

 Back to All: Default

 Return to the specified: domain name, separated by commas, such as: id,item_price

Default search fields:

 If the field name is written when searching according to the specified field, but only the field value is written, then the search will not be possible. If the default search field is given, then the search can be done.

Highlight:

 hl.fl: Highlighted Domain

 hl.simple.pre: Start tag

 hl.simple.post: End tag

2.3. Maintaining Index Library

Add: Add a file in json format, refer to the above

Modification: Adding a new document requires that the document id be the same as that of the modified document (the principle is delete before add)

Delete: There are two ways to use xml format

 1. Delete according to id:

  

 2. Delete according to query

  


Keywords: Java solr Tomcat xml Apache

Added by apitto on Wed, 26 Jun 2019 03:19:54 +0300