Kouhei Sutou
null+****@clear*****
Sun May 25 12:56:32 JST 2014
Kouhei Sutou 2014-05-25 12:56:32 +0900 (Sun, 25 May 2014) New Revision: 49cabdd7d41527f230f1277faeef79652b8fa0ca https://github.com/groonga/heroku-sample-rroonga-blog/commit/49cabdd7d41527f230f1277faeef79652b8fa0ca Message: Support initializing Groonga database Added files: groonga/init.rb Modified files: .gitignore Gemfile Gemfile.lock Modified: .gitignore (+3 -0) =================================================================== --- .gitignore 2014-05-25 12:39:05 +0900 (6a502e9) +++ .gitignore 2014-05-25 12:56:32 +0900 (ef68cf2) @@ -14,3 +14,6 @@ # Ignore all logfiles and tempfiles. /log/*.log /tmp + +# Ignore Groonga database. +/groonga/database* Modified: Gemfile (+2 -0) =================================================================== --- Gemfile 2014-05-25 12:39:05 +0900 (03be23c) +++ Gemfile 2014-05-25 12:56:32 +0900 (e701dad) @@ -40,3 +40,5 @@ gem 'spring', group: :development # gem 'debugger', group: [:development, :test] gem 'rails_12factor', group: :production + +gem 'rroonga' Modified: Gemfile.lock (+16 -0) =================================================================== --- Gemfile.lock 2014-05-25 12:39:05 +0900 (a9d76d4) +++ Gemfile.lock 2014-05-25 12:56:32 +0900 (76ece3f) @@ -27,6 +27,8 @@ GEM minitest (~> 5.1) thread_safe (~> 0.1) tzinfo (~> 1.1) + archive-zip (0.6.0) + io-like (>= 0.3.0) arel (5.0.1.20140414130214) builder (3.2.2) coffee-rails (4.0.1) @@ -38,8 +40,15 @@ GEM coffee-script-source (1.7.0) erubis (2.7.0) execjs (2.0.2) + gqtp (1.0.6) + groonga-client (0.0.8) + gqtp (>= 1.0.4) + groonga-command (>= 1.0.4) + groonga-command (1.0.7) + json hike (1.2.3) i18n (0.6.9) + io-like (0.3.0) jbuilder (2.0.7) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) @@ -54,6 +63,7 @@ GEM minitest (5.3.4) multi_json (1.10.1) pg (0.17.1) + pkg-config (1.1.5) polyglot (0.3.4) rack (1.5.2) rack-test (0.6.2) @@ -81,6 +91,11 @@ GEM rake (10.3.2) rdoc (4.1.1) json (~> 1.4) + rroonga (4.0.1) + archive-zip + groonga-client (>= 0.0.3) + json + pkg-config sass (3.2.19) sass-rails (4.0.3) railties (>= 4.0.0, < 5.0) @@ -124,6 +139,7 @@ DEPENDENCIES pg rails (= 4.1.1) rails_12factor + rroonga sass-rails (~> 4.0.3) sdoc (~> 0.4.0) spring Added: groonga/init.rb (+47 -0) 100644 =================================================================== --- /dev/null +++ groonga/init.rb 2014-05-25 12:56:32 +0900 (d50b20c) @@ -0,0 +1,47 @@ +require_relative '../config/environment' + +require 'fileutils' +require 'groonga' + +database_path = ENV['GROONGA_DATABASE_PATH'] || 'groonga/database' +if File.exist?(database_path) + Groonga::Database.open(database_path) +else + Groonga::Database.create(path: database_path) +end + +Groonga::Schema.define do |schema| + schema.create_table('Posts', + type: :hash, + key_type: :uint32) do |table| + table.short_text('title') + table.text('content') + table.time('created_at') + table.time('updated_at') + end +end + +posts = Groonga['Posts'] +Post.all.each do |post| + attributes = post.attributes + id = attributes.delete("id") + posts.add(id, attributes) +end + +Groonga::Schema.define do |schema| + schema.create_table('Terms', + type: :patricia_trie, + key_type: :short_text, + normalizer: 'NormalizerAuto', + default_tokenizer: 'TokenBigram') do |table| + table.index('Posts.title') + table.index('Posts.content') + end + + schema.create_table('Times', + type: :patricia_trie, + key_type: :time) do |table| + table.index('Posts.created_at') + table.index('Posts.updated_at') + end +end -------------- next part -------------- HTML����������������������������... ダウンロード