[Groonga-commit] ranguba/groonga-client-model at 6692021 [master] migration: support auto "WITH_SECTION"

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Mar 7 20:41:43 JST 2017


Kouhei Sutou	2017-03-07 20:41:43 +0900 (Tue, 07 Mar 2017)

  New Revision: 6692021cfe67b48b9f08664d50d108a2d4149681
  https://github.com/ranguba/groonga-client-model/commit/6692021cfe67b48b9f08664d50d108a2d4149681

  Message:
    migration: support auto "WITH_SECTION"

  Modified files:
    lib/groonga_client_model/migration.rb
    test/unit/migration/test_create_table.rb

  Modified: lib/groonga_client_model/migration.rb (+4 -1)
===================================================================
--- lib/groonga_client_model/migration.rb    2017-03-07 20:00:25 +0900 (270960d)
+++ lib/groonga_client_model/migration.rb    2017-03-07 20:41:43 +0900 (317da96)
@@ -163,6 +163,7 @@ module GroongaClientModel
 
       value_type = normalize_type(value_type)
       type = normalize_column_type(type || :scalar)
+      sources ||= source || []
       flags = Array(flags) | [type]
       if type == "COLUMN_INDEX"
         schema = GroongaClientModel::Schema.new
@@ -172,8 +173,10 @@ module GroongaClientModel
         else
           flags << "WITH_POSITION"
         end
+        if sources.size > 1
+          flags << "WITH_SECTION"
+        end
       end
-      sources ||= source
       options = {
         flags: flags,
         value_type: value_type,

  Modified: test/unit/migration/test_create_table.rb (+45 -0)
===================================================================
--- test/unit/migration/test_create_table.rb    2017-03-07 20:00:25 +0900 (94f9ce4)
+++ test/unit/migration/test_create_table.rb    2017-03-07 20:41:43 +0900 (1d08eee)
@@ -437,6 +437,51 @@ column_create terms posts_content COLUMN_INDEX|WITH_POSITION posts content
           end
         end
       end
+
+      test("multi sources") do
+        expected_up_report = <<-REPORT
+-- create_table(:posts, {:type=>"TABLE_NO_KEY"})
+   -> 0.0s
+-- add_column(:posts, :title, {:flags=>["COLUMN_SCALAR"], :value_type=>"ShortText"})
+   -> 0.0s
+-- add_column(:posts, :content, {:flags=>["COLUMN_SCALAR"], :value_type=>"Text"})
+   -> 0.0s
+-- create_table(:terms, {:type=>"TABLE_PAT_KEY", :key_type=>"ShortText", :tokenizer=>"TokenBigram", :normalizer=>"NormalizerAuto"})
+   -> 0.0s
+-- add_column(:terms, "posts_title_content", {:flags=>["COLUMN_INDEX", "WITH_POSITION", "WITH_SECTION"], :value_type=>:posts, :sources=>[:title, :content]})
+   -> 0.0s
+        REPORT
+        expected_down_report = <<-REPORT
+-- remove_table(:terms)
+   -> 0.0s
+-- remove_table(:posts)
+   -> 0.0s
+        REPORT
+        expected_dump = <<-DUMP.chomp
+table_create posts TABLE_NO_KEY
+column_create posts content COLUMN_SCALAR Text
+column_create posts title COLUMN_SCALAR ShortText
+
+table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
+
+column_create terms posts_title_content COLUMN_INDEX|WITH_SECTION|WITH_POSITION posts title,content
+        DUMP
+        assert_migrate(expected_up_report,
+                       expected_down_report,
+                       expected_dump) do |migration|
+          migration.instance_eval do
+            create_table(:posts) do |table|
+              table.short_text(:title)
+              table.text(:content)
+            end
+
+            create_table(:terms,
+                         :propose => :full_text_search) do |table|
+              table.index(:posts, [:title, :content])
+            end
+          end
+        end
+      end
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index