Setting Up Apache Solr with IK Analyzer on Linux
Apache Solr is a powerful, open-source search platform built on Apache Lucene. The following guide outlines the manual deployment process for Solr 4.10.3 on a Linux server and the integration of the IK Analyzer for Chinese language support.
1. Environment Preparation
Ensure you have Java JDK installed. You will need the Apache Tomcat server and the Solr distribution package. First, prepare the deployment directory:
# Extract Tomcat and create the workspace directory
tar -zxf apache-tomcat-7.0.47.tar.gz
mkdir -p /opt/search_engine/solr
cp -r apache-tomcat-7.0.47 /opt/search_engine/solr/container
2. Deploying the Solr Application
After extracting the Solr package, deploy the war file to Tomcat and initialize the home directory:
# Copy the war file to webapps
cp solr-4.10.3.war /opt/search_engine/solr/container/webapps/solr.war
# Start Tomcat to trigger auto-extraction, then stop and remove the original war file
/opt/search_engine/solr/container/bin/startup.sh
# (Wait for extraction)
/opt/search_engine/solr/container/bin/shutdown.sh
rm /opt/search_engine/solr/container/webapps/solr.war
# Copy required logging/dependency libraries
cp solr-4.10.3/example/lib/ext/* /opt/search_engine/solr/container/webapps/solr/WEB-INF/lib/
# Set up the Solr Home directory
cp -r solr-4.10.3/example/solr /opt/search_engine/solr/home
Edit the /opt/search_engine/solr/container/webapps/solr/WEB-INF/web.xml file to point the solr/home JNDI entry to your new /opt/search_engine/solr/home directory.
3. Integrating IK Analyzer
To enable Chinese text analysis, include the IK Analyzer library and its configuration filles within the application context:
# Install dependencies
cp IKAnalyzer.jar /opt/search_engine/solr/container/webapps/solr/WEB-INF/lib/
# Deploy dictionaries and configuration
cp IKAnalyzer.cfg.xml stopword.dic main.dic /opt/search_engine/solr/container/webapps/solr/WEB-INF/classes/
4. Schema Configuration
Modify /opt/search_engine/solr/home/collection1/conf/schema.xml to define your business fields and integrate the IK Analyzer type:
<fieldType name="text_ik" class="solr.TextField">
<analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>
</fieldType>
<field name="user_title" type="text_ik" indexed="true" stored="true"/>
<field name="user_bio" type="text_ik" indexed="true" stored="true"/>
<field name="search_aggregate" type="text_ik" indexed="true" stored="false" multiValued="true"/>
<copyField source="user_title" dest="search_aggregate"/>
<copyField source="user_bio" dest="search_aggregate"/>
Restart the Tomcat server to apply all configurations and initialize the index core.