#!/usr/bin/env ruby # -*- coding: utf-8 -*- base_dir = File.join(File.dirname(__FILE__), "..") groonga_ext_dir = File.join(base_dir, 'ext') groonga_lib_dir = File.join(base_dir, 'lib') $LOAD_PATH.unshift(groonga_ext_dir) $LOAD_PATH.unshift(groonga_lib_dir) begin require "groonga" rescue LoadError require "rubygems" require "groonga" end require 'time' # Groonga::Logger.register(:level => :debug) do |level, time, title, message, location| # p [level, time, title, message, location] # end $KCODE = "UTF-8" Groonga::Context.default_options = {:encoding => :utf8} path = ARGV[0] if path.nil? require 'tmpdir' require 'fileutils' temporary_directory = File.join(Dir.tmpdir, "ruby-groonga") FileUtils.mkdir_p(temporary_directory) at_exit {FileUtils.rm_rf(temporary_directory)} path = File.join(temporary_directory, "db") end persistent = true p Groonga::Database.create(:path => path) p(items = Groonga::Hash.create(:name => "", :persistent => persistent)) p items.add("http://ja.wikipedia.org/wiki/Ruby") p items.add("http://www.ruby-lang.org/") p items.define_column("title", "", :persistent => persistent) p(terms = Groonga::Hash.create(:name => "", :key_type => "", :persistent => persistent, :default_tokenizer => "")) p terms.define_index_column("item_title", items, :persistent => persistent, :with_weight => true, :with_section => true, :with_position => true, :source => ".title") p items.find("http://ja.wikipedia.org/wiki/Ruby")["title"] = "Ruby" p items.find("http://www.ruby-lang.org/")["title"] = "オブジェクト指向スクリプト言語Ruby" p(users = Groonga::Hash.create(:name => "", :key_type => "", :persistent => persistent)) p users.define_column("name", "", :persistent => persistent) p(comments = Groonga::Array.create(:name => "", :persistent => persistent)) p comments.define_column("item", items) p comments.define_column("author", users) p comments.define_column("content", "") p comments.define_column("issued", "