Architecture and implementation of Apache Lucene

41
Architecture and implementation of Apache Lucene Kolloquium zur Masterarbeit Josiane Gamgo November 2010

description

Thesis defense.

Transcript of Architecture and implementation of Apache Lucene

Page 1: Architecture and implementation of Apache Lucene

Architecture and implementation of Apache Lucene

Kolloquium zur Masterarbeit

Josiane Gamgo

November 2010

Page 2: Architecture and implementation of Apache Lucene

16.11.10 2

AgendaMotivationApache Lucene KonzepteÜberblick über die KomponentenLucene DokumentIndizierungIndex-Suche Case study: Solr

Page 3: Architecture and implementation of Apache Lucene

16.11.10 3

Motivation

Bedarf an einer effizienten Suchmaschine für Kunden

Mehr Wissen über Lucene

Mangel an wissenschaftlicher Arbeit über

die interne Struktur von Apache Lucene

Page 4: Architecture and implementation of Apache Lucene

16.11.10 4

Erfunden 1998 von Doug Cutting

2001 von Apache von Sourceforge übernommen und

wird bis heute “Apache Lucene” genannt

Ist eine Java-Bibliothek für die Volltextsuche

Benutzt für die Indizierung und für die Suche

Implementiert algorithmen und Modelle der Information

Retrieval

Apache Lucene

Page 5: Architecture and implementation of Apache Lucene

16.11.10 5

Konzepte

Lucene-Dokument

Analyzer

Indizierung

QueryParser

Indexsuche

Page 6: Architecture and implementation of Apache Lucene

16.11.10 6

Überblick über die Komponenten

Page 7: Architecture and implementation of Apache Lucene

16.11.10 Lucene Dokument 7

Lucene Dokument:Architektur Übersicht

Page 8: Architecture and implementation of Apache Lucene

16.11.10 Lucene Dokument 8

Feld: Eigenschaften

Page 9: Architecture and implementation of Apache Lucene

16.11.10 Lucene Dokument 9

Boost factor

Gibt mehr Bedeutung zu einem Feld oder einer Abfrage

fcal.setBoost((float) 0.75);

q.setBoost((float)0.5);

Page 10: Architecture and implementation of Apache Lucene

16.11.10 Lucene Dokument 10

Daten Struktur: Beispiel

Page 11: Architecture and implementation of Apache Lucene

16.11.10 Lucene Dokument 11

Erstellung eines Lucene-Dokuments

Das DocumentHandler Interface

Ein Dokumenten Parser. Z.B. : PDFBOx, SAX

Eine Implementierung des DocumentHandlers

Interface

Page 12: Architecture and implementation of Apache Lucene

16.11.10 Lucene Dokument 12

Implementierung des DocumentHandlers interface

Page 13: Architecture and implementation of Apache Lucene

16.11.10 Lucene Dokument 13

Implementierung des DocumentHandlers Interface

1

2

public class PdfHandler implements DocumentHandler{

public Document getDocument(File originalFile) throws DocumentHandlerException {

try {

pdfdoc = PDDocument.load(originalFile);//load original document into a PDDocument

PDFTextStripper stripper = new PDFTextStripper();StringWriter writer = new StringWriter();stripper.writeText(pdfdoc, writer);

...

PdfContents =writer.getBuffer().toString();PDDocumentInformation metadata = pdfdoc.getDocumentInformation(); 3

doc.add(new Field("contents",PdfContents,Field.Store.NO,Field.Index.ANALYZED,Field.TermVector.YES));doc.add(new Field("path",originalFile.getAbsolutePath(),Field.Store.YES,Field.Index.ANALYZED));doc.add(new Field("filename",originalFile.getName(),Field.Store.YES,Field.Index.ANALYZED));doc.add(fcal);

4fcal = new Field("date of creation",String.valueOf(cal.get(Calendar.DAY_OF_WEEK)),Field.Store.YES,Field.Index.ANALYZED);fcal.setOmitNorms(true);fcal.setBoost((float) 0.75);

Calendar cal = metadata.getCreationDate();

Calendar cal = metadata.getCreationDate();

...

...

...

Page 14: Architecture and implementation of Apache Lucene

16.11.10 14

Indizierung: Komponenten Übersicht

Page 15: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 15

Analyzer: Die Strategie des IndexWriters

Page 16: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 16

Analyzer: Die Strategie des IndexWriters

Page 17: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 17

TokenStream decorator pattern

Page 18: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 18

Tokenizer

Page 19: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 19

Tokenizer: Beispiel

Page 20: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 20

TokenFilter

Page 21: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 21

TokenFilter Beispiel: PorterStemFilter

(condition)S1-> S2Condition =

(*V*)Y → i, ZB.• Z.b. Query → queri

(m>0)ational → ate(m>1)ate →

• Z.b. Informational → informationate → inform

Page 22: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 22

Erstellung eines Index

Beispiel: Erstellung eines Index für zwei pdf Dateien:

Page 23: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 23

Erstellung eines Index

Extracted and analyzed terms

DocIds

all 1

literature 1

shares 1

assumption 1

web 1

searches 1

motivated 1

information 1

need 1

search 2

engines 2

uses 2

spider 2

search 2

spider 2

web 2

information 2

terms(sorted) DocIds

all 1

assumption 1

engines 2

information 1

information 2

literature 1

motivated 1

need 1

search 2

search 2

searches 1

shares 1

spider 2

spiders 2

uses 2

web 1

web 2

Page 24: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 24

Erstellung eines Index

Terms Dictionary(term,tfq)

Posting lists

all 1 1

assumption 1 1

engines 1 2

information 2 1,2

literature 1 1

motivated 1 1

need 1 1

search 2 2

searches 1 1

shares 1 1

spider 1 2

spiders 1 2

uses 1 2

web 2 1,2

Terms Dictionary( stemmed terms,tfq)

Posting lists

all 1 1

assumpt 1 1

engin 1 2

inform 2 1,2

literatur 1 1

motiv 1 1

need 1 1

search 3 1,2

share 1 1

spider 2 2

us 1 2

web 2 1,2

Page 25: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 25

Indizierungsalgorithmen: IR Versus Lucene

Indizierungsalgorithmen in Information Retrieval(IR)Suffix arraysSignature FilesInverted Files

Lucene IndizierungsalgorithmusBasis-Algorithmus Inkrementell-Algorithmus.

Page 26: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 26

Lucene Indizierungsalgorithmus

Quelle:http://lucene.sourceforge.net/talks/pisa

Page 27: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 27

Lucene Indizierungsalgorithmus

Page 28: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 28

Index Optimierung

Lucene benutzte Puffer kontrollieren: MergeFactorminMergeDocsmaxMergeDocs

Zuerst den Index in den Arbeitspeicher speichernIndexWriter.optimize()IndexWriter.MaxFieldLength

Page 29: Architecture and implementation of Apache Lucene

16.11.10 Indizierung 29

Index Datentypen

Page 30: Architecture and implementation of Apache Lucene

16.11.10 30

Indexsuche: Komponenten

Page 31: Architecture and implementation of Apache Lucene

16.11.10 Index Suche 31

Lucene Abfrage Sprache(Query Language)

Hat eine Grammatik:Query ::=(clause)*

Clause ::=[“+”,”-”][<TERM>”:”](<TERM>| “(“Query”)”)

Definiert die Syntax eines Lucene Query Token

Page 32: Architecture and implementation of Apache Lucene

16.11.10 Index Suche 32

Lucene Query: Beispiel „web AND search“

Page 33: Architecture and implementation of Apache Lucene

16.11.10 Index Suche 33

Benutzung der Index für Die Suche

Page 34: Architecture and implementation of Apache Lucene

16.11.10 Index Suche 34

Index Search Algorithmus

Quelle: http://lucene.sourceforge.net/papers/riao97.ps

Page 35: Architecture and implementation of Apache Lucene

16.11.10 Index Suche 35

Lucene Retrieval Modell

Ist eine Kombination von Boolean Model und Vector space model

Boolean Model: Beispiel query = “Web AND search”

Page 36: Architecture and implementation of Apache Lucene

16.11.10 Index Suche 36

Lucene Retrieval Modell

Vector space modelErfunden 1945 by Gerard SaltonPrinzip: Gegeben sei ein Dokument Dj, und ein Query Q. Beide werden als Vektoren von t terms Dargestellt. Die Ähnlichkeit zwischen den beiden Vektoren wird berechnet. Je kleiner der Winkel zwischen den beiden ist, desto näher ist das Dokument von den Query. Die Ähnlichkeit ist wie folgt berechnet:

Page 37: Architecture and implementation of Apache Lucene

16.11.10 Index Suche 37

Begriff Gewichtung: tfij - idfi

Die Begriffe, die als Such Ergebnisse dargestellt werden, sollten höhere Begriff frequenz haben und eine geringe frequenz in der Lucene Dokumenten Sammlung haben Die Gewichtung eines Begriff hängt von 3 Faktoren ab: tfij , idfi , und die Länge des Dokuments.

Der Begriff Gewichtung in das Dokument ist das Produkt: tfij x idfi

Page 38: Architecture and implementation of Apache Lucene

16.11.10 Index Suche 38

Lucene Formel zur Berechnung der Such Ergebnisse

Coord(q,d)= tfiq, für ein Begriff I in then query qqueryNorm(q)= Wiq x t.getBoost()t.getBoost() ist der Boost factor, der für den Query definiert istnorm(t,d) enthält länge und boost für jedes Field

Page 39: Architecture and implementation of Apache Lucene

16.11.10 39

Case Study: Solr

Ein Open source enterprise search server

Basiert auf Lucene

Komponenten:

SolrDocument

Solr analysis

Solr QueryParser Z.B.:Query= {!func}sum(n,5)

Wesentliche Merkmale: highlighting,faceting, caching.

Page 40: Architecture and implementation of Apache Lucene

16.11.10 40

Case Study: Solr

Quelle: http://www.typo3-solr.com/en/what-is-solr/

Page 41: Architecture and implementation of Apache Lucene

16.11.10 41

Danke für Ihre Aufmerksamkeit !