SlideShare a Scribd company logo
5
Most read
11
Most read
16
Most read
Introduction to Apache Lucene

Sumit Luthra
Agenda
What is Apache Lucene ?
Focus of Apache Lucene
Lucene Architecture
Core Indexing Classes
Core Searching Classes
Demo
Questions & Answers
What is Apache Lucene?
Apache Lucene is a high-performance, full- featured text search
engine library written entirely in Java.”
Also known as Information Retrieval Library.
Lucene is specifically an API, not an application.
Open Source
Focus
Indexing Documents
Searching Documents

Note :
You can use Lucene to provide consistent full-text indexing across
both database objects and documents in various formats (Microsoft
Office documents, PDF, HTML, text, emails and so on).
Lucene Architecture
Index
document

Users

Analyze
document

Search UI

Build document

Index

Build
query

Render
results

Acquire content
Raw
Content

Run query
Indexing Documents
IndexWriter writer = new IndexWriter(directory, analyzer, true);
Document doc = new Document();
doc.add(new Field(“content", “Hello World”,
Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field(“name", “filename.txt",
Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field(“path", “http://myfile/",
Field.Store.YES, Field.Index.TOKENIZED));
// [...]
writer.addDocument(doc);
writer.close();
Core indexing classes
IndexWriter
Directory
Analyzer
Document
Field
IndexWriter construction
// Deprecated
IndexWriter(Directory d, Analyzer a, // default analyzer
IndexWriter.MaxFieldLength mfl);

// Preferred
IndexWriter(Directory d,
IndexWriterConfig c);
Directory
FSDirectory
RAMDirectory
DbDirectory
FileSwitchDirectory
JEDirectory
Analyzers
Tokenizes the input text
Common Analyzers
–

WhitespaceAnalyzer
Splits tokens on whitespace

–

SimpleAnalyzer
Splits tokens on non-letters, and then lowercases

–

StopAnalyzer
Same as SimpleAnalyzer, but also removes stop words

–

StandardAnalyzer
Most sophisticated analyzer that knows about certain token types,
lowercases, removes stop words, ...
Analysis examples
•

“The quick brown fox jumped over the lazy dog”

•

WhitespaceAnalyzer
–

•

SimpleAnalyzer
–

•

[the] [quick] [brown] [fox] [jumped] [over] [the] [lazy] [dog]

StopAnalyzer
–

•

[The] [quick] [brown] [fox] [jumped] [over] [the] [lazy] [dog]

[quick] [brown] [fox] [jumped] [over] [lazy] [dog]

StandardAnalyzer
–

[quick] [brown] [fox] [jumped] [over] [lazy] [dog]
More analysis examples
•

“XY&Z Corporation – xyz@example.com”

•

WhitespaceAnalyzer
–

•

SimpleAnalyzer
–

•

[xy] [z] [corporation] [xyz] [example] [com]

StopAnalyzer
–

•

[XY&Z] [Corporation] [-] [xyz@example.com]

[xy] [z] [corporation] [xyz] [example] [com]

StandardAnalyzer
–

[xy&z] [corporation] [xyz@example.com]
Document & Fields
A Document is the atomic unit of indexing and
searching, It contains Fields
Fields have a name and a value
–

You have to translate raw content into Fields

–

Examples: Title, author, date, abstract, body, URL, keywords, ...

–

Different documents can have different fields
Field options
Field.Store
–

NO : Don’t store the field value in the index

–

YES : Store the field value in the index

Field.Index
–

ANALYZED : Tokenize with an Analyzer

–

NOT_ANALYZED : Do not tokenize

–

NO : Do not index this field
Searching an Index
IndexSearcher searcher = new IndexSearcher(directory);
QueryParser parser = new QueryParser(Version, field_name
,analyzer);
Query query = parser.parse(WORD_SEARCHED);
TopDocs hits = searcher.search(query, noOfHits);
ScoreDoc[] document = hits.scoreDocs;
Document doc = searcher.doc(0); // look at first match
System.out.println(“name=" + doc.get(“name"));
searcher.close();
Core searching classes
IndexSearcher
Query
QueryParser
TopDocs
ScoreDoc
IndexSearcher
Constructor:
–

IndexSearcher(Directory d);
•

–

// Deprecated

IndexSearcher(IndexReader r);
•

Construct an IndexReader with static method
IndexReader.open(dir)
Query
•

TermQuery
–

Constructed from a Term

•

TermRangeQuery

•

NumericRangeQuery

•

PrefixQuery

•

BooleanQuery

•

PhraseQuery

•

WildcardQuery

•

FuzzyQuery

•

MatchAllDocsQuery
QueryParser
•

Constructor
–

•

QueryParser(Version matchVersion,
String defaultField,
Analyzer analyzer);

Parsing methods
–

Query parse(String query) throws
ParseException;

–

... and many more
QueryParser syntax examples
Query expression

Document matches if…

java

Contains the term java in the default field

java junit
java OR junit

Contains the term java or junit or both in the default field
(the default operator can be changed to AND)

+java +junit

Contains both java and junit in the default field

java AND junit
title:ant

Contains the term ant in the title field

title:extreme –subject:sports

Contains extreme in the title and not sports in subject

(agile OR extreme) AND java

Boolean expression matches

title:”junit in action”

Phrase matches in title

title:”junit action”~5

Proximity matches (within 5) in title

java*

Wildcard matches

java~

Fuzzy matches

lastmodified:[1/1/09 TO
12/31/09]

Range matches
TopDocs
Class containing top N ranked searched documents/results
that match a given query.

ScoreDoc
Array of ScoreDoc containing documents/results
that match a given query.
Demo of simple indexing and searching
using Apache Lucene

You will require lucene-core-x.y.jar for this demo.
Any Questions ?
Thank You.

More Related Content

What's hot (20)

PDF
Elasticsearch
Shagun Rathore
 
PDF
Elasticsearch From the Bottom Up
foundsearch
 
PDF
Introduction to elasticsearch
pmanvi
 
PDF
Apache Calcite Tutorial - BOSS 21
Stamatis Zampetakis
 
PPTX
An Intro to Elasticsearch and Kibana
ObjectRocket
 
PPTX
Introduction to Elasticsearch with basics of Lucene
Rahul Jain
 
PPTX
sql function(ppt)
Ankit Dubey
 
PPTX
Soap vs rest
Antonio Severien
 
ODP
Elasticsearch for beginners
Neil Baker
 
PDF
Introduction to Elasticsearch
Ruslan Zavacky
 
PDF
My first 90 days with ClickHouse.pdf
Alkin Tezuysal
 
PDF
Intro to Elasticsearch
Clifford James
 
PDF
Spark SQL Deep Dive @ Melbourne Spark Meetup
Databricks
 
PDF
Introduction à ElasticSearch
Fadel Chafai
 
PPTX
Elasticsearch
Divij Sehgal
 
PPT
HBASE Overview
Sampath Rachakonda
 
PDF
Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...
Edureka!
 
PDF
A Deep Dive into Query Execution Engine of Spark SQL
Databricks
 
PPTX
Lucene
Harshit Agarwal
 
PDF
Introducing DataFrames in Spark for Large Scale Data Science
Databricks
 
Elasticsearch
Shagun Rathore
 
Elasticsearch From the Bottom Up
foundsearch
 
Introduction to elasticsearch
pmanvi
 
Apache Calcite Tutorial - BOSS 21
Stamatis Zampetakis
 
An Intro to Elasticsearch and Kibana
ObjectRocket
 
Introduction to Elasticsearch with basics of Lucene
Rahul Jain
 
sql function(ppt)
Ankit Dubey
 
Soap vs rest
Antonio Severien
 
Elasticsearch for beginners
Neil Baker
 
Introduction to Elasticsearch
Ruslan Zavacky
 
My first 90 days with ClickHouse.pdf
Alkin Tezuysal
 
Intro to Elasticsearch
Clifford James
 
Spark SQL Deep Dive @ Melbourne Spark Meetup
Databricks
 
Introduction à ElasticSearch
Fadel Chafai
 
Elasticsearch
Divij Sehgal
 
HBASE Overview
Sampath Rachakonda
 
Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...
Edureka!
 
A Deep Dive into Query Execution Engine of Spark SQL
Databricks
 
Introducing DataFrames in Spark for Large Scale Data Science
Databricks
 

Viewers also liked (20)

PDF
Architecture and implementation of Apache Lucene
Josiane Gamgo
 
PPTX
Solr
sortivo
 
ODP
Search Lucene
Jeremy Coates
 
PDF
Devinsampa nginx-scripting
Tony Fabeen
 
PDF
Munching & crunching - Lucene index post-processing
abial
 
PPTX
Index types
Volodymyr Zhabiuk
 
PDF
From Lucene to Elasticsearch, a short explanation of horizontal scalability
Stéphane Gamard
 
PDF
Text Indexing / Inverted Indices
Carlos Castillo (ChaTo)
 
PDF
Lucene
Matt Wood
 
PPT
Lucene and MySQL
farhan "Frank"​ mashraqi
 
PPT
Lucandra
otisg
 
PPT
Inverted index
Krishna Gehlot
 
PPT
Intelligent crawling and indexing using lucene
Swapnil & Patil
 
PPT
An introduction to inverted index
weedge
 
PDF
Apache Solr/Lucene Internals by Anatoliy Sokolenko
Provectus
 
PDF
Berlin Buzzwords 2013 - How does lucene store your data?
Adrien Grand
 
PDF
Introduction to solr
Sematext Group, Inc.
 
PDF
Architecture and Implementation of Apache Lucene: Marter's Thesis
Josiane Gamgo
 
PPT
Lucene Introduction
otisg
 
ODP
The search engine index
CJ Jenkins
 
Architecture and implementation of Apache Lucene
Josiane Gamgo
 
Solr
sortivo
 
Search Lucene
Jeremy Coates
 
Devinsampa nginx-scripting
Tony Fabeen
 
Munching & crunching - Lucene index post-processing
abial
 
Index types
Volodymyr Zhabiuk
 
From Lucene to Elasticsearch, a short explanation of horizontal scalability
Stéphane Gamard
 
Text Indexing / Inverted Indices
Carlos Castillo (ChaTo)
 
Lucene
Matt Wood
 
Lucene and MySQL
farhan "Frank"​ mashraqi
 
Lucandra
otisg
 
Inverted index
Krishna Gehlot
 
Intelligent crawling and indexing using lucene
Swapnil & Patil
 
An introduction to inverted index
weedge
 
Apache Solr/Lucene Internals by Anatoliy Sokolenko
Provectus
 
Berlin Buzzwords 2013 - How does lucene store your data?
Adrien Grand
 
Introduction to solr
Sematext Group, Inc.
 
Architecture and Implementation of Apache Lucene: Marter's Thesis
Josiane Gamgo
 
Lucene Introduction
otisg
 
The search engine index
CJ Jenkins
 
Ad

Similar to Introduction To Apache Lucene (20)

PPTX
Apache lucene
Dr. Abhiram Gandhe
 
PPT
Lucene BootCamp
GokulD
 
PDF
Tutorial 5 (lucene)
Kira
 
PDF
Full Text Search with Lucene
WO Community
 
PPTX
Apache Lucene Basics
Anirudh Sharma
 
PDF
IR with lucene
Stelios Gorilas
 
PPT
Lucene Bootcamp -1
GokulD
 
PPT
Lucene basics
Nitin Pande
 
PPTX
Introduction to Information Retrieval using Lucene
DeeKan3
 
PPT
Advanced full text searching techniques using Lucene
Asad Abbas
 
PPT
Lucene Bootcamp - 2
GokulD
 
PPTX
Illuminating Lucene.Net
Dean Thrasher
 
PDF
Lucene for Solr Developers
Erik Hatcher
 
ODP
Apache Lucene: Searching the Web and Everything Else (Jazoon07)
dnaber
 
PPT
Apache Lucene Searching The Web
Francisco Gonçalves
 
PDF
Lucene for Solr Developers
Erik Hatcher
 
PPTX
Search Me: Using Lucene.Net
gramana
 
PPTX
Search enabled applications with lucene.net
Willem Meints
 
PDF
Let's Build an Inverted Index: Introduction to Apache Lucene/Solr
Sease
 
PDF
Lucene for Solr Developers
Erik Hatcher
 
Apache lucene
Dr. Abhiram Gandhe
 
Lucene BootCamp
GokulD
 
Tutorial 5 (lucene)
Kira
 
Full Text Search with Lucene
WO Community
 
Apache Lucene Basics
Anirudh Sharma
 
IR with lucene
Stelios Gorilas
 
Lucene Bootcamp -1
GokulD
 
Lucene basics
Nitin Pande
 
Introduction to Information Retrieval using Lucene
DeeKan3
 
Advanced full text searching techniques using Lucene
Asad Abbas
 
Lucene Bootcamp - 2
GokulD
 
Illuminating Lucene.Net
Dean Thrasher
 
Lucene for Solr Developers
Erik Hatcher
 
Apache Lucene: Searching the Web and Everything Else (Jazoon07)
dnaber
 
Apache Lucene Searching The Web
Francisco Gonçalves
 
Lucene for Solr Developers
Erik Hatcher
 
Search Me: Using Lucene.Net
gramana
 
Search enabled applications with lucene.net
Willem Meints
 
Let's Build an Inverted Index: Introduction to Apache Lucene/Solr
Sease
 
Lucene for Solr Developers
Erik Hatcher
 
Ad

More from Mindfire Solutions (20)

PDF
Physician Search and Review
Mindfire Solutions
 
PDF
diet management app
Mindfire Solutions
 
PDF
Business Technology Solution
Mindfire Solutions
 
PDF
Remote Health Monitoring
Mindfire Solutions
 
PDF
Influencer Marketing Solution
Mindfire Solutions
 
PPT
High Availability of Azure Applications
Mindfire Solutions
 
PPTX
IOT Hands On
Mindfire Solutions
 
PPTX
Glimpse of Loops Vs Set
Mindfire Solutions
 
ODP
Oracle Sql Developer-Getting Started
Mindfire Solutions
 
PPT
Adaptive Layout In iOS 8
Mindfire Solutions
 
PPT
Introduction to Auto-layout : iOS/Mac
Mindfire Solutions
 
PPT
LINQPad - utility Tool
Mindfire Solutions
 
PPT
Get started with watch kit development
Mindfire Solutions
 
PPTX
Swift vs Objective-C
Mindfire Solutions
 
ODP
Material Design in Android
Mindfire Solutions
 
ODP
Introduction to OData
Mindfire Solutions
 
PPT
Ext js Part 2- MVC
Mindfire Solutions
 
PPT
ExtJs Basic Part-1
Mindfire Solutions
 
PPT
Spring Security Introduction
Mindfire Solutions
 
Physician Search and Review
Mindfire Solutions
 
diet management app
Mindfire Solutions
 
Business Technology Solution
Mindfire Solutions
 
Remote Health Monitoring
Mindfire Solutions
 
Influencer Marketing Solution
Mindfire Solutions
 
High Availability of Azure Applications
Mindfire Solutions
 
IOT Hands On
Mindfire Solutions
 
Glimpse of Loops Vs Set
Mindfire Solutions
 
Oracle Sql Developer-Getting Started
Mindfire Solutions
 
Adaptive Layout In iOS 8
Mindfire Solutions
 
Introduction to Auto-layout : iOS/Mac
Mindfire Solutions
 
LINQPad - utility Tool
Mindfire Solutions
 
Get started with watch kit development
Mindfire Solutions
 
Swift vs Objective-C
Mindfire Solutions
 
Material Design in Android
Mindfire Solutions
 
Introduction to OData
Mindfire Solutions
 
Ext js Part 2- MVC
Mindfire Solutions
 
ExtJs Basic Part-1
Mindfire Solutions
 
Spring Security Introduction
Mindfire Solutions
 

Recently uploaded (20)

DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PDF
The Growing Value and Application of FME & GenAI
Safe Software
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
PDF
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
The Growing Value and Application of FME & GenAI
Safe Software
 
Kubernetes - Architecture & Components.pdf
geethak285
 
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Practical Applications of AI in Local Government
OnBoard
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 

Introduction To Apache Lucene