One: What is Solr?

Solr is a high-performance, Java-based full-text search server based on Lucene. At the same time, it has been extended to provide a richer query language than Lucene, at the same time to achieve configurable, extensible and query performance optimization, and provides a perfect function management interface, is a very good full-text search engine.
Solr features: Solr is a high-performance, Java5 based Lucene full-text search server. At the same time, it has been extended to provide a richer query language than Lucene, at the same time to achieve configurable, extensible and query performance optimization, and provides a perfect function management interface, is a very good full-text search engine.
Documents are added to a search collection using XML over Http. Querying this collection is also done by receiving an XML/JSON response over HTTP. Its key features include efficient and flexible caching, vertical search, highlighting of search results, improved availability through index replication, a powerful Data Schema to define fields, types, and text analysis, and a Web-based management interface.

Two: Solr environment construction

1: Solr is Java development, need to install JDK, due to the production environment JDK version 7 reason, so use SolR5, it is recommended that the JDK version allows the higher version of Solr, such as 6 to 5, Solr has hundreds of optimizations, solR6 and above need JDK8. Version 5.5 is the highest version I can choose for JDK7. Solr’s installation has changed a lot since version 5, and jetty has been built in, so it’s basically install-free, just a few commands to remember
2: Download and decompress the version, go to solR-5.5.0, and start Solr
CD/Users/apple/Desktop/solr - 5.5.0 open solr command bin/solr start closing solr command: bin/solr stopCopy the code
If the following message is displayed, the SolR server is successfully installed. The default listening port number is 8983:
When you see the Solr Web management interface, the installation is successful

Three: Create a core administrator

1: Create an administrator

Solr specifies two directories for the core before it is created:
Mkdir server/solr/core name mkdir server/solr/core name /conf mkdir server/solr/core name /data cp -r server/solr/configsets/basic_configs/conf server/solr/new_coreCopy the code
3: the solrconfig. XML configuration must be included in the conf directory, where some default configurations are directly assigned. Click new again on the interface to succeed

4: common Solr command
Start command: bin/solr start[-p port number] Do not specify the default listening port 8983; Restart command: bin/solr restart Stop command: bin/solr stop [-p port number], bin/solr stop [-all] olr restart 'Stop command: Bin /solr stop [-p port number], bin/solr stop [-all] Check the status: bin/solr statusCopy the code
5: Let’s configure the Chinese word segmentation index
In the picture below we can see that when we type some Random Chinese words, it does not put one word together, but separately.
Download analyzer

6: Copy the two JAR packages to this path
/ Users/apple/Desktop/solr - 5.5.0 / server/solr webapp/webapp/WEB - INF/libCopy the code
7: Copy the other three configuration files to this path
/ Users/apple/Desktop/solr - 5.5.0 / server/solr webapp \ webapp \ WEB - INF \. Create a new classes folder if you don't have one.Copy the code
8: Add the following information to the new_core/conf/managed-schema TAB
<fieldType name="text_ik" class="solr.TextField">
  <analyzer type="index">
	  <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false" conf="ik.conf"/>
	  <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
	  <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true" conf="ik.conf"/>
	  <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>
Copy the code
If you restart Solr, you will find a new type: text_ik, select text_IK, search again and you will find a new word, not the same as before

4. Import index data (MySQL database as an example)

1: Create the my-data-config. XML file in the directory
/ Users/apple/Desktop/solr - 5.5.0 / server/solr/new_core/confCopy the code
2: Use solr to add the index field corresponding to the database field. After adding the index field, open the managed-schema file
<field name="imgUrl" type="string" indexed="true" stored="true"/>
<field name="title" type="string" indexed="true" stored="true"/>
Copy the code

3: Open the file in the directory:
/ Users/apple/Desktop/solr - 5.5.0 / server/solr/new_core/conf \ solrconfig XMLCopy the code
4: Add the following configuration to any node of the same level as requestHandler
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
	<lst name="defaults">
		<str name="config">my-data-config.xml</str>
	</lst>
</requestHandler>
Copy the code
Will/Users/apple/Desktop/solr - 5.5.0 / dist directory solr - dataimporthandler - 7.5.0. Jar, solr - dataimporthandler - 5.5.0. Jar, Solr - dataimporthandler - extras - 5.5.0 jar, Mysql-connector-java-8.0.11.jar (mysql-connector-java-8.0.11.jar) Copy the solr_home \ server \ solr webapp \ webapp \ WEB - INF \ lib (/ Users/apple/Desktop/solr - 5.5.0 / server/solr webapp/webapp/WEB - INF/lib ) directory. Restart the Solr serviceCopy the code

5: Above configuration files

Five: Start importing data

1: After configuring the previous information, you can import data in the background. The configuration information needs to be reloaded to take effect. If there is an error in the configuration file, an error message will be displayed during reload

2: After reload, import begins

3: The import is successful

That’s the basic setup for Solr.