About Me

Android, HTML5 and BlackBerry apps developers. Proactive towards new technologies. Reading books, playing chess are my hobbies.

Tuesday, December 9, 2014

Lucene Search API : Lucene Search implementation - Part 2

For understanding what is Lucene Index and creating Lucene Indexes, please take a look into my previous article here


Searching on the Index file:

Searching is the process of looking for words in the index and finding the documents that contain those words.
The following are the fundamental Lucene classes for searching a given text: Searcher, Term.

Searcher : Searcher is an abstract base class that has various search methods. The Search method returns an ordered collection of documents ranked by computed scores. Lucene calculates a score for each of the documents that match a given query.

IndexSearcher is most commonly used subclass that allows searching indices stored in a given directory. IndexSearcher is thread-safe, a single instance can be used by multiple threads concurrently.

SearcherFactory is a factory class used to customize the search results.

Term : Term is the most fundamental unit for searching. It's composed of two elements: the text of the word and the name of the field(column name) in which the text occurs.

Query : Query is an abstract base class for queries. Searching for a specified word or phrase involves wrapping them in a term, adding the terms to a query object, and passing this query object to IndexSearcher's search method.

Lucene comes with various types of concrete query implementations, such as TermQuery, BooleanQuery, PhraseQuery, PrefixQuery, RangeQuery, MultiTermQuery, FilteredQuery, SpanQuery, etc.

Displaying Results :

IndexSearcher returns an array of references to ranked search results, such as documents. Primary classes involved in retrieving the search results are ScoreDoc and TopDocs.

ScoreDoc  A simple pointer to a document contained in the search results. This encapsulates the position of a document in
the index and the score(number of matches) computed by Lucene.

TopDocs  Encapsulates the total number of search results and an array of ScoreDoc

No comments:

Post a Comment