Title: Solr 7.0 Maven integration, engine building

author: Eric liu

Tags: [solr, engine, search] Categories:

  • solr
  • search

Project Background:

Recently, I used Solr to do search. I found it very interesting. I created a set of engines by myself, which is also convenient for research. Look at the web is basically manual configuration, copy jar package, no Maven integration, integration solr version is very old. So I integrated myself with Maven first. Later, some custom functionality may be added to the project. Such as custom word segmentation, custom scoring and so on.Copy the code

Solr use: This project is only an engine. As for the use of Solr, I put it in another project. The other project is mainly used to use Solr, and some custom solrUtils, pinyin, Solr conditional splicing under business scenarios, search, article feed, suggest and other specific implementation and description. Test data.

Making the address

https://github.com/Eric-ly/solr_engine
Copy the code

I. Early configuration/description

1. Download Tomcat 8 and add setenv.sh in bin to customize tomcat startup parametersexport SOLR_HOME="$CATALINA_HOME/webapps/lsearch/WEB-INF/solr_home"
    export SOLR_LOG="$CATALINA_HOME/logs/"
    export TOMCAT_USER="tomcat"
    export JAVA_OPTS="$JAVA_OPTS -Dsolr.solr.home=$SOLR_HOME -Dsolr.solr.log.dir=$SOLR_LOG -Dbootstrap_conf=true -DhostContext=lsearch"Configure solr.home and solr.log so that they do not need to be written to death in web.xml. 2. Modify classeslogSolr.log in 4j.properties so that solr can be set during Tomcat startuplogThe solr. Log =${catalina.base}/logs 3. Unlike stand-alone solr, you do not need to open the env tag in web. XML to configure Solr Home. The IK jar package is integrated in the WEB-INF lib. The IK jar package is configured in the WEB-INF lib. The IK jar package is configured in the MAVEN POM. There is no need for copy JAR packages like those in a stand-alone machine.Copy the code

Two, instructions for use

1. MVN clean install package, add the war package to the Tomcat webapps, add the setenv.sh file, and run the script in bin.

./startup.sh
http://localhost:8081/lsearch/index.html
Copy the code

2. Idea Configure the Deploy Artifact War package in Tomcat, and access the URL directly after tomcat is started.

http://localhost:8081/lsearch/index.html

Third, test data

Four, the pit encountered

1. Solr. Home requires the absolute path to be written to death, which is not flexible

-Dsolr.solr.home=$SOLR_HOME
Copy the code

2. Solr. Log. The problem of permisson

logThe solr.log directory in 4j.properties does not have a corresponding directory, so the absolute path can be written out, which is added in the tomcat startup parametersexport SOLR_LOG="$CATALINA_HOME/logs/"
	-Dsolr.solr.log.dir=$SOLR_LOG 
Copy the code

3. Test tomcat startup parameters

Run the JPS -v command to check JVM parameters. Run the tomcat bin command to set JVM parameters and run the startup.sh command to start the JVMCopy the code
  1. 404 error
Solr. log, catalina.out,localhost.xxx.log Exception starting filter SolrRequestFilter java.lang.NoClassDefFoundError: Com/codahale/metrics/MetricSet solution: lack of metrics such as jars. (2) the web in XML < security - the constraint > note off (3)Copy the code