Lucene Search Operation - Lucene

What is Lucene Search Operation?

The procedure of searching is one of the core functionalities provide by Lucerne. Following figure illustrates the process and its use. Index Searcher is one of the middle works of the searching process.
searching_process (1)

we initial generate Directory(s) containing indexes and then exceed it to Index Searcher which open the Directory using Index Reader. Then we make a Query with a Term and make a search using Index Searcher by passing the Query to the searcher. Index Searcher returns a To-dos entity which contains the search information along with essay ID(s) of the file which is the result of the search process.

We will now explain you a step-wise move towards and help you recognize the indexing process using an essential instance.

Create a Query Parser

Query Parser category parses the user enter input into Lucerne clear format query. Follow these steps to build a Query Parser −

Step 1 − construct object of Query Parser.

Step 2 − Initialize the Query Parser object created with a pattern analyzer having version information and index name on which this query is to be run.

Create a Index Searcher

Index Searcher class acts as a middle constituent which searcher indexes formed during indexing process. Follow these steps to create an Index Searcher −

Step 1 − Create object of Index Searcher.

Step 2 − Create a Lucerne directory which should point to position where indexes are to be store.

Step 3 − Initialize the Index Searcher object produced with the index directory.

Make search

Follow these steps to construct search −

Step 1 − generate a Query object by parsing the search phrase through Query Parser.

Step 2 − Make search by calling the IndexSearcher.search () method.

Get the Document

The following program shows how to get the manuscript.

Close Index Searcher

The following program shows how to secure the Index Searcher.

Example Application

Let us form a test Lucerne application to test searching development.

Step Description
1
Create a project with a name LuceneFirstApplication under a package com.wisdomjobs.lucene as explained in the Lucene - First Application chapter. You can also use the project created in Lucene - First Application chapter as such for this chapter to understand the searching process.
2
CreateLuceneConstants.java,TextFileFilter.javaandSearcher.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 business logic is working as per the requirements.

LuceneConstants.java

This class is used to offer different constants to be used diagonally the sample application.

TextFileFilter.java

This class is used as a .txt file filter.

Searcher.java

This division is used to read the indexes made on raw data and searches data use the Lucerne annals.

LuceneTester.java

This division is usedto test the searching ability of the Lucerne library.

Data & Index Directory Creation

We have use 10 text files named record1.txt to record10.txt contain names and other information of the students and put them in the directory E:\Lucene\Data. Test Data. An index directory course should be formed as E:\Lucene\Index. After running the indexing program in the section Lucerne - Indexing Process, you can observe the list of index files produced in that database.

Running the Program

Formerly you are done with the design of the source, the raw data, the data directory, the index directory and the indexes, you can continue by compile and running your program. To do this, maintain LuceneTester.Java file tab dynamic and use each the Run option accessible in the Eclipse IDE or use Ctrl + F11 to assemble and run your LuceneTesterapplication. If your application runs effectively, it will print the following communication in Eclipse IDE's comfort –

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

Lucene Topics