Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Elastic Searching With PHP

4.198 Aufrufe

Veröffentlicht am

Veröffentlicht in: Technologie
  • ⇒⇒⇒WRITE-MY-PAPER.net ⇐⇐⇐ has really great writers to help you get the grades you need, they are fast and do great research. Support will always contact you if there is any confusion with the requirements of your paper so they can make sure you are getting exactly what you need.
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • These are one of the best companies for review articles. High quality with cheap rates. ⇒⇒⇒WRITE-MY-PAPER.net ⇐⇐⇐ I highly recommend it :)
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • I'd advise you to use this service: ⇒ www.HelpWriting.net ⇐ The price of your order will depend on the deadline and type of paper (e.g. bachelor, undergraduate etc). The more time you have before the deadline - the less price of the order you will have. Thus, this service offers high-quality essays at the optimal price.
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • Worldwide New Products: https://saidbenrida.blogspot.com/ https://saidbenrida-best.blogspot.com/ https://saidbenrida-opp.blogspot.com/ https://saidbenrida-recommended.blogspot.com/ https://saidbenrida-trusted.blogspot.com/ https://trusted-saidbenrida.blogspot.com/ http://www.saidbenrida.ws/ https://ewallet-worldwide.tumblr.com/ https://concsaid.blogspot.com/ https://copsaid.blogspot.com/ https://domasaid.blogspot.com/ https://hostsaid.blogspot.com/ https://paysaid.blogspot.com/ https://wsmoney.blogspot.com/
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • You can hardly find a student who enjoys writing a college papers. Among all the other tasks they get assigned in college, writing essays is one of the most difficult assignments. Fortunately for students, there are many offers nowadays which help to make this process easier. The best service which can help you is ⇒ www.WritePaper.info ⇐
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier

Elastic Searching With PHP

  1. 1. Elastic Searching WithPHPLea Hänsenberger - @lea_hLiip AG – Agile Web Development – Fribourg, Zürich, Bern
  2. 2. About me – work lifesmartvote.chWeb Developer at Liip AG for 3 years
  3. 3. About me – the other lifeAerobatics Paragliding Pilot
  4. 4. ElasticaFOSElasticaBundle
  5. 5. elasticsearchLuceneFull textsearchDocument orientedRESTfulAPISchema freehttp://elasticsearch.org
  6. 6. elasticsearch – full textsearchBased on Lucene„Apache LuceneTM is a high-performance, full-featuredtext search engine library written entirely in Java. It isa technology suitable for nearly any application thatrequires full-text search, especially cross-platform.“
  7. 7. elasticsearch – full textsearchMulti-language supportGeolocationDid-you-mean suggestionsAutocompleteand a lot more...
  8. 8. elasticsearch – documentorientedEntities as structured JSON documentsAll fields indexed by default{"field" : "value"}
  9. 9. elasticsearch – schema freeAll fields indexed by defaultDetecting data structure{"name" : "Peter","age" : 22}
  10. 10. elasticsearch – RESTful APIJSON over HTTP
  11. 11. elasticsearch – RESTful API–Add/update document$ curl -XPUT http://localhost:9200/phpday/speaker/1-d {"firstname" : "John","lastname" : "Doe","speeches" : 2}{"ok" : true,"_index" : "phpday","_type" : "speaker","_id" : "1","_version" : 1}RequestResponse
  12. 12. elasticsearch – RESTful API–Delete document$ curl -XDELETE http://localhost:9200/phpday/speaker/1{"ok" : true,"_index" : "phpday","_type" : "speaker","_id" : "1","found" : true}RequestResponse
  13. 13. elasticsearch – RESTful API–Field Mapping$ curl -XPUT http://localhost:9200/phpday/speaker/_mapping-d {"speaker" : {"properties" : {"firstname" : { "type" : "string" },"lastname" : { "type" : "string" },"speeches" : { "type" : "integer" }}}}
  14. 14. elasticsearch – RESTful API–Search$ curl -XGET http://localhost:9200/phpday/speaker/_search-d {"query":{"bool":{"should":[{"query_string":{"default_field":"_all","query":"John"}}]}}}Request
  15. 15. elasticsearch – RESTful API–Search{..."hits":{..."hits":[{..."_source":{"firstname":"John","lastname":"Doe","speeches":2}}]}}Response
  16. 16. Elasticsearch - ToolsBrowser/Queryinghttp://mobz.github.io/elasticsearch-head/
  17. 17. Elasticahttp://elastica.ioPHP client
  18. 18. elastica - Connect$elasticaClient = new ElasticaClient();$elasticaClient = new ElasticaClient(array(host => otherhost.org,port => 12345,));
  19. 19. elastica - Prepare// Load index$elasticaIndex = $elasticaClient->getIndex(phpday);// Create a type$elasticaType = $elasticaIndex->getType(speaker);
  20. 20. elastica – Add/updatedocument$doc = new ElasticaDocument(1, array(firstname => John,(...)));$elasticaType->addDocument($doc);$elasticaIndex->refresh();
  21. 21. elastica – Bulk indexing/* @var array ElasticaDocument */$docs = array();$docs[] = ...$elasticaType->addDocuments($docs);$elasticaIndex->refresh();
  22. 22. elastica – Add object$elasticaType->setSerializer($callable);$elasticaType->addObject($object, $elasticaDoc);Configure serializer Object -> ArrayAdd objects directly
  23. 23. elastica – Delete document(s)$elasticaType->deleteDocument($elasticaDoc);$elasticaType->deleteById($id);$elasticaType->deleteIds($ids);$elasticaType->deleteByQuery($elasticaQuery);
  24. 24. elastica – Field mapping$mapping = new ElasticaTypeMapping();$mapping->setType($elasticaType);$mapping->setProperties(array(firstname => array(type => string),(...)));$mapping->send();Index must exist!
  25. 25. elastica – Search$elasticaQueryString = new ElasticaQueryQueryString();$elasticaQueryString->setQuery(John);Define the query
  26. 26. elastica – Search$elasticaQuery = new ElasticaQuery();$elasticaQuery->setQuery($elasticaQueryString);$resultSet = $elasticaType->search($elasticaQuery);Create the actual search objectSearch on type or index
  27. 27. elastica – Search$elasticaQuery->setFilter($elasticaFilter);$elasticaQuery->addFacet($elasticaFacet);...Filters, facets, etc. are added to the search object
  28. 28. FOSElasticaBundleSymfony 2 Bundlehttp://git.io/foselasticabundleelastica
  29. 29. FOSElasticaBundleMoved to FOS namespace recentlyFormerly known as FOQElasticaBundle
  30. 30. FOSElasticaBundle –Configurationfos_elastica:clients:default: { host: localhost, port: 9200 }indexes:phpday:client: defaulttypes:speaker: ~
  31. 31. FOSElasticaBundle –Add/update documentsAutomatic provider for Doctrine, MongoDB, PropelManual provideror: just use elastica
  32. 32. FOSElasticaBundle –Add/update – AutomaticConfig:! Mapping requiredfos_elastica:...speaker:mappings:firstname: {type: string}persistence:driver: ormmodel: LiipPhpdayBundleEntitySpeakerprovider: ~
  33. 33. FOSElasticaBundle –Add/update – AutomaticRun command:$ app/console fos:elastica:populate
  34. 34. FOSElasticaBundle –Add/update – AutomaticSpeakerRepository::getSpeakers() returnsQueryBuilderNo propel support yet!fos_elastica:...speaker:...persistence:...provider:query_builder_method: getSpeakers
  35. 35. FOSElasticaBundle –Add/update – ManualProviderRemove persistence configurationDefine service for provider classservices:liip_phpday.search_provider.speaker:class: LiipPhpdayBundleProviderSpeakerProvidertags:- {name: fos_elastica.provider,index: phpday,type: speaker}arguments: [ @fos_elastica.index.phpday.speaker ]
  36. 36. FOSElasticaBundle –Add/update – ManualProviderManually create and add elastica documentsclass SpeakerProvider implements ProviderInterface{function populate(Closure $loggerClosure = null){...}}
  37. 37. FOSElasticaBundle –Delete DocumentUse elastica directlyor: use populate command to completely reindex
  38. 38. FOSElasticaBundle – SearchUsing elastica/** var ElasticaType */$speakerType = $this->container->get(fos_elastica.index.phpday.speaker);/** var ElasticaResultSet */$results = $speakerType->search(MariaSymfony);
  39. 39. FOSElasticaBundle – SearchGetting back Doctrine/Propel Entitiesfos_elastica:...mappings: ...persistence:driver: ormmodel: LiipPhpdayBundleEntitySpeakerprovider: ~finder: ~
  40. 40. FOSElasticaBundle – SearchGetting back Doctrine/Propel Entities/** var FOSElasticaBundleFinderTransformedFinder */$finder = $this->container->get(fos_elastica.finder.phpday.speaker);/** var array of LiipPhpdayBundleEntitySpeaker */$speakers = $finder->find(MariaSymfony);
  41. 41. FOSElasticaBundle – SearchCustom queriesfos_elastica:...mappings: ...persistence:driver: ormmodel: LiipPhpdayBundleEntitySpeakerprovider: ~finder: ~repository: ...SearchSpeakerRepository
  42. 42. FOSElasticaBundle – SearchCustom queriesclass SpeakerRepository extends FOSElasticaBundleRepository{public function findWithCustomQuery($searchTerm){// build query with Elastica objectsreturn $this->find($searchTerm);}}
  43. 43. FOSElasticaBundle – SearchCustom queries/** var FOSElasticaBundleManagerRepositoryManager */$repositoryManager = $this->container->get(fos_elastica.manager);/** var FOSElasticaBundleRepository */$repository = $repositoryManager->getRepository(LiipPhpdayBundle:Speaker);/** var array of LiipPhpdayBundleEntitySpeaker */$results = $repository->findWithCustomQuery(MariaSymfony);
  44. 44. FOSElasticaBundle – Andmore...Live index updatesAdvanced elasticsearch configurationPaged search...=> http://git.io/foselasticabundle
  45. 45. ElasticaFOSElasticaBundle?

×