Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Elasticsearch for Pharo Smalltalk

Elasticsearch for Pharo Smalltalk

Elasticsearch for Pharo Smalltalk. Smalltalkで全文検索

newapplesho

January 29, 2016
Tweet

More Decks by newapplesho

Other Decks in Programming

Transcript

  1. Elasticsearchͱ͸ • Apache LuceneϕʔεͷશจݕࡧΤϯδϯɺ ղੳαʔόʔ • εΩʔϚϨεɺυΩϡϝϯτࢦ޲ • RESTͰૢ࡞Ͱ͖Δ •

    ΫϥελϦϯά΋૝ఆ͍ͯ͠ΔͷͰɺجຊతͳઃఆ͸༰қʁ • ϥΠηϯε͸ Apache License v2 • JavaͰ࣮૷ • ϑΝηοτɺϋΠϥΠτݕࡧ΋Մೳ
  2. σʔλߏ଄ RDB = Database -> Tables -> Rows -> Columns

    ElasticSearch = Index -> Types -> Documents -> Fields ͦ΋ͦ΋શ͘͜ͱͳΔͷͰൺ΂Δͷ΋มͰ͕͢ɾɾɾɾ
  3. Elasticsearch for Pharo Smalltalk • Paul DeBruicker ͕࡞ͬͨElasticsearchͷϑΥʔΫϓϩδΣΫτ • http://ss3.gemtalksystems.com/ss/Elasticsearch.html

    • ࡞ऀ: @umejava, @newapplesho • ࠷৽ϦϙδτϦ͸GitHub • https://github.com/newapplesho/elasticsearch-smalltalk • Elasticsearch version 1ܥ͸αϙʔτɻ2ܥ͸ະରԠ
  4. ىಈ֬ೝ $ curl localhost:9200 { "status" : 200, "name" :

    "Lilandra Neramani", "cluster_name" : "elasticsearch", "version" : { "number" : "1.7.2", "build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec", "build_timestamp" : "2015-09-14T09:49:53Z", "build_snapshot" : false, "lucene_version" : "4.10.4" }, "tagline" : "You Know, for Search" }
  5. elasticsearch for Pharo SmalltalkΛinstall Gofer new url: 'http://ss3.gemtalksystems.com/ss/Elasticsearch'; package: 'ConfigurationOfElasticsearch';

    load. (Smalltalk at: #ConfigurationOfElasticsearch) load. Metacello new baseline: 'Elasticsearch'; repository: 'github://newapplesho/elasticsearch-smalltalk:v1.1.3/pharo-repository'; load. ·ͨ͸
  6. ,VSPNPKJͷಈ࡞֬ೝ݁Ռ { "tokens" : [ { "token" : "༉ѹ", "start_offset"

    : 0, "end_offset" : 2, "type" : "word", "position" : 1 }, { "token" : "γϣϕϧ", "start_offset" : 2, "end_offset" : 6, "type" : "word", "position" : 2 }, { "token" : "͸", "start_offset" : 6, "end_offset" : 7, "type" : "word", "position" : 3 }, { "token" : "ݐઃ", "start_offset" : 7, "end_offset" : 9, "type" : "word", "position" : 4 }, { "token" : "ػց", "start_offset" : 9, "end_offset" : 11, "type" : "word", "position" : 5 } ] }
  7. Sample Data "properties": { "title": { "type": "string", "store": "yes",

    "index": "not_analyzed" }, "description": { "type": "string", "store": "yes", "index": "analyzed" }, "price": { "type": "integer", "store": "yes" }
  8. Sample (Seaside Example Sushi Store) #('Akami Maguro' 'Red Tuna' 'The

    lean meat near the spine of the tuna fish. It comes in various shades of red--with the lighter, shinier varieties being the best. For dieters, however, the redder the better. Easy on the palatte. The least expensive of the thre types of maguro.' 150)
  9. υΩϡϝϯτͷ௥Ճ neta := JsonObject new. neta title:'Aji'; description:'This fish is

    pink-grey and shiny. When it''s fresh, the flesh is almost transparent. The texture is slippery and easy on the tongue--it should melt in your mouth. Aji is often eaten with soy sauce containing onion, ginger and garlic.' esDocument := ESDocument new type:'store'; content: neta. index addDocument: esDocument.
  10. શ݅ݕࡧ "Match All" index := ESIndex indexNamed: 'st_study'. search :=

    ESSearch new; index: index. query := ESMatchAllQuery new. search query: query. results := search search. results explore.
  11. શ݅ݕࡧʢϖʔδϯάʣ "Match All" index := ESIndex indexNamed: 'st_study'. search :=

    ESSearch new index: index. query := ESMatchAllQuery new. search query: query. results := search searchFrom: 0 size:2. results explore.
  12. Match Query "Match" index := ESIndex indexNamed: 'st_study'. search :=

    ESSearch new; index: index. query := ESMatchQuery new. query query:'aji'. search query: query. results := search search. results explore.
  13. Term Query "ESTermQuery" index := ESIndex indexNamed: 'st_study'. search :=

    ESSearch new index: index. query := ESTermQuery new field:'title'; query:'Aji'. search query: query. results := search search. results explore.
  14. ιʔτ "sort" index := ESIndex indexNamed: 'st_study'. search := ESSearch

    new; index: index. query := ESTermQuery new field:'title'; query:'Aji'. sort := ESSortCriteria new fieldName: 'title'; sortDescending; yourself. search query: query. search addSortCriteria: sort. results := search search. results explore.
  15. Aggregations "min Aggregations" index := ESIndex indexNamed: 'st_study'. search :=

    ESSearch new; index: index. query := ESMatchAllQuery new. aggregation := ESMinAggregation new field:'price'. search query: query. search addAggregation: aggregation. result := search aggregate.
  16. Aggregations "max Aggregations" index := ESIndex indexNamed: 'st_study'. search :=

    ESSearch new; index: index. query := ESMatchAllQuery new. aggregation := ESMaxAggregation new field:'price'. search query: query. search addAggregation: aggregation. result := search aggregate.
  17. Aggregations "avg Aggregations" index := ESIndex indexNamed: 'st_study'. search :=

    ESSearch new; index: index. query := ESMatchAllQuery new. aggregation := ESAvgAggregation new field:'price'. search query: query. search addAggregation: aggregation. result := search aggregate.