Class: Groonga::PatriciaTrie
- Defined in:
- ext/groonga/rb-grn-patricia-trie.c,
lib/groonga/patricia-trie.rb
Overview
各レコードをパトリシアトライで管理するテーブル。ハッシュテーブルに比べて完全一致検索の速度がやや遅いが、前方一致検索・共通接頭辞探索などの検索ができる。またカーソルを用いてキーの昇降順にレコードを取り出すことができる。
Instance Method Summary collapse
-
#tag_keys(text, options = {}) ⇒ Object
text を走査し、レコードのキーとマッチする部分文字列ごとに そのレコードが record として、その部分文字列が word として、 ブロックが呼び出される。ブロックから返された文字列が元の部 分文字列と置換される。全てのヒットに対してのその置換処理が 行われた文字列が返される。.
Methods inherited from Table
Instance Method Details
#tag_keys(text, options = {}) ⇒ Object
text を走査し、レコードのキーとマッチする部分文字列ごとにそのレコードが record として、その部分文字列が word として、ブロックが呼び出される。ブロックから返された文字列が元の部分文字列と置換される。全てのヒットに対してのその置換処理が行われた文字列が返される。
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/groonga/patricia-trie.rb', line 51 def tag_keys(text, ={}) ||= {} other_text_handler = [:other_text_handler] position = 0 result = '' if text.respond_to?(:encoding) encoding = text.encoding bytes = text.dup.force_encoding("ascii-8bit") else encoding = nil bytes = text end scan(text) do |record, word, start, length| previous_text = bytes[position...start] previous_text.force_encoding(encoding) if encoding if other_text_handler previous_text = other_text_handler.call(previous_text) end result << previous_text result << yield(record, word) position = start + length end last_text = bytes[position..-1] unless last_text.empty? last_text.force_encoding(encoding) if encoding last_text = other_text_handler.call(last_text) if other_text_handler result << last_text end result end |