SlideShare a Scribd company logo
Elasticsearch for Pharo Smalltalk
Smalltalkで全文検索
Sho Yoshida / @newapplesho
SORABITO Inc.
2016/01/29 第84回Smalltalk勉強会
About
• Sho Yoshida
• SORABITO Inc. で働いています
• 働く機械の国際オンライン取引所 ALLSTOCKER ( https://allstocker.com) を作ってい
ます
おかげさまで160カ国以上からアクセスが来ております
こんなものを扱っています
第75回Smalltalk勉強会の話
• 第75回Smalltalk勉強会で今後やりたいことの1つに「全文検索」
• http://www.smalltalk-users.jp/Home/gao-zhi/dai75kaismalltalkbenkyoukai
• RDS PostgreSQLを使っているので、日本語の全文検索ができない
• 日英の全文検索をサポートしなければならない
https://www.elastic.co/products/elasticsearch
Elasticsearchとは
• Apache Luceneベースの全文検索エンジン、 解析サーバー
• スキーマレス、ドキュメント指向
• RESTで操作できる
• クラスタリングも想定しているので、基本的な設定は容易?
• ライセンスは Apache License v2
• Javaで実装
• ファセット、ハイライト検索も可能
事例
• GitHub
• foursquare
• SoundCloud
• stackoverflow
• ALLSTOCKER
GitHubを使って見る
https://github.com
全文検索とElasticsearch
Elasticsearchは転置インデックス(単語とドキュメントIDを辞書にして、検索する)
https://speakerdeck.com/johtani/introduction-elasticsearch-and-elk-
elasticsearchmian-qiang-hui-in-nagoya
詳しくは
データ構造
RDB = Database -> Tables -> Rows -> Columns
ElasticSearch = Index -> Types -> Documents -> Fields
そもそも全くことなるので比べるのも変ですが・・・・
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系は未対応
Elasticsearch for Pharo Smalltalk
• 拡張が難しいのを改善
• Aggregation, Query系を一新した
Elasticsearchのインストール
1.wget https://download.elasticsearch.org/….
2.tar -xf elasticsearch-1.7.2.tar.gz
3../elasticsearch-1.7.2/bin/elasticsearch
Kuromojiのinstall
日本語の形態素解析エンジン
bin/plugin install elasticsearch/elasticsearch-analysis-kuromoji/2.5.0
Elasticsearch-inquisitorプラグインのインストール
bin/plugin -install polyfractal/elasticsearch-inquisitor
http://localhost:9200/_plugin/inquisitor/#/
Elasticsearch-inquisitor GUIからQueryを実行できるプラグイン
起動確認
$ 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"
}
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.
または
インデックス作成とマッピングの設定
curl -XPUT 'localhost:9200/st_study' -d @sushi.json
Kuromojiの動作確認
curl -XPOST 'http://localhost:9200/st_study/
_analyze?analyzer=analyzer&pretty=true' -d '油圧ショベルは建設
機械'
Kuromojiの動作確認結果 {
"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
} ]
}
Sample Data
"properties": {
"title": {
"type": "string",
"store": "yes",
"index": "not_analyzed"
},
"description": {
"type": "string",
"store": "yes",
"index": "analyzed"
},
"price": {
"type": "integer",
"store": "yes"
}
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)
ドキュメントの追加
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.
ドキュメントの削除
esDocument := ESDocument new id:'AVKMOVs3-FeOW1ziNoOb';
type:'store'; content: neta.
esDocument deleteFromIndex: index.
インデックスの削除
index delete.
全件検索
"Match All"
index := ESIndex indexNamed: 'st_study'.
search := ESSearch new; index: index.
query := ESMatchAllQuery new.
search query: query.
results := search search.
results explore.
全件検索(ページング)
"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.
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.
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.
ソート
"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.
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.
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.
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.
DEMO
今後の予定
• Elasticsearch 2.0に対応予定
準備は整った
さあSmalltalkを書こう
paul bica https://www.flickr.com/photos/dexxus/5820866907/

More Related Content

PDF
3. javascript bangla tutorials
PDF
I Don't Care About Security (And Neither Should You)
PDF
I Don't Care About Security (And Neither Should You)
PDF
Five Things you Need to Know About Scaling
PPTX
Pry, the good parts
PPTX
User registration and login using stored procedure in php
PDF
Ben Bridts - $ aws help
PPTX
Google says you shouldn’t visit my church
3. javascript bangla tutorials
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)
Five Things you Need to Know About Scaling
Pry, the good parts
User registration and login using stored procedure in php
Ben Bridts - $ aws help
Google says you shouldn’t visit my church

What's hot (6)

KEY
Hidden treasures of Ruby
PDF
Defcon 22-blake-self-cisc0ninja-dont-ddos-me-bro
PDF
Defcon 22-graham-mc millan-tentler-masscaning-the-internet
PPTX
Setup testdata
PPTX
Twas the night before Malware...
PDF
Eric Redmond – Distributed Search on Riak 2.0 - NoSQL matters Barcelona 2014
Hidden treasures of Ruby
Defcon 22-blake-self-cisc0ninja-dont-ddos-me-bro
Defcon 22-graham-mc millan-tentler-masscaning-the-internet
Setup testdata
Twas the night before Malware...
Eric Redmond – Distributed Search on Riak 2.0 - NoSQL matters Barcelona 2014
Ad

More from Sho Yoshida (16)

PDF
OpenRestyを用いてイケイケなサービスを作る方法
PDF
Continuous Integration for Pharo Smalltalk Part 2 (Smalltalk and Travis CI)
PDF
今時なウェブ開発をSmalltalkでやってみる?
PDF
Continuous Integration for Pharo Smalltalk - Smalltalkと継続的インテグレーション
PDF
Source Code Management with Pharo Smalltalk - Pharo Smalltalkソースコード管理方法
PDF
RUNNING Smalltalk - 実践Smalltalk
PDF
AWS SDK for Smalltalk
PDF
How Smalltalker Works
PDF
Smaltalk驚異の開発(私が使い続ける2012年の話)
PDF
愛せよ、さもなくば捨てよ。
PDF
情熱Smalltalker SmalltalkとAWSでクラウドサービスを実現するための挑戦
PDF
もしイチゴ農家の園主がSmalltalkの「Seaside」(で作られたシステム)を使ってみたら
PDF
エコSmalltalk
PDF
今日から使おうSmalltalk
PDF
Iliad or Seaside
PDF
Pharo(Smalltalk)でAPI作りをはじめよう
OpenRestyを用いてイケイケなサービスを作る方法
Continuous Integration for Pharo Smalltalk Part 2 (Smalltalk and Travis CI)
今時なウェブ開発をSmalltalkでやってみる?
Continuous Integration for Pharo Smalltalk - Smalltalkと継続的インテグレーション
Source Code Management with Pharo Smalltalk - Pharo Smalltalkソースコード管理方法
RUNNING Smalltalk - 実践Smalltalk
AWS SDK for Smalltalk
How Smalltalker Works
Smaltalk驚異の開発(私が使い続ける2012年の話)
愛せよ、さもなくば捨てよ。
情熱Smalltalker SmalltalkとAWSでクラウドサービスを実現するための挑戦
もしイチゴ農家の園主がSmalltalkの「Seaside」(で作られたシステム)を使ってみたら
エコSmalltalk
今日から使おうSmalltalk
Iliad or Seaside
Pharo(Smalltalk)でAPI作りをはじめよう
Ad

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Encapsulation theory and applications.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Electronic commerce courselecture one. Pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Encapsulation_ Review paper, used for researhc scholars
Network Security Unit 5.pdf for BCA BBA.
Building Integrated photovoltaic BIPV_UPV.pdf
Understanding_Digital_Forensics_Presentation.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Encapsulation theory and applications.pdf
Approach and Philosophy of On baking technology
Electronic commerce courselecture one. Pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MIND Revenue Release Quarter 2 2025 Press Release
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
20250228 LYD VKU AI Blended-Learning.pptx
Spectroscopy.pptx food analysis technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Digital-Transformation-Roadmap-for-Companies.pptx
Review of recent advances in non-invasive hemoglobin estimation
Mobile App Security Testing_ A Comprehensive Guide.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Elasticsearch for Pharo Smalltalk