Solr勉強会
- 2. 自己紹介
• 柳吾朗
• 株式会社マーズフラッグに勤務
• 研究開発部に所属
• 主にサイト内検索エンジン MARS FINDERの開
発
• 本日の目的
1. 皆様への恩返し
• Solr勉強会の資料にはお世話になっています(でも参加はなか
なか出来ませんでした。。)
2. 会社の宣伝
• 人材募集中です(人脈つくりの下心。飲み会楽しみにしています!)
© 2012 MARS FLAG Corporation. All rights reserved. 2
- 3. 株式会社マーズフラッグ
• 検索エンジンを中心とした ASP ベンダー
です。
• Webクローラーなどの周辺技術も使って、
色々やっています。
• Solr にも大注目中です。Solrを使ったアプ
リケーションも作成中です。
© 2012 MARS FLAG Corporation. All rights reserved. 3
- 4. ネタは色々考えたのですが
• ドリルダウン
• サジェストともしかして
• 順位調整の色々
• Solr Core マネージメント
• スケーラビリティとパフォーマンス
© 2012 MARS FLAG Corporation. All rights reserved. 4
- 7. Droll Downとは?
In information technology, to drill down means to
move from summary information to detailed data
by focusing in on something.
Wikipedia
何かの要素に着目し、
概要情報から詳細情報に移動すること。
© 2012 MARS FLAG Corporation. All rights reserved. 7
- 10. Solrではどうやるの?
Facet と Filter Query を組み合わせて行うのが
一般的
/select?q=<検索キーワード>
&fq=<絞り込み用field>:<絞り込みた
い値>
&facet=true
&facet.field=<集計したいfield>
© 2012 MARS FLAG Corporation. All rights reserved. 10
- 11. 先ほどの例をSolrのクエリで実現しようとす
ると
/select?q=ケーブル
&fq=category1:パソコン・周辺機器
&facet=true
&facet.field=category2
© 2012 MARS FLAG Corporation. All rights reserved. 11
- 12. さらに絞り込むとしたら。。。
/select?q=ケーブル
&fq=category1:パソコン・周辺機器
&fq=category2:ウルトラブック
&facet=true
&facet.field=category3
© 2012 MARS FLAG Corporation. All rights reserved. 12
- 17. Solrのクエリで実現しようとすると。。。
多段のドリルダウン
を実現する方法を、
幾つかご紹介致しま
す。
© 2012 MARS FLAG Corporation. All rights reserved. 17
- 18. 説明したいところ
(1) request
検索機能付きWebサイト
(2) 検索結果画面
© 2012 MARS FLAG Corporation. All rights reserved. 18
- 19. 説明したいところ
Web App Solr
(1) request (2)変換 (3) Solr 検索要求
(4) 検索
(7) 検索結果画面 (6) 検索結果画面生成 (5) Solr 検索結果
© 2012 MARS FLAG Corporation. All rights reserved. 19
- 20. サンプルアプリケーション(書籍検索)
*:* 検索
検索結果n件(1 ~ 10まで表示)
+人文・思想(14)
+倫理学・道徳(5)
坊ちゃん
夏目漱石
+哲学・思想(5)
.... .....
+文学・評論(13)
+歴史・時代小説
(5) 永遠の0(講談社)
..... 百田 尚樹
.....
注文の多い料理店
宮沢 賢治
.....
.....
© 2012 MARS FLAG Corporation. All rights reserved. 20
- 21. 投入データ
タイトル :坊っちゃん
タイトル :夏目 :坊っちゃん
著者 タイトル 漱石 :坊っちゃん
著者著者 :夏目 漱石
:夏目 漱石
大カテゴリ :文学・評論
大カテゴリ :文学・評論
大カテゴリ :文学・評論
中カテゴリ :文芸作品
中カテゴリ :文芸作品
中カテゴリ :文芸作品
....
「Amazon > 書籍」より拝借
© 2012 MARS FLAG Corporation. All rights reserved. 21
- 22. ドリルダウンペイン
*:* 検索
検索結果n件(1 ~ 10まで表示)
+人文・思想(14)
+倫理学・道徳(5)
坊ちゃん
夏目漱石
+哲学・思想(5)
.... .....
+文学・評論(13)
+歴史・時代小説
(5) 永遠の0(講談社)
..... 百田 尚樹
.....
注文の多い料理店
宮沢 賢治
.....
.....
© 2012 MARS FLAG Corporation. All rights reserved. 22
- 23. ドリルダウンペイン
*:* 検索
検索結果n件(1 ~ 10まで表示)
+人文・思想(14)
+倫理学・道徳(5)
坊ちゃん
夏目漱石
+哲学・思想(5)
ドリルダウン template .... .....
データ engine +文学・評論(13)
+歴史・時代小説
(5) 永遠の0(講談社)
..... 百田 尚樹
.....
注文の多い料理店
宮沢 賢治
.....
.....
© 2012 MARS FLAG Corporation. All rights reserved. 23
- 24. ドリルダウン データフォーマット
<drilldown> ::= [{<category>}]
<category> ::= [<name>, <count>,<drilldown>]
<name> ::= tabを除く任意の文字列
<count> ::= 数値
© 2012 MARS FLAG Corporation. All rights reserved. 24
- 25. ドリルダウン データフォーマット
<drilldown> ::= [{<category>}]
<category> ::= [<name>, <count>,<drilldown>]
<name> ::= tabを除く任意の文字列
<count> ::= 数値
[[人文・思想, 14, [[倫理学・道徳, 5, [] ],...]...]
<name> <count> <drilldown>
<name> <count> <drilldown>
<drilldown>
© 2012 MARS FLAG Corporation. All rights reserved. 25
- 26. インデントすると分かりやすい
[
[
人文・思想, 14, [
[倫理学・道徳, 5, []], +人文・思想(14)
[哲学・思想, 5, []], +倫理学・道徳(5)
.... +哲学・思想(5)
] ....
], +文学・評論(13)
[
+歴史・時代小説(5)
文学・評論, 13, [
[歴史・時代小説, 5, []], .....
....
]
]
]
© 2012 MARS FLAG Corporation. All rights reserved. 26
- 27. 方法その1
実直形
© 2012 MARS FLAG Corporation. All rights reserved. 27
- 28. schema.xmlと投入データ
schema.xml
<field name="category1" type="string" .. multiValued="true"/>
<field name="category2" type="string" .. multiValued="true"/>
投入データ
<add>
<doc>
<field name="title">坊っちゃん</field>
<field name="author">夏目 漱石</field>
<field name="category1">文学・評論</field>
<field name="category2">文芸作品</field>
</doc>
....
</add>
© 2012 MARS FLAG Corporation. All rights reserved. 28
- 29. 検索
大カテゴリ
Q /select?q=*:*&facet.field=category1&wt=json&facet=true
R category1:["人文・思想", 14, "文学・評論", 13, ...]
© 2012 MARS FLAG Corporation. All rights reserved. 29
- 30. 検索
大カテゴリ
Q /select?q=*:*&facet.field=category1&wt=json&facet=true
R category1:["人文・思想", 14, "文学・評論", 13, ...]
中カテゴリ
/select?q=*:*&facet.field=category2&fq=category1:人文・思想
Q &wt=json&facet=true
R category2:["倫理学・道徳", 5, "哲学・思想", 5, "宗教", 5, ...]
© 2012 MARS FLAG Corporation. All rights reserved. 30
- 31. まとめる
[
[
人文・思想, 14,
[
大カテゴリ
category1:["人文・思想", 14, "文学・評論
", 13, ...]
]
],
[
文学・評論, 13,
[
]
]
]
© 2012 MARS FLAG Corporation. All rights reserved. 31
- 32. まとめる
[
[
人文・思想, 14,
[
大カテゴリ
[倫理学・道徳, 5, []],
category1:["人文・思想", 14, "文学・評論", 13, ...] [哲学・思想, 5, []],
....
]
中カテゴリ
],
[
category2:["倫理学・道徳", 5, "哲学・思想", 5, .. 文学・評論, 13,
[
category2:["文芸作品", 5, "歴史・時代小説", 5, ...] ....
]
]
]
© 2012 MARS FLAG Corporation. All rights reserved. 32
- 33. 効率悪すぎやしないか。。。
© 2012 MARS FLAG Corporation. All rights reserved. 33
- 35. schema.xmlと投入データ
schema.xml
<field name="category_join" type="string" .. multiValued="true"/>
<add>
<doc>
<field name="id">坊っちゃん</field>
<field name="author">夏目 漱石</field>
<field name="category_join">人文・思想</field>
<field name="category_join">
人文・思想<tab>倫理学・道徳
</field>
</doc>
....
</add>
© 2012 MARS FLAG Corporation. All rights reserved. 35
- 36. 検索
Q /select?q=*:*&facet.field=category_join&wt=json&facet=true
category_join: ["人文・思想", 14, "文学・評論", 13,
"人文・思想<tab>倫理学・道徳",5,
R "人文・思想<tab>哲学・思想", 5,
"人文・思想<tab>宗教", 5,
"文学・評論<tab>歴史・時代小説",5...]
© 2012 MARS FLAG Corporation. All rights reserved. 36
- 37. まとめる
[
[
人文・思想, 14,
[
大カテゴリ
h_join: [ "人文・思想", 14, "文学・評論
", 13,
]
],
"人文・思想<tab>倫理学・道徳",5, [
"人文・思想<tab>哲学・思想", 5, 文学・評論, 13,
"人文・思想<tab>宗教", 5, [
"文学・評論<tab>歴史・時代小説",5...]
]
]
]
© 2012 MARS FLAG Corporation. All rights reserved. 37
- 38. まとめる
[
[
人文・思想, 14,
[
大カテゴリ
[倫理学・道徳, 5, []],
h_join: ["人文・思想", 14, "文学・評論", [哲学・思想, 5, []],
13, ....
大カテゴリ<tab>中カテゴリ ]
],
"人文・思想<tab>倫理学・道徳",5, [
"人文・思想<tab>哲学・思想", 5, 文学・評論, 13,
"人文・思想<tab>宗教", 5, [
"文学・評論<tab>歴史・時代小説",5...] ....
]
]
]
© 2012 MARS FLAG Corporation. All rights reserved. 38
- 41. schema.xmlと投入データ
schema.xml
<field name="category1" type="string" .. multiValued="true"/>
<field name="category2" type="string" .. multiValued="true"/>
投入データ
<add>
<doc>
<field name="id">坊っちゃん</field>
<field name="author">夏目 漱石</field>
<field name="category1">文学・評論</field>
<field name="category2">文芸作品</field>
</doc>
....
</add>
© 2012 MARS FLAG Corporation. All rights reserved. 41
- 42. 検索
Q /select?q=*:*&facet.pivot=category1,catetory2&wt=json&facet=true
category1,category2: [
{
field: "category1", value: "人文・思想", count: 14,
pivot: [ { field: "category2", value: "倫理学・道徳", count: 5 },
{ field: "category2", value: "哲学・思想", count: 5, ....]
},
{
R field: "category1", value: "文学・評論", `count: 13,
pivot: [ { field: "category2",value: "文芸作品",count: 5 },
{ field: "category2", value: "歴史・時代小説", count:
5 },....]
},
....
]
© 2012 MARS FLAG Corporation. All rights reserved. 42
- 43. まとめる(というか殆ど同じ)
[
h1_ss,h2_ss: [ [
{ 人文・思想, 14,
field: "h1_ss", value: "人文・思想", count: 14,
[
pivot: [
{field: "h2_ss", value: "倫理学・道徳", count: 5},
[倫理学・道徳, 5, []],
{field: "h2_ss", value: "哲学・思想", count: 5}, [哲学・思想, 5, []],
.... ....
] ]
}, ],
{ [
field: "h1_ss", value: "文学・評論", count: 13, 文学・評論, 13,
pivot: [
[
....
]
....
} ]
] ]
]
© 2012 MARS FLAG Corporation. All rights reserved. 43
- 44. 比較
実直形 少し工夫形 Pivot Facet
検索コスト 悪い 良い 良い
データ加工 不必要 必要 不必要
柔軟性 悪くない 悪い 良い
© 2012 MARS FLAG Corporation. All rights reserved. 44
- 45. Pivot Facetの柔軟性についてもう少し
Q /select?q=*:*&facet.pivot=auhotr,catetory1,category2&wt=json&facet=true
author,category1,category2: [
{
field: "author", value: "百田 尚樹", count: 3,
pivot: [
{
field: "category1", value: "文学・評論", count: 3,
pivot: [
R { field: "category2", value: "歴史・時代小説", count: 2 },
{ field: "category2", value: "経済・社会小説", count: 2 },
{ field: "category2", value: "文芸作品", count: 1}
....
]
},
....
© 2012 MARS FLAG Corporation. All rights reserved. 45
- 46. まとめ
• Pivot Facet がSolr 4.0でリリースされました。
• 多段のドリルダウンを実装する再は是非
使ってみてください。
© 2012 MARS FLAG Corporation. All rights reserved. 46
- 48. MARS FLAG
人材募集中です!
http://www.marsflag.com/
(宣伝はしたぞ!-> マーケティング本部)
© 2012 MARS FLAG Corporation. All rights reserved. 48
- 50. 参考文献
• 関口 宏司、三部 靖夫、武田 光平、中野
猛、「Apache Solr入門 ―オープンソース
全文検索エンジン」、技術評論社、2010
• HierarchicalFaceting、
http://wiki.apache.org/solr/HierarchicalFaceti
ng、ErikHatch、2012/11/18
© 2012 MARS FLAG Corporation. All rights reserved. 50