Lucene - Analysis-Stop Analyzer - Lucene

What is Lucene Stop Analyzer?

This analyzer works similar to SimpleAnalyzer and remove the common words like 'a', 'an', 'the', etc.

Class Declaration

Following is the declaration for the org.apache.lucene.analysis.StopAnalyzer class −

Fields

Following are the fields for the org.apache.lucene.analysis.StopAnalyzer class −

  • static Set<?> ENGLISH_STOP_WORDS_SET - An unmodifiable set containing some common English words that are not usually useful for searching.

Class Constructors

The following table shows the different class constructors −

S.No. Constructor & Description
1
StopAnalyzer(Version matchVersion)
Builds an analyzer which removes words in ENGLISH_STOP_WORDS_SET.
2
StopAnalyzer(Version matchVersion, File stopwordsFile)
Builds an analyzer with the stop words from the given file.
3
StopAnalyzer(Version matchVersion, Reader stopwords)
Builds an analyzer with the stop words from the given reader.
4
StopAnalyzer(Version matchVersion, Set<?> stopWords)
Builds an analyzer with the stop words from the given set.

Class Methods

The following table shows the different class methods −

S.No.

Method & Description

1

protected Reusable Analyzer Base. Token Stream Components create Components (String field Name, Reader reader)

Creates a new ReusableAnalyzerBase.TokenStreamComponents used to tokenize all the text in the provided Reader.

Methods Inherited

This class inherits methods from the following classes −

  • org.apache.lucene.analysis.StopwordAnalyzerBase

  • org.apache.lucene.analysis.ReusableAnalyzerBase
  • org.apache.lucene.analysis.Analyzer
  • java.lang.Object

Usage

Example Application

Let us create a test Lucene application to test search using BooleanQuery.

Step Description
1 Create a project with a nameLuceneFirstApplicationunder a packagecom.wisdomjobs.luceneas explained in theLucene - First Applicationchapter. You can also use the project created inLucene - First Applicationchapter as such for this chapter to the understand searching process.
2 CreateLuceneConstants.javaas explained in theLucene - First Applicationchapter. Keep the rest of the files unchanged.
3 CreateLuceneTester.javaas mentioned below.
4 Clean and Build the application to make sure the business logic is working as per the requirements.

LuceneConstants.java

This class is used to provide various constants to be used across the sample application.

LuceneTester.java

This class is used to test the searching capability of the Lucene library.

Running the Program

Once you are done with the creation of the source, you can proceed by compiling and running your program. To do this, keep the LuceneTester.Java file tab active and use either the Run option available in the Eclipse IDE or use Ctrl + F11 to compile and run your LuceneTester application. If your application runs successfully, it will print the following message in Eclipse IDE's console −

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Lucene Topics