[Groonga-commit] ranguba/rroonga at 70ffee9 [master] Move #reindex to TableKeySupport from Table

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Jan 15 21:20:47 JST 2016


Kouhei Sutou	2016-01-15 21:20:47 +0900 (Fri, 15 Jan 2016)

  New Revision: 70ffee9d8d8906d3c202e4016a0d451fb24a97f9
  https://github.com/ranguba/rroonga/commit/70ffee9d8d8906d3c202e4016a0d451fb24a97f9

  Message:
    Move #reindex to TableKeySupport from Table
    
    Because Groonga::Array can't reindex. Lexicon must have key.

  Modified files:
    ext/groonga/rb-grn-database.c
    ext/groonga/rb-grn-fix-size-column.c
    ext/groonga/rb-grn-index-column.c
    ext/groonga/rb-grn-table-key-support.c
    ext/groonga/rb-grn-table.c
    ext/groonga/rb-grn-variable-size-column.c
    test/test-table-key-support.rb
    test/test-table.rb

  Modified: ext/groonga/rb-grn-database.c (+3 -3)
===================================================================
--- ext/groonga/rb-grn-database.c    2016-01-15 21:15:40 +0900 (9f13f7c)
+++ ext/groonga/rb-grn-database.c    2016-01-15 21:20:47 +0900 (2fd70d7)
@@ -632,8 +632,8 @@ rb_grn_database_unmap (VALUE self)
  * this method spends more time rather than you specify only reindex
  * needed index columns.
  *
- * You can use {Groonga::Table#reindex} to specify reindex target
- * index columns in a table.
+ * You can use {Groonga::TableKeySupport#reindex} to specify reindex
+ * target index columns in a table.
  *
  * You can use {Groonga::FixSizeColumn#reindex} or
  * {Groonga::VariableSizeColumn#reindex} to specify reindex target
@@ -681,7 +681,7 @@ rb_grn_database_unmap (VALUE self)
  * @overload reindex
  *   @return [void]
  *
- * @see Groonga::Table#reindex
+ * @see Groonga::TableKeySupport#reindex
  * @see Groonga::FixSizeColumn#reindex
  * @see Groonga::VariableSizeColumn#reindex
  * @see Groonga::IndexColumn#reindex

  Modified: ext/groonga/rb-grn-fix-size-column.c (+3 -3)
===================================================================
--- ext/groonga/rb-grn-fix-size-column.c    2016-01-15 21:15:40 +0900 (9afd19a)
+++ ext/groonga/rb-grn-fix-size-column.c    2016-01-15 21:20:47 +0900 (8ea1007)
@@ -153,8 +153,8 @@ rb_grn_fix_size_column_decrement (int argc, VALUE *argv, VALUE self)
  * You can use {Groonga::Database#reindex} to recreate all index
  * columns in a database.
  *
- * You can use {Groonga::Table#reindex} to recreate all index
- * columns in a table.
+ * You can use {Groonga::TableKeySupport#reindex} to recreate all
+ * index columns in a table.
  *
  * You can use {Groonga::IndexColumn#reindex} to specify the reindex
  * target index column.
@@ -199,7 +199,7 @@ rb_grn_fix_size_column_decrement (int argc, VALUE *argv, VALUE self)
  *   @return [void]
  *
  * @see Groonga::Database#reindex
- * @see Groonga::Table#reindex
+ * @see Groonga::TableKeySupport#reindex
  * @see Groonga::VariableSizeColumn#reindex
  * @see Groonga::IndexColumn#reindex
  *

  Modified: ext/groonga/rb-grn-index-column.c (+3 -3)
===================================================================
--- ext/groonga/rb-grn-index-column.c    2016-01-15 21:15:40 +0900 (45a471e)
+++ ext/groonga/rb-grn-index-column.c    2016-01-15 21:20:47 +0900 (9a843b3)
@@ -1196,8 +1196,8 @@ rb_grn_index_column_estimate_size (int argc, VALUE *argv, VALUE self)
  * You can use {Groonga::Database#reindex} to recreate all index
  * columns in a database.
  *
- * You can use {Groonga::Table#reindex} to recreate all index
- * columns in a table.
+ * You can use {Groonga::TableKeySupport#reindex} to recreate all
+ * index columns in a table.
  *
  * You can use {Groonga::FixSizeColumn#reindex} or
  * {Groonga::VariableSizeColumn#reindex} to recreate all index
@@ -1240,7 +1240,7 @@ rb_grn_index_column_estimate_size (int argc, VALUE *argv, VALUE self)
  *   @return [void]
  *
  * @see Groonga::Database#reindex
- * @see Groonga::Table#reindex
+ * @see Groonga::TableKeySupport#reindex
  * @see Groonga::FixSizeColumn#reindex
  * @see Groonga::VariableSizeColumn#reindex
  *

  Modified: ext/groonga/rb-grn-table-key-support.c (+87 -1)
===================================================================
--- ext/groonga/rb-grn-table-key-support.c    2016-01-15 21:15:40 +0900 (c17b30c)
+++ ext/groonga/rb-grn-table-key-support.c    2016-01-15 21:20:47 +0900 (e8569b3)
@@ -1,7 +1,7 @@
 /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
-  Copyright (C) 2014  Masafumi Yokoyama <myokoym �� gmail.com>
   Copyright (C) 2009-2014  Kouhei Sutou <kou �� clear-code.com>
+  Copyright (C) 2014-2016  Masafumi Yokoyama <yokoyama �� clear-code.com>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -1025,6 +1025,89 @@ rb_grn_table_key_support_tokenize (int argc, VALUE *argv, VALUE self)
     return rb_tokens;
 }
 
+/*
+ * Recreates all index columns in the table.
+ *
+ * This method is useful when you have any broken index columns in
+ * the table. You don't need to specify each index column. But this
+ * method spends more time rather than you specify only reindex
+ * needed index columns.
+ *
+ * You can use {Groonga::Database#reindex} to recreate all index
+ * columns in a database.
+ *
+ * You can use {Groonga::FixSizeColumn#reindex} or
+ * {Groonga::VariableSizeColumn#reindex} to specify reindex target
+ * index columns. They use index columns of the data column as
+ * reindex target index columns.
+ *
+ * You can use {Groonga::IndexColumn#reindex} to specify the reindex
+ * target index column.
+ *
+ * @example How to recreate all index columns in the table
+ *   Groonga::Schema.define do |schema|
+ *     schema.create_table("Memos") do |table|
+ *       table.short_text("title")
+ *       table.text("content")
+ *     end
+ *
+ *     schema.create_table("BigramTerms",
+ *                         :type => :patricia_trie,
+ *                         :key_type => :short_text,
+ *                         :normalizer => "NormalizerAuto",
+ *                         :default_tokenizer => "TokenBigram") do |table|
+ *       table.index("Memos.title")
+ *       table.index("Memos.content")
+ *     end
+ *
+ *     schema.create_table("MeCabTerms",
+ *                         :type => :patricia_trie,
+ *                         :key_type => :short_text,
+ *                         :normalizer => "NormalizerAuto",
+ *                         :default_tokenizer => "TokenMecab") do |table|
+ *       table.index("Memos.title")
+ *       table.index("Memos.content")
+ *     end
+ *   end
+ *
+ *   Groonga["BigramTerms"].reindex
+ *   # They are called:
+ *   #   Groonga["BigramTerms.Memos_title"].reindex
+ *   #   Groonga["BigramTerms.Memos_content"].reindex
+ *   #
+ *   # They aren't called:
+ *   #   Groonga["MeCabTerms.Memos_title"].reindex
+ *   #   Groonga["MeCabTerms.Memos_content"].reindex
+ *
+ * @overload reindex
+ *   @return [void]
+ *
+ * @see Groonga::Database#reindex
+ * @see Groonga::FixSizeColumn#reindex
+ * @see Groonga::VariableSizeColumn#reindex
+ * @see Groonga::IndexColumn#reindex
+ *
+ * @since 5.1.1
+ */
+static VALUE
+rb_grn_table_key_support_reindex (VALUE self)
+{
+    grn_rc rc;
+    grn_ctx *context;
+    grn_obj *table;
+
+    rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
+                                         NULL, NULL, NULL,
+                                         NULL, NULL, NULL,
+                                         NULL);
+
+    rc = grn_obj_reindex(context, table);
+    rb_grn_context_check(context, self);
+    rb_grn_rc_check(rc, self);
+
+    return Qnil;
+}
+
 void
 rb_grn_init_table_key_support (VALUE mGrn)
 {
@@ -1084,4 +1167,7 @@ rb_grn_init_table_key_support (VALUE mGrn)
 
     rb_define_method(rb_mGrnTableKeySupport, "tokenize",
                      rb_grn_table_key_support_tokenize, -1);
+
+    rb_define_method(rb_mGrnTableKeySupport, "reindex",
+                     rb_grn_table_key_support_reindex, 0);
 }

  Modified: ext/groonga/rb-grn-table.c (+0 -85)
===================================================================
--- ext/groonga/rb-grn-table.c    2016-01-15 21:15:40 +0900 (f8da568)
+++ ext/groonga/rb-grn-table.c    2016-01-15 21:20:47 +0900 (7b37fed)
@@ -2678,89 +2678,6 @@ rb_grn_table_rename (VALUE self, VALUE rb_name)
     return self;
 }
 
-/*
- * Recreates all index columns in the table.
- *
- * This method is useful when you have any broken index columns in
- * the table. You don't need to specify each index column. But this
- * method spends more time rather than you specify only reindex
- * needed index columns.
- *
- * You can use {Groonga::Database#reindex} to recreate all index
- * columns in a database.
- *
- * You can use {Groonga::FixSizeColumn#reindex} or
- * {Groonga::VariableSizeColumn#reindex} to specify reindex target
- * index columns. They use index columns of the data column as
- * reindex target index columns.
- *
- * You can use {Groonga::IndexColumn#reindex} to specify the reindex
- * target index column.
- *
- * @example How to recreate all index columns in the table
- *   Groonga::Schema.define do |schema|
- *     schema.create_table("Memos") do |table|
- *       table.short_text("title")
- *       table.text("content")
- *     end
- *
- *     schema.create_table("BigramTerms",
- *                         :type => :patricia_trie,
- *                         :key_type => :short_text,
- *                         :normalizer => "NormalizerAuto",
- *                         :default_tokenizer => "TokenBigram") do |table|
- *       table.index("Memos.title")
- *       table.index("Memos.content")
- *     end
- *
- *     schema.create_table("MeCabTerms",
- *                         :type => :patricia_trie,
- *                         :key_type => :short_text,
- *                         :normalizer => "NormalizerAuto",
- *                         :default_tokenizer => "TokenMecab") do |table|
- *       table.index("Memos.title")
- *       table.index("Memos.content")
- *     end
- *   end
- *
- *   Groonga["BigramTerms"].reindex
- *   # They are called:
- *   #   Groonga["BigramTerms.Memos_title"].reindex
- *   #   Groonga["BigramTerms.Memos_content"].reindex
- *   #
- *   # They aren't called:
- *   #   Groonga["MeCabTerms.Memos_title"].reindex
- *   #   Groonga["MeCabTerms.Memos_content"].reindex
- *
- * @overload reindex
- *   @return [void]
- *
- * @see Groonga::Database#reindex
- * @see Groonga::FixSizeColumn#reindex
- * @see Groonga::VariableSizeColumn#reindex
- * @see Groonga::IndexColumn#reindex
- *
- * @since 5.1.1
- */
-static VALUE
-rb_grn_table_reindex (VALUE self)
-{
-    grn_rc rc;
-    grn_ctx *context;
-    grn_obj *table;
-
-    rb_grn_table_deconstruct(SELF(self), &table, &context,
-                             NULL, NULL, NULL,
-                             NULL, NULL,
-                             NULL);
-
-    rc = grn_obj_reindex(context, table);
-    rb_grn_context_check(context, self);
-    rb_grn_rc_check(rc, self);
-
-    return Qnil;
-}
-
 void
 rb_grn_init_table (VALUE mGrn)
 {
@@ -2848,8 +2765,6 @@ rb_grn_init_table (VALUE mGrn)
 
     rb_define_method(rb_cGrnTable, "rename", rb_grn_table_rename, 1);
 
-    rb_define_method(rb_cGrnTable, "reindex", rb_grn_table_reindex, 0);
-
     rb_grn_init_table_key_support(mGrn);
     rb_grn_init_array(mGrn);
     rb_grn_init_hash(mGrn);

  Modified: ext/groonga/rb-grn-variable-size-column.c (+3 -3)
===================================================================
--- ext/groonga/rb-grn-variable-size-column.c    2016-01-15 21:15:40 +0900 (de2b21f)
+++ ext/groonga/rb-grn-variable-size-column.c    2016-01-15 21:20:47 +0900 (206c725)
@@ -575,8 +575,8 @@ rb_grn_variable_size_column_defrag (int argc, VALUE *argv, VALUE self)
  * You can use {Groonga::Database#reindex} to recreate all index
  * columns in a database.
  *
- * You can use {Groonga::Table#reindex} to recreate all index
- * columns in a table.
+ * You can use {Groonga::TableKeySupport#reindex} to recreate all
+ * index columns in a table.
  *
  * You can use {Groonga::IndexColumn#reindex} to specify the reindex
  * target index column.
@@ -620,7 +620,7 @@ rb_grn_variable_size_column_defrag (int argc, VALUE *argv, VALUE self)
  *   @return [void]
  *
  * @see Groonga::Database#reindex
- * @see Groonga::Table#reindex
+ * @see Groonga::TableKeySupport#reindex
  * @see Groonga::FixSizeColumn#reindex
  * @see Groonga::IndexColumn#reindex
  *

  Modified: test/test-table-key-support.rb (+42 -0)
===================================================================
--- test/test-table-key-support.rb    2016-01-15 21:15:40 +0900 (7e8bdd4)
+++ test/test-table-key-support.rb    2016-01-15 21:20:47 +0900 (8fcb900)
@@ -1,4 +1,5 @@
 # Copyright (C) 2013-2014  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2016  Masafumi Yokoyama <yokoyama �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -195,4 +196,45 @@ class TableKeySupportTest < Test::Unit::TestCase
       end
     end
   end
+
+  class ReindexTest < self
+    def test_patricia_trie
+      Groonga::Schema.define do |schema|
+        schema.create_table("Memos",
+                            :type => :array) do |table|
+          table.text("content")
+        end
+        schema.create_table("Terms",
+                            :type => :patricia_trie,
+                            :key_type => :short_text,
+                            :default_tokenizer => "TokenBigram",
+                            :normalizer => "NormalizerAuto") do |table|
+          table.index("Memos.content")
+        end
+      end
+
+      memos = context["Memos"]
+      memos.add(:content => "This is a memo")
+
+      terms = context["Terms"]
+      terms.delete("this")
+
+      assert_equal([
+                     "a",
+                     "is",
+                     "memo",
+                   ],
+                   terms.collect(&:_key).sort)
+
+      terms.reindex
+
+      assert_equal([
+                     "a",
+                     "is",
+                     "memo",
+                     "this",
+                   ],
+                   terms.collect(&:_key).sort)
+    end
+  end
 end

  Modified: test/test-table.rb (+0 -39)
===================================================================
--- test/test-table.rb    2016-01-15 21:15:40 +0900 (a1b79ee)
+++ test/test-table.rb    2016-01-15 21:20:47 +0900 (cbf8b26)
@@ -422,45 +422,6 @@ class TableTest < Test::Unit::TestCase
                  sorted_bookmarks.collect(&:value))
   end
 
-  def test_reindex
-    Groonga::Schema.define do |schema|
-      schema.create_table("Memos",
-                          :type => :array) do |table|
-        table.text("content")
-      end
-      schema.create_table("Terms",
-                          :type => :patricia_trie,
-                          :key_type => :short_text,
-                          :default_tokenizer => "TokenBigram",
-                          :normalizer => "NormalizerAuto") do |table|
-        table.index("Memos.content")
-      end
-    end
-
-    memos = context["Memos"]
-    memos.add(:content => "This is a memo")
-
-    terms = context["Terms"]
-    terms.delete("this")
-
-    assert_equal([
-                   "a",
-                   "is",
-                   "memo",
-                 ],
-                 terms.collect(&:_key).sort)
-
-    terms.reindex
-
-    assert_equal([
-                   "a",
-                   "is",
-                   "memo",
-                   "this",
-                 ],
-                 terms.collect(&:_key).sort)
-  end
-
   sub_test_case "#geo_sort" do
     setup
     def setup_schema
-------------- next part --------------
HTML����������������������������...
Download 



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