solr6.x Deployment in TOMCAT8 (entry level)
The company's recent projects want to introduce full text indexing function, the recommendation of solr, so I searched the internet myself some information, found that a lot of blog write a variety of, mixed, and trampled a lot of pits = =. So I want to write a SOLR under Tomcat deployment of the article, in order to be able to provide help to users. "This article only describes stand-alone Tomcat deployments"
solr6.x Deployment in TOMCAT8 (entry level) 1. The popular point is that SOLR 2. How to deploy 3 under Tomcat. SOLR Simple Operation Introduction
1. Popular point to say SOLRSOLR is a full-text search server based on the Apache Lucene, which can be accessed via HTTP or WebService. SOLR can configure a database connection that can be used to obtain data for a specified field in a specified database table and generate a Full-text index based on the SOLR-related configuration file. For invocation that is to say, use aspect, SOLR resembles Redis, provide service for our own application, only need to configure it, launch it, call itsolr-6.x and solr-5.x are somewhat different, this article only applies to solr-6.x 2. How to deploy under TomcatDownload solr-6.5.1:solr–6.5.1 download Tomcat-8.5.27:tomcat All versions download, you can choose a new folder according to the URL, named:solr-tomcat-8.5.27"Custom can" the above two downloaded files, copy in, respectively decompression under solr-tomcat-8.5.27 new folder: Solr-home will Solr-tomcat-8.5.27\solr-6.5.1\server\ The readme.txt,solr.xml,zoo.cfg three files under Solr are copied to solr-home under the Solr-tomcat-8.5.27\apache-tomcat-8.5.27\webapps directory, Create a new empty folder: SOLR; Copy all files under Solr-tomcat8\solr-6.5.1\server\solr-webapp\webapp to the newly created SOLR folder in Solr-tomcat-8.5.27\ Apache-tomcat-8.5.27\webapps\solr\web-inf folder, create a new folder: classes, will solr-tomcat8\solr-6.5.1\server\resources\ Log4j.properties copies the following Jar packs to Solr-tomcat8\apache-tomcat-8.5.27\webapps\solr\web-inf\lib under the just classes:
Solr-tomcat-8.5.27\solr-6.5.1\server\lib\ext\: "5 jars: All under solr-tomcat-8.5.27\solr-6.5.1\dist\:" 2 Jar:solr-dataimporthandler-6.5.1.jar,solr-dataimporthandler-extras-6.5.1.jar "solr-tomcat-8.5.27\solr-6.5.1\ Server\lib\: "5 jars: Jar with metrics" connect a jar:maven of MySQL repository download a jar of Chinese participle: Other people upload resources: Ikanalyzer6.5.0.jar download Modify Solr-tomcat8\apache-tomcat-8.5.27\webapps\solr\web-inf\web.xml:
Before <filter></filter> tag, add: "The absolute path where Env-entry-value is Solr-home"
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>G:\tomcat\solr-tomcat8\solr-home</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
"If you do not do this, you will get an error without a Jndi connection" comment out the last <security-constraint></security-constraint>
"If you do not do this step browser access will error 403" Access http://localhost:8080/solr/index.html, you can see the SOLR Control Panel, indicating that the configuration was successful3. Solr Simple Operation IntroductionNew Core
In the Solr-home directory, create a new folder article "name arbitrary" will solr-tomcat8\solr-6.5.1\server\solr\configsets\basic_configs\ the following Conf folder, Copy to solr-tomcat8\solr-home\article in the browser in the SOLR console, new core, as shown below: You will see the new success, must be in order to
Configure core to create a new file in solr-tomcat8\solr-home\article\conf: Data-config.xml, paste the following configuration in:
<?xml version= "1.0" encoding= "UTF-8"?> <dataConfig> <datasource type= " Jdbcdatasource "driver=" Com.mysql.jdbc.Driver "url=" Jdbc:mysql://127.0.0.1:3306/hxyframe "user=" root "password=" Root "batchsize="-1 "/> <document> <entity name=" solr_article "query=" select Id,title,author,img,content, Create_time,update_time from Solr_article "> <field column=" id "name=" id "/> <field" column= Le "name=" title "/> <field column=" img "name=" img "/> <field column=" Author "name=" author "/&G
T <field column= "Content" name= "content"/> <field column= "create_time" name= "Createtime"/> ; field column= "Update_time" name= "UpdateTime"/> </entity> </document> </dataConfig>
"Description:" The URL property in DataSource does not support adding? useunicode=true&characterencoding=utf-8&autoreconnect=true;entity Name is your database table name, and query is the range of data you want to index, colnum in field is the name of the database table field, name is field name in the Managed-schema file, and "This XML file cannot have Chinese annotations, remember" Modify the Solrconfig.xml file in the same directory and add the following code before the final </config>
Xml
<!--introducing the jar--> of Dataimporthandler class
<lib dir= ". /.. /.. /solr-6.5.1/dist/"regex=" Solr-dataimporthandler-.*\.jar "/>
<requesthandler name= "/dataimport" class= "Org.apache.solr.handler.dataimport.DataImportHandler" >
<lst name= "Defaults" >
<str name= "config" >data-config.xml</str>
</lst>
</requestHandler>
Modify the Managed-schema file in the same directory and add the following code
<fieldtype name= "Text_ik" class= "SOLR." TextField "> <analyzer type=" index "class=" Org.wltea.analyzer.lucene.IKAnalyzer "/> <analyzer" q Uery "class=" Org.wltea.analyzer.lucene.IKAnalyzer "/> </fieldType> <field name=" type "type=" string " Indexed= "true" stored= "true"/> <field name= "img" type= "string" indexed= "true" stored= "true"/> <field "title" Type= "Text_ik" multivalued= "false" indexed= "true" stored= "true"/> <field name= "Author" type= "Text_ik" Multivalued= "false" indexed= "true" stored= "true"/> <field name= "content" type= "Text_ik" indexed= "true" stored= " True "/> <field name= createtime" type= "Tdate" indexed= "true" stored= "true"/> <field name= "UpdateTime" type = "Tdate" indexed= "true" stored= "true"/> <field name= "KeyWord" type= "Text_ik" multivalued= "true" indexed= "true" Stored= "true"/> <copyfield source= "title" dest= "KeyWord"/> <copyfield "source=" author "dest="/ > <copyfield source="Content" dest= "KeyWord"/>
Description: "Copyfield can be used to make a combined index, in an example, to build Title,content,author into a composite index keyword, which means that when you use a keyword query, you find matching data from the 3 fields above The data in the configured data source is generated, and the Full-text index is created
manipulate the following figure: SOLR query
operates as follows: