Recently, I have prepared to use SOLR to build a project, so I have some knowledge about it. I am using solr4.4. This version of SOLR has changed a lot compared to the previous version, here, record the installation and configuration process.
Many SOLR tutorials on the Internet are very old. Many tutorials are still based on solr1.3 or 1.4, and some documents will be migrated to the cloud after being compared with the current version.
Look at the official wiki documentation: http://wiki.apache.org/solr/
SOLR Introduction
Here is an introduction to SOLR:
SOLR is a Lucene-based Java search engine server. SOLR provides hierarchical search, eye-catching hit display, and multiple output formats (including XML/XSLT and JSON ). It is easy to install and configure, and comes with an HTTP-based management interface. SOLR has been used in many large websites and is relatively mature and stable. SOLR encapsulates and extends Lucene, so SOLR basically follows the related terms of Lucene. More importantly, the index created by SOLR is fully compatible with the Lucene search engine library. By configuring SOLR appropriately, encoding may be required in some cases. SOLR can read and use indexes built into other Lucene applications. In addition, many Lucene tools (such as nutch and Luke) can also use the index created by SOLR.
Download and decompress
Http://lucene.apache.org/solr/
Download list: http://www.apache.org/dyn/closer.cgi/lucene/solr/4.4.0
Decompress the downloaded solr-4.4.0.zip package and you will see the following directory structure:
What is useful to us is the content in the example and DIST directories.
Installation and configuration
First, set SOLR. decompress the war package and copy it to Tomcat's webapps, or directly extract SOLR. copy the war package directly to Tomcat's webapps, start Tomcat to decompress it, and then delete the war package. If Tomcat is started, an error is reported because solr_home is not set (that is, the directory where the index and configuration file are located ).
Configure the following:
There are several ways to set solr_home. Baidu can do it right away. Here I use the method configured in the web. xml file of the SOLR application. Open the SOLR/WEB-INF/Web. xml file and find the following:
[HTML]View plaincopy
- <Env-entry>
- <Env-entry-Name> SOLR/home </env-entry-Name>
- <Env-entry-value> ../webapps/SOLR/solr_home </env-entry-value>
- <Env-entry-type> JAVA. Lang. String </env-entry-type>
- </Env-entry>
The content is initially commented out. After the comment is unfixed, you can change the content of the <env-entry-value> node to a location on your disk. Here, I use a relative location, the absolute position is also acceptable.
After the configuration is complete, you also need to place a folder in the configuration path as solr_home (provided in SOLR example ), copy the example/SOLR directory to the SOLR project directory (here is % tomcat_home %/webapps/SOLR/) and rename it solr_home (depending on your configuration ).
Configure log output
At this time, if Tomcat is started (by calling the startup. Sh script), it still cannot be started normally, and there are only a few lines of errors, as shown below:
[Java]View plaincopy
- 2013-8-9 15:49:05 org. Apache. Catalina. Core. standardcontext start
- Severe: Error filterstart
- 2013-8-9 15:49:05 org. Apache. Catalina. Core. standardcontext start
- Severe: context [/SOLR] startup failed due to previous errors
The error message is not clear. If we start Tomcat in another way, we will find the error output. Switch to % atat_home %/bin in the command line and run the following command:
[Java]View plaincopy
- Java-jar Bootstrap. Jar
In this way, the following exception information is output by the command line (Omitted ):
Apparently, the prompt we can not find the log-related jar package, also prompts us to see SOLR related wiki link: http://wiki.apache.org/solr/SolrLogging
On this Wiki page, we will find the following text descriptions:
The above explains what changes have been made to log output in the new SOLR version and how to solve them.
First, copy the jar package in the example/lib/EXT directory to the classpath of the project. Here, the example is obtained by extracting the SOLR compressed package. The SOLR Application WAR package is also obtained from this directory; we can put these jar packages under % atat_home %/lib, you can also put them under the project's lib (on my computer is/opt/tomcat-6.0.37/webapps/SOLR/WEB-INF/LIB );
Then, set example/resources/log4j. properties is also copied to classpath (I created a new classes directory under the/opt/tomcat-6.0.37/webapps/SOLR/directory and put log4j. properties is put in );
Then start Tomcat, and no exception is thrown. SOLR is successfully started. We access it through a browser and you will see the following picture:
Use Chinese Word Segmentation in SOLR
Chinese Word Segmentation is indispensable for full-text search. Here, mmseg4j word segmentation is used. The mmseg4j word divider has built-in support for SOLR. The latest version supports sorl of version 4.x, which is very convenient to use.
Googlecode address: http://code.google.com/p/mmseg4j/
To use the mmseg4j Chinese Word divider, you must first configure a fieldtype node in the schema. xml file (similar to other Chinese Word divider), as shown below:
[HTML]View plaincopy
- <! -- Chinese Word Segmentation -->
- <Fieldtype name = "text_zh" class = "SOLR. textfield" positionincrementgap = "100">
- <Analyzer>
- <Tokenizer class = "com. chenlb. mmseg4j. SOLR. mmsegtokenizerfactory" mode = "complex"/>
- </Analyzer>
- </Fieldtype>
Then the filedtype can be referenced in the field node. The following is a definition example of a filed node:
[HTML]View plaincopy
- <Field name = "title" type = "text_zh" indexed = "true" stored = "true" multivalued = "true"/>
- <Field name = "content" type = "text_zh" indexed = "true" stored = "false" multivalued = "true"/>
Then try the effect in the browser:
Summary
The following describes how to install and configure solr4.4.0:
- Prepare Java and tomcat;
- Download and decompress solr-4.4.4.zip to get the solr-4.4.0 directory;
- Copy the solr-4.4.0/example/webapps/SOLR. War package to the % tomcat_home %/webapps directory, start Tomcat to decompress it, delete the SOLR. War package;
- Open the % tomcat_home %/webapps/SOLR/WEB-INF/Web. xml file, configure solr_home, copy the solr-4.4.0/example/SOLR directory according to the solr_home configuration (this directory is used as solr_home );
- Copy all jar packages under solr-4.4.0/example/lib/ext to the classpath of the project, and copy the log4j. properties configuration file to classpath;
- Configure the Chinese word divider.
Installation and configuration of solr4.4