[null, {"document_url": "http://techie-experience.blogspot.com/2012/12/lucene-quickly-add-index-and-search.html", "unformatted_src": "http://1.bp.blogspot.com/-TvZr2uzB2h0/UNsRcmkTEKI/AAAAAAAAANo/xArSxH8jtjU/s320/lucene.png", "src": "http://1.bp.blogspot.com/-TvZr2uzB2h0/UNsRcmkTEKI/AAAAAAAAANo/xArSxH8jtjU/s320/lucene.png", "formatted_filename": "lucene", "rendered_width": 320, "rendered_height": 112}, null, {"document_url": "http://techie-experience.blogspot.com/2012/12/lucene-quickly-add-index-and-search.html", "unformatted_src": "http://2.bp.blogspot.com/-DitfSzwwhaM/UNsTU935V2I/AAAAAAAAAN4/pWxUyLNVYeg/s1600/lucene-process.jpg", "src": "http://2.bp.blogspot.com/-DitfSzwwhaM/UNsTU935V2I/AAAAAAAAAN4/pWxUyLNVYeg/s1600/lucene-process.jpg", "formatted_filename": "lucene process"}, null, {"document_url": "http://techie-experience.blogspot.com/2012/12/lucene-quickly-add-index-and-search.html", "unformatted_src": "http://1.bp.blogspot.com/-_N-tlzyeDrg/UNsUTiJf3JI/AAAAAAAAAOE/MA-Gucjzh0E/s1600/lucene-indexing.jpg", "src": "http://1.bp.blogspot.com/-_N-tlzyeDrg/UNsUTiJf3JI/AAAAAAAAAOE/MA-Gucjzh0E/s1600/lucene-indexing.jpg", "formatted_filename": "lucene indexing"}, null, {"document_url": "http://techie-experience.blogspot.com/2012/12/lucene-quickly-add-index-and-search.html", "unformatted_src": "http://4.bp.blogspot.com/-2Lzi3MKsUis/UNsWC1K4N4I/AAAAAAAAAOY/rTtoyAqvllQ/s1600/lucene-analyzers.jpg", "src": "http://4.bp.blogspot.com/-2Lzi3MKsUis/UNsWC1K4N4I/AAAAAAAAAOY/rTtoyAqvllQ/s1600/lucene-analyzers.jpg", "formatted_filename": "lucene analyzers"}, null, {"document_url": "http://techie-experience.blogspot.com/2012/12/lucene-quickly-add-index-and-search.html", "unformatted_src": "http://1.bp.blogspot.com/-DSX30pXgvU0/UNsWhArp2dI/AAAAAAAAAOg/oY54QjGvO8o/s1600/sample-analyzer.jpg", "src": "http://1.bp.blogspot.com/-DSX30pXgvU0/UNsWhArp2dI/AAAAAAAAAOg/oY54QjGvO8o/s1600/sample-analyzer.jpg", "formatted_filename": "sample analyzer"}, null, {"document_url": "http://techie-experience.blogspot.com/2012/12/lucene-quickly-add-index-and-search.html", "unformatted_src": "http://2.bp.blogspot.com/-KH44H11xWAM/UNsYcfTAEbI/AAAAAAAAAO0/3uzv_-4TJ-8/s1600/lucene-store-index.jpg", "src": "http://2.bp.blogspot.com/-KH44H11xWAM/UNsYcfTAEbI/AAAAAAAAAO0/3uzv_-4TJ-8/s1600/lucene-store-index.jpg", "formatted_filename": "lucene store index"}, null, {"document_url": "http://techie-experience.blogspot.com/2012/12/lucene-quickly-add-index-and-search.html", "unformatted_src": "http://1.bp.blogspot.com/-Eajgrj420PY/UNsZzGSlLQI/AAAAAAAAAPI/AoPQ8zly7sY/s1600/lucene-query.jpg", "src": "http://1.bp.blogspot.com/-Eajgrj420PY/UNsZzGSlLQI/AAAAAAAAAPI/AoPQ8zly7sY/s1600/lucene-query.jpg", "formatted_filename": "lucene query"}, null, {"document_url": "http://techie-experience.blogspot.com/2012/12/lucene-quickly-add-index-and-search.html", "unformatted_src": "http://4.bp.blogspot.com/-RGQUq-HJUfw/UNsaZK3EfVI/AAAAAAAAAPQ/krUPtaW1QgA/s1600/lucene-sample-queries.jpg", "src": "http://4.bp.blogspot.com/-RGQUq-HJUfw/UNsaZK3EfVI/AAAAAAAAAPQ/krUPtaW1QgA/s1600/lucene-sample-queries.jpg", "formatted_filename": "lucene sample queries"}, null, null, {"document_url": "http://techie-experience.blogspot.com/2012/12/lucene-quickly-add-index-and-search.html", "unformatted_src": "//lh4.googleusercontent.com/-TRewx7X7LlE/AAAAAAAAAAI/AAAAAAAAIr4/vRJmQeLzpsQ/s80-c/photo.jpg", "src": "http://lh4.googleusercontent.com/-TRewx7X7LlE/AAAAAAAAAAI/AAAAAAAAIr4/vRJmQeLzpsQ/s80-c/photo.jpg", "formatted_filename": "photo", "alt_text": "My photo", "rendered_width": 80, "rendered_height": 80}, null, null, null, null]

Lucene - Quickly add Index and Search Capability What is Lucene?

Lucene can plain text, integers, index PDF, Office Documents. etc.,

How Lucene enables Faster Search?

Lucence creates something called Inverted Index.   Normally we map    document -> terms in the document.  But, Lucene does the reverse. Creates a index term -> list of documents containing the term, which makes it faster to search.

Install Lucene

Maven Dependency

Download Dependency

Download Lucene from http://lucene.apache.org/ and add the lucene-core.jar in the classpath

How does Lucene Work? Let's understand the picture first from bottom - Center. The Raw Text is used to create a Lucene "Document" which is analyzed using the specified Analyzer and Document is added to the index based on the Store, TermVector and Analzed property of the Fields.

Next, the search from top to center. The users specify the query in a text format. The query Object is build based on the query text and the result of the executed query is returned as TopDocs.

Core Lucene Classes

The Lucene Directory

Directory - is the data space on which lucene operates. It can be a File System or a Memory.
Below are the often used Directory

Create an Index Entry

Lucene "Document" object is the main object used in indexing.  Documents contain multiple fields. The Analyzers work on the document fields to break them down into tokens and then writes the Directory using an Index Writer. The job of analyzing text into tokens or keywords to be searched. There are few default Analyzers provided by Lucene. The choice of Analyzer defined how the indexed text is tokenized and searched.
Below are some standard analyzers. Example - How analyzers work on sample text Properties that define Field indexing

Store :

Should the field be stored to retreive later


How to analyze the text

Term Vector

Need Term details for similar, highlight etc. Example of Creating Index

Example of Updating Index

Example of Deleting Index

Searching an Index : The users specify the query in a text format. The query Object is built based on the query text, analyzed and the result of the executed query is returned as TopDocs.


Queries are the main input for the search.

Sample Queries Example on Search:

Lucene Diagnostic Tools:

Complete Example:

Download here : LuceneTester.java



Posted by Srividhya Umashanker at 07:50