Lucene JDK for Linux Configuration

Source: Internet
Author: User
ArticleDirectory
    • Configure and apply Lucene 2.9.1 in Red Hat Linux 9
Configure and apply Lucene 2.9.1 in Red Hat Linux 9   Label: Linux Lucene

Configure and apply Lucene 2.9.1 in Red Hat Linux 9

 

1. Environment Introduction. 1

2. Configuration prerequisites. 1

2.1 install JDK 1.6 1

3 configure Lucene 2

3.1 install ant (optional) 2

3.2 install javacc (optional) 2

3.3 unzip and install Lucene 2

3.3 build Lucene (optional) 3

3.4 configure Lucene environment variables. 3

4 test Lucene 4

 

1. Environment Introduction

Operating System: Red Hat Linux 9.0

Lucene version: lucene-2.9.1 download http://apache.etoak.com/lucene/java/

2. Configure prerequisite 2.1 to install JDK 1.6

Step 1: # chmod + x jdk-1_6_0_13-linux-i586-rpm.bin (this command is used to get execution permissions)

Step 2: #./jdk-1_6_0_13-linux-i586-rpm.bin (used to generate the RPM installation package)

Step 3: # rpm-IVH jdk-1_6_0_13-linux-i586.Rpm (this command is used to install JDK)

After installation,Install JDK in the/usr/Java/directory. (This directory will be created during installation)

Last step: configure the JDK environment variables.

1): # vi/etc/profile. d/Java. Sh (this file is opened in the VI editor)

2): Enter the content in Java. Sh.

# Set Java environment

Export java_home =/usr/Java/jdk1.6.0 _ 13

Export classpath =.: $ java_home/lib: $ java_home/JRE/lib

Export Path = $ java_home/bin: $ java_home/JRE/bin: $ path

3): # chmod + x/etc/profile. d/Java. Sh

In this case, the configuration is complete.

We recommend that you set environment variables in/etc/profile.

[Root @ red-hat-9 root] # vi/etc/profile

Add the following statement:

Java_home =/usr/Java/jdk1.6.0 _ 13

Export java_home

Classpath =.: $ java_home/lib: $ java_home/JRE/lib (note the colon)

Export classpath

Path = $ java_home/bin: $ java_home/JRE/bin: $ path

[Root @ red-hat-9 root] # chmod + x/etc/profile (Execution permission)

[Root @ red-hat-9 root] # source/etc/profile (effective later)

3. Configure javase3.1 to install ant (optional)

(1) download APACHE-ant-1.7.1 to a directory (for example,/root ),

Http://apache.etoak.com/ant/binaries/apache-ant-1.7.1-bin.tar.gz

(2) unzip the package to a directory (/zkl/programe)

[Root @ red-hat-9 root] # tar zxvf apache-ant-1.7.1-bin.tar.gz

[Root @ red-hat-9 root] # mv APACHE-ant-1.7.1/zkl/programe

(3) set ant Environment Variables

[Root @ red-hat-9 root] # vi/etc/profile

Add the following statement

Ant_home =/zkl/Program/Apache-ant-1.7.1

Export ant_home

Path = $ path: $ ant_home/bin

[Root @ red-hat-9 root] # source/etc/profile (effective later)

3.2 install javacc (optional)

(1) download javacc-5.0 (javacc official website is https://javacc.dev.java.net /)

Https://javacc.dev.java.net/files/documents/17/138911/javacc-5.0.tar.gz

(2) unzip the package to a directory/zkl/Program

[Root @ red-hat-9 root] # gunzip javacc-5.0.tar.gz

[Root @ red-hat-9 root] # tar-xvf javacc-5.0.tar

[Root @ red-hat-9 root] # mv javacc-5.0/zkl/Program

3.3 unzip and install Lucene

(1) download lucene-2.9.1

Http://apache.etoak.com/lucene/java/lucene-2.9.1.tar.gz

(2) decompress the package to a directory/zkl/IR/Lucene

[Root @ red-hat-9 root] # tar xf lucene-2.9.1.tar.gz
[Root @ red-hat-9root] # mv lucene-2.9.1/zkl/IR/Lucene

(3) After completion, Lucene's main directory is/zkl/IR/Lucene/lucene-2.9.1

3.3 build Lucene (optional)

This step is not required, because the downloaded Lucene has actually been built.
(1) another user's main directory ~ /To generate the build. properties file and write it to the javacc main directory.

[Root @ red-hat-9 root] # cd/zkl/IR/Lucene/lucene-2.9.1
[Root @ red-hat-9 lucene-2.9.1] #

Echo "javacc. Home =/zkl/Program/javacc-5.0"> ~ /Build. Properties

(2) Run ant to build
[Root @ red-hat-9 lucene-2.9.1] #/zkl/Program/Apache-ant-1.7.1/bin/ant

Buildfile: Build. xml

Jar. Core-check:

Compile-demo:

Build successful (built successfully)

Total time: 0 seconds

3.4 configure Lucene Environment Variables

[Root @ red-hat-9 root] # vi/etc/profile

Add the following statement

Export e_home =/zkl/IR/Lucene/lucene-2.9.1

Classpath =.: $ java_home/lib: $ java_home/JRE/lib: $ e_e_home/lucene-core-2.9.1.jar: $ lucene_home/lucene-demos-2.9.1.jar

(Note: Colon)

[Root @ red-hat-9 root] # source/etc/profile (effective later)

The Environment Changes in/etc/profileare as follows (see profile.txt ):

4. Test Lucene

(1) Use indexfiles in src/demo to create an index and use searchfiles to search

After this example is run, the Directory Index that stores the created index will be created under the/zkl/IR/Lucene/lucene-2.9.1/src/demo directory, and the index will be deleted first when re-running. Searchfiles searches for files based on the created index stored in the demo/index. Enter the keyword.

① First, I create a/zkl/IR/index_files directory to store the files that need to be indexed. I create some files under the directory;

② Then I call the demo example, first enter the demo directory, and then execute the following command

Java ORG/Apache/Lucene/demo/indexfiles/zkl/IR/index_files/

This indexes the files in the/zkl/IR/index_files/directory and stores them in demo/index;

Run the following command to search for files:

Java ORG/Apache/Lucene/demo/searchfiles

③ If the two commands are allowed to receive an exception prompt, it indicates that the Lucene environment variable has a problem. If an exception occurs, it indicates that the Java environment variable is OK,

When executing commands, note that Java ORG/Apache/Lucene/demo/searchfiles

Here is searchfiles, rather than searchfiles. java.

When you enter the org/Apache/Lucene/demo/directory, you will find that the directory contains only a few. java files, they do not compile how to run it, in fact, this is because luncene has already packaged the demo into a lucene-demos-2.9.1.jar, And you introduced in the classpath environment variables, so can run.

④ When you run searchfiles, each time you enter a keyword, the query ends, you need to press ENTER below, then enter the keyword, and then perform the next query.

Related Article

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.