おんがえし (http://ongaeshi.me/)
schema.create_table("Documents", :type => :hash) do |table|
table.string("path")
table.string("package")
table.time("timestamp")
table.string("suffix")
end
schema.create_table("Terms",
:type => :patricia_trie,
:key_normalize => true,
:default_tokenizer => "TokenBigramSplitSymbolAlphaDigit") do |table|
table.index("documents.path", :with_position => true)
table.index("documents.package", :with_position => true)
table.index("documents.suffix", :with_position => true)
end
$ gem install grn_mini
require 'grn_mini'
GrnMini::create_or_open("test.db")
array = GrnMini::Array.new
array << {text: "aaa", number: 1} # add()も使えます
array << {text: "bbb", number: 2}
array.size #=> 2
array[1].text #=> "aaa"
array[2].number #=> "2"
array[2].attributes #=> {text: "bbb", number: 2}
# textに"aa"を含むものを探す
results = array.select("text:@aa")
# 検索結果を表示
results.each do |record|
p record.attributes #=> {text: "aaa", number: 1}
end
array.grn #=> Groonga::Array
hash = GrnMini::Hash.new
# Add
hash["a"] = {text:"aaa", number:1}
hash["b"] = {text:"bbb", number:2}
hash["c"] = {text:"ccc", number:3}
# Read
hash["b"].text #=> "bbb"
# Write
hash["b"].text = "BBB"
GrnMini::tmpdb do
array = GrnMini::Array.new
array << {text: "aaa", number: 1}
array << {text: "bbb", number: 2}
array << {text: "ccc", number: 3}
# 色々と実験…
end
# Delete temporary database
GrnMini::tmpdb do
array = GrnMini::Array.new
# ダミーデータを設定する
array.setup_columns(
filename: "",
int: 0,
float: 0.0,
time: Time.new,
)
# データの追加
array << {filename: "a.txt", int: 1, float: 1.5, time: Time.at(1999)}
end
users = GrnMini::Hash.new("Users")
articles = GrnMini::Hash.new("Articles")
users.setup_columns(name: "")
articles.setup_columns(author: users, text: "")
users["aaa"] = {name: "Mr.A"}
users["bbb"] = {name: "Mr.B"}
articles["aaa:1"] = {author: users["aaa"], text: "111"}
articles["aaa:2"] = {author: users["aaa"], text: "222"}
articles["bbb:1"] = {author: users["bbb"], text: "111"}
# 著者がMr.Aで本文に'1'を含む記事
articles.select("author.name:Mr.A text:@1") #=> ["aaa:1"]
https://github.com/ongaeshi/grn_mini