Fading Coder

One Final Commit for the Last Sprint

Home > Notes > Content

Setting Up Apache Solr with IK Analyzer on Linux

Notes Nov 1 1

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.

Related Articles

Designing Alertmanager Templates for Prometheus Notifications

How to craft Alertmanager templates to format alert messages, improving clarity and presentation. Alertmanager uses Go’s text/template engine with additional helper functions. Alerting rules referenc...

Deploying a Maven Web Application to Tomcat 9 Using the Tomcat Manager

Tomcat 9 does not provide a dedicated Maven plugin. The Tomcat Manager interface, however, is backward-compatible, so the Tomcat 7 Maven Plugin can be used to deploy to Tomcat 9. This guide shows two...

Skipping Errors in MySQL Asynchronous Replication

When a replica halts because the SQL thread encounters an error, you can resume replication by skipping the problematic event(s). Two common approaches are available. Methods to Skip Errors 1) Skip a...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.