SlideShare une entreprise Scribd logo
1  sur  41
Architecture and
implementation of
  Apache Lucene



 Kolloquium zur Masterarbeit
      Josiane Gamgo
       November 2010
Agenda
      Motivation
      Apache Lucene
      Konzepte
      Überblick über die Komponenten
      Lucene Dokument
      Indizierung
      Index-Suche
      Case study: Solr



16.11.10                               2
Motivation


 Bedarf an einer effizienten Suchmaschine
 für Kunden
 Mehr Wissen über Lucene


 Mangel an wissenschaftlicher Arbeit über
 die interne Struktur von Apache Lucene




16.11.10                                    3
Apache Lucene
  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



16.11.10                                              4
Konzepte

    Lucene-Dokument
    Analyzer
    Indizierung
    QueryParser
    Indexsuche




16.11.10              5
Überblick über die Komponenten




16.11.10                         6
Lucene Dokument:
           Architektur Übersicht




16.11.10          Lucene Dokument   7
Feld: Eigenschaften




16.11.10      Lucene Dokument   8
Boost factor

  Gibt mehr Bedeutung zu einem Feld oder einer
  Abfrage
           fcal.setBoost((float) 0.75);
           q.setBoost((float)0.5);




16.11.10                     Lucene Dokument   9
Daten Struktur: Beispiel




16.11.10      Lucene Dokument   10
Erstellung eines Lucene-Dokuments

      Das DocumentHandler Interface
      Ein Dokumenten Parser. Z.B. : PDFBOx, SAX
      Eine Implementierung des DocumentHandlers
      Interface




16.11.10               Lucene Dokument            11
Implementierung des
           DocumentHandlers interface




16.11.10             Lucene Dokument    12
Implementierung des
           DocumentHandlers Interface
           public class PdfHandler implements DocumentHandler{

            public Document getDocument(File originalFile) throws DocumentHandlerException {

              try {

              pdfdoc = PDDocument.load(originalFile);//load original document into a PDDocument         1
                            ...
              PDFTextStripper stripper = new PDFTextStripper();
              StringWriter writer = new StringWriter();             2
              stripper.writeText(pdfdoc, writer);

                                      Calendar cal = metadata.getCreationDate();
              PdfContents =writer.getBuffer().toString();
              PDDocumentInformation metadata = pdfdoc.getDocumentInformation();     3
              Calendar cal = metadata.getCreationDate();
                            ...
              fcal = new Field("date of
              creation",String.valueOf(cal.get(Calendar.DAY_OF_WEEK)),Field.Store.YES,Field.Index.ANALYZED);
                                                                                                                      4
              fcal.setOmitNorms(true);
              fcal.setBoost((float) 0.75);
                            ...

              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);
                      ...


16.11.10                                         Lucene Dokument                                                     13
Indizierung: Komponenten
                    Übersicht




16.11.10                              14
Analyzer: Die Strategie des
                  IndexWriters




16.11.10              Indizierung        15
Analyzer: Die Strategie des
                  IndexWriters




16.11.10              Indizierung        16
TokenStream decorator pattern




16.11.10      Indizierung       17
Tokenizer




16.11.10    Indizierung   18
Tokenizer: Beispiel




16.11.10        Indizierung   19
TokenFilter




16.11.10      Indizierung   20
TokenFilter Beispiel: PorterStemFilter

                        (condition)S1-> S2
                        Condition =
                              (*V*)Y → i, ZB.
                 •




                        Z.b. Query → queri
                              (m>0)ational → ate
                              (m>1)ate →
                 •      Z.b. Informational →
                        informationate → inform


16.11.10        Indizierung                        21
Erstellung eines Index
      Beispiel: Erstellung eines Index für zwei pdf
      Dateien:




16.11.10                   Indizierung                22
Erstellung eines Index
                                                        terms(sorted)   DocIds
          Extracted and   DocIds
         analyzed terms
                                                 all                      1
   all                      1
                                                 assumption               1
   literature               1
                                                 engines                  2
   shares                   1
                                                 information              1
   assumption               1
                                                 information              2
   web                      1
                                                 literature               1
   searches                 1
                                                 motivated                1
   motivated                1
                                                 need                     1
   information              1
                                                 search                   2
   need                     1
                                                 search                   2
   search                   2
                                                 searches                 1
   engines                  2
                                                 shares                   1
   uses                     2
                                                 spider                   2
   spider                   2
                                                 spiders                  2
   search                   2
                                                 uses                     2
   spider                   2
                                                 web                      1
   web                      2
                                                 web                      2
   information              2




16.11.10                           Indizierung                                   23
Erstellung eines Index
       Terms Dictionary   Posting lists
                                             Terms Dictionary     Posting lists
          (term,tfq)
                                           ( stemmed terms,tfq)

all               1            1
                                          all            1             1
assumption        1            1
                                          assumpt        1             1
engines           1            2
                                          engin          1             2
information       2           1,2
                                          inform         2            1,2
literature        1            1
                                          literatur      1             1
motivated         1            1

need              1            1          motiv          1             1

search            2            2          need           1             1

searches          1            1          search         3            1,2

shares            1            1          share          1             1

spider            1            2
                                          spider         2             2
spiders           1            2
                                          us             1             2
uses              1            2
                                          web            2            1,2
web               2           1,2




       16.11.10                                    Indizierung                    24
Indizierungsalgorithmen: IR Versus
              Lucene
       Indizierungsalgorithmen in Information Retrieval(IR)
             Suffix arrays
             Signature Files
             Inverted Files

       Lucene Indizierungsalgorithmus
          Basis-Algorithmus
          Inkrementell-Algorithmus.




16.11.10                    Indizierung                  25
Lucene Indizierungsalgorithmus




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




16.11.10                             Indizierung             26
Lucene Indizierungsalgorithmus




16.11.10       Indizierung       27
Index Optimierung

  Lucene benutzte Puffer kontrollieren:
           MergeFactor
           minMergeDocs
           maxMergeDocs


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



16.11.10                  Indizierung      28
Index Datentypen




16.11.10     Indizierung   29
Indexsuche: Komponenten




16.11.10                  30
Lucene Abfrage Sprache
              (Query Language)
  Hat eine Grammatik:
      Query ::=(clause)*
      Clause ::=[“+”,”-”][<TERM>”:”](<TERM>| “(“Query”)”)


  Definiert die Syntax eines Lucene Query Token




16.11.10                  Index Suche                 31
Lucene Query:
           Beispiel „web AND search“




16.11.10             Index Suche       32
Benutzung der Index für Die Suche




16.11.10      Index Suche       33
Index Search Algorithmus




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



16.11.10                                    Index Suche             34
Lucene Retrieval Modell

   Ist eine Kombination von Boolean Model und
   Vector space model
       Boolean Model: Beispiel query = “Web AND
       search”




16.11.10                 Index Suche              35
Lucene Retrieval Modell
    Vector space model
           Erfunden 1945 by Gerard Salton
           Prinzip: 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:




16.11.10                    Index Suche                  36
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




16.11.10                     Index Suche                          37
Lucene Formel zur Berechnung
          der Such Ergebnisse




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




16.11.10                         Index Suche                            38
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.



16.11.10                                               39
Case Study: Solr




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


16.11.10                                                 40
Danke für Ihre Aufmerksamkeit !




16.11.10                                     41

Contenu connexe

En vedette

From Lucene to Elasticsearch, a short explanation of horizontal scalability
From Lucene to Elasticsearch, a short explanation of horizontal scalabilityFrom Lucene to Elasticsearch, a short explanation of horizontal scalability
From Lucene to Elasticsearch, a short explanation of horizontal scalabilityStéphane Gamard
 
Lucandra
LucandraLucandra
Lucandraotisg
 
Intelligent crawling and indexing using lucene
Intelligent crawling and indexing using luceneIntelligent crawling and indexing using lucene
Intelligent crawling and indexing using luceneSwapnil & Patil
 
An introduction to inverted index
An introduction to inverted indexAn introduction to inverted index
An introduction to inverted indexweedge
 
Apache Solr/Lucene Internals by Anatoliy Sokolenko
Apache Solr/Lucene Internals  by Anatoliy SokolenkoApache Solr/Lucene Internals  by Anatoliy Sokolenko
Apache Solr/Lucene Internals by Anatoliy SokolenkoProvectus
 
Berlin Buzzwords 2013 - How does lucene store your data?
Berlin Buzzwords 2013 - How does lucene store your data?Berlin Buzzwords 2013 - How does lucene store your data?
Berlin Buzzwords 2013 - How does lucene store your data?Adrien Grand
 
Architecture and Implementation of Apache Lucene: Marter's Thesis
Architecture and Implementation of Apache Lucene: Marter's ThesisArchitecture and Implementation of Apache Lucene: Marter's Thesis
Architecture and Implementation of Apache Lucene: Marter's ThesisJosiane Gamgo
 
Lucene Introduction
Lucene IntroductionLucene Introduction
Lucene Introductionotisg
 
The search engine index
The search engine indexThe search engine index
The search engine indexCJ Jenkins
 
Introduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of LuceneIntroduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of LuceneRahul Jain
 
Using Solr Cloud to Tame an Index Explosion
Using Solr Cloud to Tame an Index ExplosionUsing Solr Cloud to Tame an Index Explosion
Using Solr Cloud to Tame an Index ExplosionLucidworks (Archived)
 
Scaling massive elastic search clusters - Rafał Kuć - Sematext
Scaling massive elastic search clusters - Rafał Kuć - SematextScaling massive elastic search clusters - Rafał Kuć - Sematext
Scaling massive elastic search clusters - Rafał Kuć - SematextRafał Kuć
 
Search Engine Powerpoint
Search Engine PowerpointSearch Engine Powerpoint
Search Engine Powerpoint201014161
 

En vedette (20)

Text Indexing / Inverted Indices
Text Indexing / Inverted IndicesText Indexing / Inverted Indices
Text Indexing / Inverted Indices
 
From Lucene to Elasticsearch, a short explanation of horizontal scalability
From Lucene to Elasticsearch, a short explanation of horizontal scalabilityFrom Lucene to Elasticsearch, a short explanation of horizontal scalability
From Lucene to Elasticsearch, a short explanation of horizontal scalability
 
Lucene
LuceneLucene
Lucene
 
Lucene and MySQL
Lucene and MySQLLucene and MySQL
Lucene and MySQL
 
Lucandra
LucandraLucandra
Lucandra
 
Inverted index
Inverted indexInverted index
Inverted index
 
Intelligent crawling and indexing using lucene
Intelligent crawling and indexing using luceneIntelligent crawling and indexing using lucene
Intelligent crawling and indexing using lucene
 
An introduction to inverted index
An introduction to inverted indexAn introduction to inverted index
An introduction to inverted index
 
Apache Solr/Lucene Internals by Anatoliy Sokolenko
Apache Solr/Lucene Internals  by Anatoliy SokolenkoApache Solr/Lucene Internals  by Anatoliy Sokolenko
Apache Solr/Lucene Internals by Anatoliy Sokolenko
 
Berlin Buzzwords 2013 - How does lucene store your data?
Berlin Buzzwords 2013 - How does lucene store your data?Berlin Buzzwords 2013 - How does lucene store your data?
Berlin Buzzwords 2013 - How does lucene store your data?
 
Introduction to solr
Introduction to solrIntroduction to solr
Introduction to solr
 
Architecture and Implementation of Apache Lucene: Marter's Thesis
Architecture and Implementation of Apache Lucene: Marter's ThesisArchitecture and Implementation of Apache Lucene: Marter's Thesis
Architecture and Implementation of Apache Lucene: Marter's Thesis
 
Lucene Introduction
Lucene IntroductionLucene Introduction
Lucene Introduction
 
The search engine index
The search engine indexThe search engine index
The search engine index
 
Lucene basics
Lucene basicsLucene basics
Lucene basics
 
Introduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of LuceneIntroduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of Lucene
 
Using Solr Cloud to Tame an Index Explosion
Using Solr Cloud to Tame an Index ExplosionUsing Solr Cloud to Tame an Index Explosion
Using Solr Cloud to Tame an Index Explosion
 
Lucece Indexing
Lucece IndexingLucece Indexing
Lucece Indexing
 
Scaling massive elastic search clusters - Rafał Kuć - Sematext
Scaling massive elastic search clusters - Rafał Kuć - SematextScaling massive elastic search clusters - Rafał Kuć - Sematext
Scaling massive elastic search clusters - Rafał Kuć - Sematext
 
Search Engine Powerpoint
Search Engine PowerpointSearch Engine Powerpoint
Search Engine Powerpoint
 

Architecture and implementation of Apache Lucene

  • 1. Architecture and implementation of Apache Lucene Kolloquium zur Masterarbeit Josiane Gamgo November 2010
  • 2. Agenda Motivation Apache Lucene Konzepte Überblick über die Komponenten Lucene Dokument Indizierung Index-Suche Case study: Solr 16.11.10 2
  • 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 16.11.10 3
  • 4. Apache Lucene 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 16.11.10 4
  • 5. Konzepte Lucene-Dokument Analyzer Indizierung QueryParser Indexsuche 16.11.10 5
  • 6. Überblick über die Komponenten 16.11.10 6
  • 7. Lucene Dokument: Architektur Übersicht 16.11.10 Lucene Dokument 7
  • 8. Feld: Eigenschaften 16.11.10 Lucene Dokument 8
  • 9. Boost factor Gibt mehr Bedeutung zu einem Feld oder einer Abfrage fcal.setBoost((float) 0.75); q.setBoost((float)0.5); 16.11.10 Lucene Dokument 9
  • 10. Daten Struktur: Beispiel 16.11.10 Lucene Dokument 10
  • 11. Erstellung eines Lucene-Dokuments Das DocumentHandler Interface Ein Dokumenten Parser. Z.B. : PDFBOx, SAX Eine Implementierung des DocumentHandlers Interface 16.11.10 Lucene Dokument 11
  • 12. Implementierung des DocumentHandlers interface 16.11.10 Lucene Dokument 12
  • 13. Implementierung des DocumentHandlers Interface public class PdfHandler implements DocumentHandler{ public Document getDocument(File originalFile) throws DocumentHandlerException { try { pdfdoc = PDDocument.load(originalFile);//load original document into a PDDocument 1 ... PDFTextStripper stripper = new PDFTextStripper(); StringWriter writer = new StringWriter(); 2 stripper.writeText(pdfdoc, writer); Calendar cal = metadata.getCreationDate(); PdfContents =writer.getBuffer().toString(); PDDocumentInformation metadata = pdfdoc.getDocumentInformation(); 3 Calendar cal = metadata.getCreationDate(); ... fcal = new Field("date of creation",String.valueOf(cal.get(Calendar.DAY_OF_WEEK)),Field.Store.YES,Field.Index.ANALYZED); 4 fcal.setOmitNorms(true); fcal.setBoost((float) 0.75); ... 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); ... 16.11.10 Lucene Dokument 13
  • 14. Indizierung: Komponenten Übersicht 16.11.10 14
  • 15. Analyzer: Die Strategie des IndexWriters 16.11.10 Indizierung 15
  • 16. Analyzer: Die Strategie des IndexWriters 16.11.10 Indizierung 16
  • 18. Tokenizer 16.11.10 Indizierung 18
  • 20. TokenFilter 16.11.10 Indizierung 20
  • 21. TokenFilter Beispiel: PorterStemFilter (condition)S1-> S2 Condition = (*V*)Y → i, ZB. • Z.b. Query → queri (m>0)ational → ate (m>1)ate → • Z.b. Informational → informationate → inform 16.11.10 Indizierung 21
  • 22. Erstellung eines Index Beispiel: Erstellung eines Index für zwei pdf Dateien: 16.11.10 Indizierung 22
  • 23. Erstellung eines Index terms(sorted) DocIds Extracted and DocIds analyzed terms all 1 all 1 assumption 1 literature 1 engines 2 shares 1 information 1 assumption 1 information 2 web 1 literature 1 searches 1 motivated 1 motivated 1 need 1 information 1 search 2 need 1 search 2 search 2 searches 1 engines 2 shares 1 uses 2 spider 2 spider 2 spiders 2 search 2 uses 2 spider 2 web 1 web 2 web 2 information 2 16.11.10 Indizierung 23
  • 24. Erstellung eines Index Terms Dictionary Posting lists Terms Dictionary Posting lists (term,tfq) ( stemmed terms,tfq) all 1 1 all 1 1 assumption 1 1 assumpt 1 1 engines 1 2 engin 1 2 information 2 1,2 inform 2 1,2 literature 1 1 literatur 1 1 motivated 1 1 need 1 1 motiv 1 1 search 2 2 need 1 1 searches 1 1 search 3 1,2 shares 1 1 share 1 1 spider 1 2 spider 2 2 spiders 1 2 us 1 2 uses 1 2 web 2 1,2 web 2 1,2 16.11.10 Indizierung 24
  • 25. Indizierungsalgorithmen: IR Versus Lucene Indizierungsalgorithmen in Information Retrieval(IR) Suffix arrays Signature Files Inverted Files Lucene Indizierungsalgorithmus Basis-Algorithmus Inkrementell-Algorithmus. 16.11.10 Indizierung 25
  • 26. Lucene Indizierungsalgorithmus Quelle:http://lucene.sourceforge.net/talks/pisa 16.11.10 Indizierung 26
  • 28. Index Optimierung Lucene benutzte Puffer kontrollieren: MergeFactor minMergeDocs maxMergeDocs Zuerst den Index in den Arbeitspeicher speichern IndexWriter.optimize() IndexWriter.MaxFieldLength 16.11.10 Indizierung 28
  • 29. Index Datentypen 16.11.10 Indizierung 29
  • 31. Lucene Abfrage Sprache (Query Language) Hat eine Grammatik: Query ::=(clause)* Clause ::=[“+”,”-”][<TERM>”:”](<TERM>| “(“Query”)”) Definiert die Syntax eines Lucene Query Token 16.11.10 Index Suche 31
  • 32. Lucene Query: Beispiel „web AND search“ 16.11.10 Index Suche 32
  • 33. Benutzung der Index für Die Suche 16.11.10 Index Suche 33
  • 34. Index Search Algorithmus Quelle: http://lucene.sourceforge.net/papers/riao97.ps 16.11.10 Index Suche 34
  • 35. Lucene Retrieval Modell Ist eine Kombination von Boolean Model und Vector space model Boolean Model: Beispiel query = “Web AND search” 16.11.10 Index Suche 35
  • 36. Lucene Retrieval Modell Vector space model Erfunden 1945 by Gerard Salton Prinzip: 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: 16.11.10 Index Suche 36
  • 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 16.11.10 Index Suche 37
  • 38. Lucene Formel zur Berechnung der Such Ergebnisse Coord(q,d)= tfiq, für ein Begriff I in then query q queryNorm(q)= Wiq x t.getBoost() t.getBoost() ist der Boost factor, der für den Query definiert ist norm(t,d) enthält länge und boost für jedes Field 16.11.10 Index Suche 38
  • 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. 16.11.10 39
  • 40. Case Study: Solr Quelle: http://www.typo3-solr.com/en/what-is-solr/ 16.11.10 40
  • 41. Danke für Ihre Aufmerksamkeit ! 16.11.10 41