SOLR is integrated from server configuration to Project Practice

Source: Internet
Author: User
Tags solr

After integrating online resources, you can use the following 100% operation steps to deploy them in Tomcat.

I. Download SOLR version 5.2.1

Address: http://pan.baidu.com/s/1eRAdk3o

Decompress the package.

1. In the decompressed folder path:/Server/webapps/SOLR. War

2. Put it in the webapps folder of Tomcat (download it on the official Tomcat website)

3. Run bin/startup. bat,

Http: // localhost: 8080/SOLR is accessible. OK.

Ii. Configure SOLR

1. Enter the project path under Tomcat: webapps/SOLR/WEB-INF/Web. xml

Edit and modify, about 40 rows

2. Cancel the annotation, enter the location of the configuration to be stored, and create a folder accordingly.

 

3. Open the unzipped Folder:/Server/SOLR. Copy all the files in the folder to the folder we created.

 

 

4. Copy all jar packages in the/Server/lib/EXT folder to Tomcat:/webapps/SOLR/WEB-INF/lib

 

 

5. Unzip the folder/Server/resources/log4j. properties to copy to Tomcat:/webapps/SOLR/WEB-INF

6. Unzip the folder/Dist/solr-dataimporthandler-5.2.1.jar to copy to Tomcat:/webapps/SOLR/WEB-INF/lib

Configuration complete. Start http: // localhost: 8080/SOLR


3. Configure Core

Keep project started

1. Extract the/example-dihsolr dB folder in the folder and copy it to the solr_home folder we created.

 

2. Add a core to the control panel. Click core admin.

Change name and instancedir to the folder name. Then add Core

Configuration complete!

4. Create a project to call the test.

1. Create a Maven Project

Pom. xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelVersion>4.0.0</modelVersion>    <groupId>com.masz.solr</groupId>    <artifactId>solrj</artifactId>    <version>0.0.1-SNAPSHOT</version>    <dependencies>        <dependency>            <groupId>org.apache.solr</groupId>            <artifactId>solr-solrj</artifactId>            <version>5.0.0</version>        </dependency>        <dependency>            <groupId>org.slf4j</groupId>            <artifactId>slf4j-simple</artifactId>            <version>1.5.6</version>        </dependency>        <dependency>            <groupId>javax.servlet</groupId>            <artifactId>servlet-api</artifactId>            <version>2.5</version>        </dependency>        <dependency>            <groupId>log4j</groupId>            <artifactId>log4j</artifactId>            <version>1.2.16</version>        </dependency>        <dependency>            <groupId>commons-logging</groupId>            <artifactId>commons-logging</artifactId>            <version>1.2</version>        </dependency>        <dependency>            <groupId>junit</groupId>            <artifactId>junit</artifactId>            <version>4.9</version>            <scope>compile</scope>        </dependency>    </dependencies></project>

2. Test code

Solrtest. Java

Import Java. io. ioexception; import Org. apache. SOLR. client. solrj. solrquery; import Org. apache. SOLR. client. solrj. solrserverexception; import Org. apache. SOLR. client. solrj. impl. httpsolrclient; import Org. apache. SOLR. client. solrj. response. queryresponse; import Org. apache. SOLR. client. solrj. response. updateresponse; import Org. apache. SOLR. common. solrdocument; import Org. apache. SOLR. common. solrdocumentlist; import Org. apache. SOLR. common. solrinputdocument; import Org. JUnit. before; import Org. JUnit. test; public class solrtest {Private Static final string url = "http: // 127.0.0.1: 8080/SOLR/DB"; private httpsolrclient Server = NULL; @ before public void Init () {// create server Server = new httpsolrclient (URL) ;}@ test public void adddoc () {solrinputdocument Doc = new solrinputdocument (); Doc. addfield ("ID", "this is ID"); Doc. addfield ("title", "this is document"); try {updateresponse response = server. add (DOC); // submit server. commit (); system. out. println ("######### query time:" + response. getqtime (); system. out. println ("######### elapsed time:" + response. getelapsedtime (); system. out. println ("######### status:" + response. getstatus ();} catch (solrserverexception | ioexception e) {system. err. print (e) ;}/ *** query */@ test public void testquery () {string querystr = "*: *"; solrquery Params = new solrquery (querystr ); params. set ("rows", 10); try {queryresponse response = NULL; response = server. query (Params); solrdocumentlist list = response. getresults (); system. out. println ("########## Total:" + list. getnumfound () + "record"); For (solrdocument DOC: List) {system. out. println ("######## ID:" + Doc. get ("ID") + "title:" + Doc. get ("title") ;}} catch (solrserverexception e) {system. err. print (e );}}}

A simple test code is provided as an example. For more information, see the official website or Baidu.

 

 

SOLR is integrated from server configuration to Project Practice

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.