SlideShare a Scribd company logo
1 of 21
Download to read offline
名古屋検索勉強会
1
アジェンダ
1. 辞書検索の構成
2. ワイルドカードクエリー
3. スペル修正
!2
特定の単語を含む文書を検索したい!
超シンプルなデータ構造は行列
だけど
無駄が多い
D1 D2 D3
T1 0 1 0
T2 1 0 0
T3 0 1 1
T4 1 0 1
単語を含まない文書には関心がない
そこで
辞書+ポスティングリスト
(標準)転置インデックス
3.1 辞書検索の構成
T1 D2
T2 D1
T3 D2 D3
T4 D1 D3
!3
3.1 辞書検索の構成
辞書に紐付くポスティングを取得する
昭和 D2
令和 D1
平安 D2 D3
永禄 D1 D3
令和
!4
3.1 辞書検索の構成
辞書を使って索引の語彙を走査する
for キー in 辞書 :
if 語彙 == キー :
return キー.Documents
総当たりはイケてない
辞書のデータ構造にはハッシュと探索木がある
トレードオフを考えよう
- キーの数
- キーの更新頻度(挿入、削除、置換)
- アクセスの偏り
!5
3.1 辞書検索の構成
ハッシュで実装する
衝突しないようにキーを生成する
一般的にサイズは大きくなる
揺らぎを解決できない
ウェブの成長でキーも増え続ける
検索の実装としてはハッシュだめぽ?
!6
ではそこまでディスられてはいない(情報検索の文脈じゃないから?)
3.1 辞書検索の構成
探索木ならハッシュの問題はクリアできる
-カンバンぽくメモリ確保できる
-衝突考えなくていいから楽
探索木と聞いてまず思い浮かぶ二分木
キーが増えても計算量はO(logN)
子ノードには似た語が並ぶ
でも更新が発生すると再調整が面倒
子ノードが一定な二分木、
一定じゃなければイケてるのに…
二分探索木の例 情報検索の基礎より抜粋
!7
3.1 辞書検索の構成
B木
子ノードが一定の範囲で増減できる
詳しくは↓
https://speakerdeck.com/nekonenene/b-tree-algorithm?slide=32
B木の例 情報検索の基礎より抜粋
!8
木構造は便利だけどソートされていなければならない
英語 26文字
中国語 文字 順番?
日本語 文字 順番??
アラビア語 文字???
ユニコードで符号化したもの使えばオッケー
混ぜるな危険
3.1 辞書検索の構成
!9
3.2 ワイルドカードクエリー
うろ覚えな言葉を検索したい
まとめて検索したい
ステミング前提で検索したい
知らない国の言葉を検索したい
全てを解決できる
そう
ワイルドカードならね
!10
3.2 ワイルドカードクエリー
後方一致ワイルドカードクエリー abc*
ROOT -> a -> b -> c -> *
探索の結果見つかった語彙全てを転置インデックスに照会する
!11
abc*
子ノードを全部拾う
二分探索木の例 情報検索の基礎より抜粋
3.2 ワイルドカードクエリー
前方一致ワイルドカードクエリー *abc
文字列を反転させて保持すれば対処できる
ROOT -> c -> b -> a -> *
!12
cba*
子ノードを全部拾う
二分探索木の例 情報検索の基礎より抜粋
3.2 ワイルドカードクエリー
中間一致ワイルドカードクエリー a*c
前方一致(a*)と後方一致(c*)で取得した結果(WとR)の積(&)を求める
!13
W R&
ワイルドカードが複数あるときはどうする?
3.2 ワイルドカードクエリー
置換インデックス
記号で末尾が分かるようにして、
1文字ずつ回転する
クエリは*が右端になるまで回転する
h*o -> h*o$ -> $h*o -> o$h*
1つのワイルドカードなら見つかる
でも複数はどうする?
!14
置換インデックスの例 情報検索の基礎より抜粋
3.2 ワイルドカードクエリー
複数ワイルドカードを含むケース
最初のワイルドカードまでを
置換インデックスで探す
mo*の部分は別途要チェック
…結局最後は力技?
!15
fi*mo*er
↓ 回転
er$fi*mo*
↓ 最初の*までなら容易
er$fi*
3.2 ワイルドカードクエリー
置換インデックスは辞書サイズが大きくなる
そこで(?)Kグラムインデックス
Kグラム=K文字の並び
castleの3グラム -> $ca cas ast stl tle le$
与えられたクエリを分割して論理演算する
re*ve -> $re AND ve$
中間一致ではないときは論理演算だけでは足りない
red* -> $re AND red
ポストフィルタリングステップ
列挙したものを単純に文字列マッチする
複数の組み合わせも論理演算でできる (例 ho*ge OR fuga*)
!16
3.3 スペル修正
carot -> carrot?
ブリトニースピアーズのタイポが界隈で有名?
編集距離とKグラムの重なりで調べる
!17
3.3 スペル修正
検索エンジンのスペル修正はどう実装されているか
2つの原則
- 「近い」ものを選択する
- 「一般的な」ものを選択する
- コレクション内での出現頻度
- クエリの入力頻度
単独の補正と文脈依存の補正
carot
flew form Heathrow
!18
3.3 スペル修正
編集距離(レーベンシュタイン距離)
s1 -> s2 の変換をいくつの操作でできるか
挿入、削除、置換と、これに対する重み付け
cat -> dog 3
horse -> house 1
!19
まとめ
ユーザーから見ると融通がきく検索でも
内部の実装は融通がきかず泥臭い
データ構造とアルゴリズムは大切です!
!20
Fin.
!21

More Related Content

Featured

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 

Featured (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

名古屋検索勉強会#3