$30 off During Our Annual Pro Sale. View Details »

Solr für Volltext-Suche oder gleich als Datenbank Engine

Frank Neff
October 30, 2014

Solr für Volltext-Suche oder gleich als Datenbank Engine

Slides zum Talk an der Symfony Live Konferenz in Berlin 2014

Frank Neff

October 30, 2014
Tweet

More Decks by Frank Neff

Other Decks in Programming

Transcript

  1. Solr für Volltext-Suche
    oder gleich als Datenbank Engine
    Frank Neff
    Symfony Live Berlin 2014
    #sfLiveSolr

    View Slide

  2. Über mich
    Frank Neff
    ■ Software Engineer @ YMC AG
    ■ Lebt in Zurich, Schweiz
    ■ Codet PHP und Java
    ■ Student
    ■ Open Source Enthusiast
    ■ Multicopter Drohne Pilot
    ■ Hobby-Fotograf
    ■ frankneff.ch
    ■ ymc.ch

    View Slide

  3. View Slide

  4. Open Source
    Switzerland
    Agile
    Since 2001
    Conferences
    International
    Software solutions
    Best of swiss web
    Über YMC

    View Slide

  5. Mehr Daten...

    View Slide

  6. ...langsame Suche

    View Slide

  7. “If all you have is a
    hammer, everything
    looks like a nail”
    - Abraham Maslow

    View Slide

  8. View Slide

  9. ● Such-Server (Reverse Index)
    ● Basiert auf Apache Lucene
    ● Standalone oder Cluster
    ● Skalierbar
    ● Unterstützt diverse Formate
    ● Stemmer, Stopwords, Facettierung
    ● Gewichtung von Feldern

    View Slide

  10. “Solr wird mit mehr
    Daten nicht markant
    langsamer...”

    View Slide

  11. Funktionsweise
    Solr Index

    View Slide

  12. Textfeld: “This example shows how SOLR's
    tokenizing/indexing works…”
    Such-String: “How-To Solr tokenization”
    Beispiel Indexierung

    View Slide

  13. View Slide

  14. Stop Filter
    Lower Case Filter
    English Possessive
    Filter
    Porter Stem Filter

    View Slide

  15. Gespeicherter Index
    Token Index
    biz 2
    example 1
    hard 2,3
    how 1,3
    index 1,3
    show 1,2
    solr 1,3
    work 1,2,3
    Index Document
    1 This example shows how SOLR's tokenizing/indexing works...
    2 Show-biz is hard work!
    3 How hard is the work with a solr index?
    *stark vereinfacht

    View Slide

  16. Query Matching

    View Slide

  17. ■ ~500’000 Wörter (Duden)
    ■ = max. Index-Tokens
    ■ Wachstum des Indexes
    verringert sich / bleibt
    konstant
    ■ Suche wird nicht langsamer
    Anzahl Artikel
    Index Grösse
    Index Grösse

    View Slide

  18. in PHP
    Integration

    View Slide

  19. ■ Grundlegende C-Extension für Indexierung und Abfrage
    ■ http://pecl.php.net/package/solr
    ■ http://php.net/manual/de/book.solr.php
    pecl/php_solr

    View Slide

  20. ■ Feature-Complete Solr Library

    Geschrieben in PHP

    Facet support

    Query building API

    Plugin system

    DisMax support
    ■ http://www.solarium-project.org/
    Solarium

    View Slide

  21. Solarium Beispiel

    View Slide

  22. Symfony 2
    Konzepte in

    View Slide

  23. ■ Volltextsuche
    ■ MySQL entlasten
    ■ Document Store
    ■ Polyglot-Persistence?
    Einsatzmöglichkeiten in Symfony 2

    View Slide

  24. Volltextsuche

    View Slide

  25. Volltextsuche
    MySQL Solr
    App
    index
    persist
    /search
    query
    /create
    ...
    /article/42
    result
    query
    result

    View Slide

  26. ■ Solr NRT-Search verwenden
    ■ Indexierung “onPostPersist”
    ■ Komplexe Queries
    ■ Keine Datenbank-Last
    Volltextsuche

    View Slide

  27. Fixture

    View Slide

  28. Controller

    View Slide

  29. Repository

    View Slide

  30. MySQL entlasten

    View Slide

  31. MySQL entlasten
    Copying to tmp table…



    View Slide

  32. MySQL entlasten
    MySQL Solr
    App
    index
    persist
    related
    articles
    query
    /create
    ...
    /article/42
    result
    article content query
    result

    View Slide

  33. ■ Komplexe Queries
    ■ Operationen die “Full-Table-Scans” auslösen
    ■ Between Abfragen
    ■ Geo-Koordinaten
    ■ Sortierte Listen
    ■ Keine Datenbank-Last
    MySQL entlasten

    View Slide

  34. Document Store

    View Slide

  35. Document Store
    Solr
    App
    persist
    ordered / grouped list
    /create
    ...
    /incident/list
    result
    /search
    fulltext search
    result

    View Slide

  36. ■ nelmio/solarium-bundle
    ■ Schnelle Abfragen
    ■ Sortierte Listen
    ■ Volltextsuche “out of the box”
    ■ Geeignet für grosse Dokumentarchive
    ■ Keine Relationen
    Document Store

    View Slide

  37. Keine Relationen?

    View Slide

  38. ■ Solr ist kein RDBMS!
    ■ Hält viele Daten, unterstützt aber keine Strukturen
    ■ Optionen

    Denormalisierung

    Object-Hydration (bspw. über Doctrine ORM)

    Polyglot-Persistence
    Relationen

    View Slide

  39. Object-Hydration
    MySQL Solr
    App
    persist
    /create /article/42
    article
    User Artikel
    user by
    article
    index
    [hydrator]
    query
    result
    article + user

    View Slide

  40. ■ floriansemm/solr-bundle
    ■ Hydration über Solr-Index oder RDBMS
    ■ Entity Annotation Support
    ■ Indexierung anhand von Doctrine-Events
    ■ Unterstützt Doctrine ORM/ODM
    Object-Hydration

    View Slide

  41. Entity Annotation

    View Slide

  42. Entity Annotation

    View Slide

  43. Entity Annotation

    View Slide

  44. Repository

    View Slide

  45. Polyglot Persistence

    View Slide

  46. Polyglot Persistence
    Neo4j Solr
    App
    persist data
    persist structure
    data
    query
    /create
    ...
    /article/42
    result
    structure query
    result

    View Slide

  47. ■ Trennung von Daten und Struktur
    ■ Synchronisierung auf Business-Logik Level
    ■ Noch kein OSS-Bundle
    Polyglot Persistence

    View Slide

  48. Query Language
    The Lucene

    View Slide

  49. "A search string"
    Simple Query
    Query all
    Fields

    View Slide

  50. title:"The Right Way" AND text:go
    Fields
    Field Name

    View Slide

  51. title:"te?t" AND text:*test*
    Wildcard search
    Single
    Character
    Wildcard
    String

    View Slide

  52. text:roam~0.8
    Fuzzy search
    Levenshtein
    Distance

    View Slide

  53. text:"solr apache"~10
    Proximity search
    Word
    Distance

    View Slide

  54. mod_date:[20020101 TO 20030101]
    Numeric Range

    View Slide

  55. title:{Aida TO Carmen}
    String Range

    View Slide

  56. text:"solr^4 apache"
    Term boosting
    Boost Factor

    View Slide

  57. "Apache Solr" NOT "Webserver"
    Exclusion
    Exclude
    Result

    View Slide

  58. (nginx OR apache) AND webserver
    Grouping

    View Slide

  59. coole Features
    Noch mehr

    View Slide

  60. ■ Cluster-Betrieb
    ■ High Availability
    ■ Fault Tolerance
    ■ Konfigurationsmanagement mit Zookeeper
    ■ Benötigt Solr 4
    ■ cwiki.apache.org/confluence/x/ioDxAQ
    Solr Cloud

    View Slide

  61. ■ Eingrenzung von Resultaten
    anhand verschiedener Filter
    ■ A.k.a Explorative Suche
    ■ Benutzer kann Filter selbst
    wählen und verknüpfen
    ■ wiki.apache.org/solr/SolrFacetingOverview
    Faceting

    View Slide

  62. ■ nelmio/NelmioSolariumBundle
    ■ floriansemm/SolrBundle
    ■ swiss-php-friends/solr-query-builder
    ■ frne/symfony-solr-playground
    Try it out!

    View Slide

  63. Web Solutions
    Big Data Analytics
    Mobile
    Fragen ?
    Input ?

    View Slide

  64. Web Solutions
    Big Data Analytics
    Mobile
    Danke ;)
    @frank_neff
    www.frankneff.ch
    www.ymc.ch
    github.com/frne
    speakerdeck.
    com/frne
    Bilder
    1. http://bigdata.globant.com/?p=629
    2. http://www.ecloudtimes.com/reduce-blog-loading-time/
    3. http://grabcad.com/
    4. http://www.colbenson.com/-/apache-solr-course-in-bilbao-
    tomorrow
    5. http://www.solarium-project.org/
    6. http://office-lernen.com/
    7. https://forums.zarafa.com/
    8. https://plus.google.com/+RecordxpressCa/posts
    9. https://www.simple-talk.com/sql
    10. http://cloudconceptgroup.com/
    11. http://www.digitec.ch

    View Slide