[Groonga-commit] ranguba/rroonga at a41f475 [support-index-small-and-index-medium] Support INDEX_SMALL and INDEX_MEDIUM flags

Back to archive index

Kentaro Hayashi null+****@clear*****
Tue Nov 1 15:54:53 JST 2016


Kentaro Hayashi	2016-11-01 15:54:53 +0900 (Tue, 01 Nov 2016)

  New Revision: a41f4753ccee17a2e30f7b51b771a3e87c9ffe3c
  https://github.com/ranguba/rroonga/commit/a41f4753ccee17a2e30f7b51b771a3e87c9ffe3c

  Message:
    Support INDEX_SMALL and INDEX_MEDIUM flags
    
    Use index_small => true or index_medium => true.

  Modified files:
    ext/groonga/rb-grn-index-column.c
    ext/groonga/rb-grn-object.c
    ext/groonga/rb-grn-table.c
    lib/groonga/dumper.rb
    lib/groonga/schema.rb
    test/test-index-column.rb

  Modified: ext/groonga/rb-grn-index-column.c (+61 -0)
===================================================================
--- ext/groonga/rb-grn-index-column.c    2016-10-31 00:29:50 +0900 (437abaa)
+++ ext/groonga/rb-grn-index-column.c    2016-11-01 15:54:53 +0900 (54a307b)
@@ -884,6 +884,48 @@ rb_grn_index_column_with_position_p (VALUE self)
 }
 
 /*
+ * _column_ が小さなインデックスを作成する場合は +true+ を返します。
+ *
+ * @overload index_small?
+ */
+static VALUE
+rb_grn_index_column_with_index_small_p (VALUE self)
+{
+    grn_obj *column;
+    grn_ctx *context;
+    grn_column_flags flags;
+
+    rb_grn_index_column_deconstruct(SELF(self), &column, &context,
+                                    NULL, NULL,
+                                    NULL, NULL, NULL, NULL, NULL,
+                                    NULL, NULL);
+
+    flags = grn_column_get_flags(context, column);
+    return CBOOL2RVAL(flags & GRN_OBJ_INDEX_SMALL);
+}
+
+/*
+ * _column_ が中サイズのインデックスを作成する場合は +true+ を返します。
+ *
+ * @overload index_medium?
+ */
+static VALUE
+rb_grn_index_column_with_index_medium_p (VALUE self)
+{
+    grn_obj *column;
+    grn_ctx *context;
+    grn_column_flags flags;
+
+    rb_grn_index_column_deconstruct(SELF(self), &column, &context,
+                                    NULL, NULL,
+                                    NULL, NULL, NULL, NULL, NULL,
+                                    NULL, NULL);
+
+    flags = grn_column_get_flags(context, column);
+    return CBOOL2RVAL(flags & GRN_OBJ_INDEX_MEDIUM);
+}
+
+/*
  * Opens cursor to iterate posting in the index column.
  *
  * @example
@@ -917,6 +959,7 @@ rb_grn_index_column_open_cursor (int argc, VALUE *argv, VALUE self)
     VALUE             rb_table_cursor;
     VALUE             options;
     VALUE             rb_with_section, rb_with_weight, rb_with_position;
+    VALUE             rb_index_small, rb_index_medium;
     VALUE             rb_table;
     VALUE             rb_lexicon;
     VALUE             rb_cursor;
@@ -932,6 +975,8 @@ rb_grn_index_column_open_cursor (int argc, VALUE *argv, VALUE self)
                         "with_section", &rb_with_section,
                         "with_weight", &rb_with_weight,
                         "with_position", &rb_with_position,
+                        "index_small", &rb_index_small,
+                        "index_medium", &rb_index_medium,
                         NULL);
 
     table_cursor = RVAL2GRNTABLECURSOR(rb_table_cursor, NULL);
@@ -958,6 +1003,18 @@ rb_grn_index_column_open_cursor (int argc, VALUE *argv, VALUE self)
         flags |= GRN_OBJ_WITH_POSITION;
     }
 
+    if (NIL_P(rb_index_small)) {
+        flags |= column_flags & GRN_OBJ_INDEX_SMALL;
+    } else if (RVAL2CBOOL(rb_index_small)) {
+        flags |= GRN_OBJ_INDEX_SMALL;
+    }
+
+    if (NIL_P(rb_index_medium)) {
+        flags |= column_flags & GRN_OBJ_INDEX_MEDIUM;
+    } else if (RVAL2CBOOL(rb_index_medium)) {
+        flags |= GRN_OBJ_INDEX_MEDIUM;
+    }
+
     index_cursor = grn_index_cursor_open(context, table_cursor,
                                          column, rid_min, rid_max, flags);
 
@@ -1310,6 +1367,10 @@ rb_grn_init_index_column (VALUE mGrn)
                      rb_grn_index_column_with_weight_p, 0);
     rb_define_method(rb_cGrnIndexColumn, "with_position?",
                      rb_grn_index_column_with_position_p, 0);
+    rb_define_method(rb_cGrnIndexColumn, "index_small?",
+                     rb_grn_index_column_with_index_small_p, 0);
+    rb_define_method(rb_cGrnIndexColumn, "index_medium?",
+                     rb_grn_index_column_with_index_medium_p, 0);
 
     rb_define_method(rb_cGrnIndexColumn, "open_cursor",
                      rb_grn_index_column_open_cursor, -1);

  Modified: ext/groonga/rb-grn-object.c (+4 -0)
===================================================================
--- ext/groonga/rb-grn-object.c    2016-10-31 00:29:50 +0900 (931fb32)
+++ ext/groonga/rb-grn-object.c    2016-11-01 15:54:53 +0900 (4807986)
@@ -927,6 +927,10 @@ rb_grn_object_inspect_content_flags_with_label (VALUE inspected,
             rb_ary_push(inspected_flags, rb_str_new_cstr("WITH_WEIGHT"));
         if (column_flags & GRN_OBJ_WITH_POSITION)
             rb_ary_push(inspected_flags, rb_str_new_cstr("WITH_POSITION"));
+        if (column_flags & GRN_OBJ_INDEX_SMALL)
+            rb_ary_push(inspected_flags, rb_str_new_cstr("INDEX_SMALL"));
+        if (column_flags & GRN_OBJ_INDEX_MEDIUM)
+            rb_ary_push(inspected_flags, rb_str_new_cstr("INDEX_MEDIUM"));
         break;
     default:
         break;

  Modified: ext/groonga/rb-grn-table.c (+16 -0)
===================================================================
--- ext/groonga/rb-grn-table.c    2016-10-31 00:29:50 +0900 (a094a4b)
+++ ext/groonga/rb-grn-table.c    2016-11-01 15:54:53 +0900 (896a31b)
@@ -357,6 +357,10 @@ rb_grn_table_define_column (int argc, VALUE *argv, VALUE self)
  *     転置索引にweight情報を合わせて格納する。
  *   @option options :with_position
  *     転置索引に出現位置情報を合わせて格納する。
+ *   @option options :index_small
+ *     小さなサイズのインデックスを作成する。
+ *   @option options :index_medium
+ *     中サイズのインデックスを作成する。
  *   @option options :source
  *    インデックス対象となるカラムを指定する。 +:sources+ との併用はできない。
  *   @option options :sources
@@ -376,6 +380,7 @@ rb_grn_table_define_index_column (int argc, VALUE *argv, VALUE self)
     VALUE rb_name, rb_value_type;
     VALUE options, rb_path, rb_persistent;
     VALUE rb_with_section, rb_with_weight, rb_with_position;
+    VALUE rb_index_small, rb_index_medium;
     VALUE rb_column, rb_source, rb_sources;
     VALUE columns;
 
@@ -395,6 +400,8 @@ rb_grn_table_define_index_column (int argc, VALUE *argv, VALUE self)
                         "with_section", &rb_with_section,
                         "with_weight", &rb_with_weight,
                         "with_position", &rb_with_position,
+                        "index_small", &rb_index_small,
+                        "index_medium", &rb_index_medium,
                         "source", &rb_source,
                         "sources", &rb_sources,
                         NULL);
@@ -443,6 +450,15 @@ rb_grn_table_define_index_column (int argc, VALUE *argv, VALUE self)
     if (RVAL2CBOOL(rb_with_position))
         flags |= GRN_OBJ_WITH_POSITION;
 
+    if (!NIL_P(rb_index_small) && !NIL_P(rb_index_medium))
+        rb_raise(rb_eArgError, "should not pass both of :index_small and :index_medium.");
+
+    if (RVAL2CBOOL(rb_index_small)) {
+        flags |= GRN_OBJ_INDEX_SMALL;
+    } else if (RVAL2CBOOL(rb_index_medium)) {
+        flags |= GRN_OBJ_INDEX_MEDIUM;
+    }
+
     if (!NIL_P(rb_source) && !NIL_P(rb_sources))
         rb_raise(rb_eArgError, "should not pass both of :source and :sources.");
 

  Modified: lib/groonga/dumper.rb (+4 -0)
===================================================================
--- lib/groonga/dumper.rb    2016-10-31 00:29:50 +0900 (51d7fbc)
+++ lib/groonga/dumper.rb    2016-11-01 15:54:53 +0900 (862dc69)
@@ -487,6 +487,8 @@ module Groonga
         options[:with_section]  = true if column.with_section?
         options[:with_weight]   = true if column.with_weight?
         options[:with_position] = true if column.with_position?
+        options[:index_small] = true if column.index_small?
+        options[:index_medium] = true if column.index_medium?
         arguments = [
           dump_object(target_table_name),
           sources.size == 1 ? source_names : "[#{source_names}]",
@@ -643,6 +645,8 @@ module Groonga
         flags << "WITH_SECTION" if column.with_section?
         flags << "WITH_WEIGHT" if column.with_weight?
         flags << "WITH_POSITION" if column.with_position?
+        flags << "INDEX_SMALL" if column.index_small?
+        flags << "INDEX_MEDIUM" if column.index_medium?
         parameters << "#{flags.join('|')}"
         parameters << "#{column.range.name}"
         source_names = column.sources.collect do |source|

  Modified: lib/groonga/schema.rb (+8 -0)
===================================================================
--- lib/groonga/schema.rb    2016-10-31 00:29:50 +0900 (c77bdfd)
+++ lib/groonga/schema.rb    2016-11-01 15:54:53 +0900 (90343e1)
@@ -936,6 +936,12 @@ module Groonga
       #     +TokenDelimit+ など全文検索用ではないトークナイザーを
       #     使う場合は明示的に +false+ を指定することで使用リソース
       #     を少なくできる。=:
+      #   - :index_small :=
+      #     +true+ を指定すると小さなサイズのインデックスを
+      #     作成することができる。=:
+      #   - :index_medium :=
+      #     +true+ を指定すると中サイズのインデックスを
+      #     作成することができる。=:
       def index(target_table_or_target_column_full_name, *args)
         key, target_table, target_columns, options =
           parse_index_argument(target_table_or_target_column_full_name, *args)
@@ -1697,6 +1703,8 @@ module Groonga
           :with_section => @options[:with_section],
           :with_weight => @options[:with_weight],
           :with_position => @options[:with_position],
+          :index_small => @options[:index_small],
+          :index_medium => @options[:index_medium],
         }
       end
 

  Modified: test/test-index-column.rb (+58 -0)
===================================================================
--- test/test-index-column.rb    2016-10-31 00:29:50 +0900 (aff362c)
+++ test/test-index-column.rb    2016-11-01 15:54:53 +0900 (9dd40ea)
@@ -378,6 +378,64 @@ class IndexColumnTest < Test::Unit::TestCase
                      context["Tags.default"].with_position?,
                    ])
     end
+
+    def test_index_small?
+      Groonga::Schema.define do |schema|
+        schema.create_table("Tags",
+                            :type => :patricia_trie,
+                            :key_type => "ShortText",
+                            :default_tokenizer => "TokenDelimit") do |table|
+          table.index("Articles.tags",
+                      :name => "true",
+                      :index_small => true)
+          table.index("Articles.tags",
+                      :name => "default")
+          table.index("Articles.tags",
+                      :name => "false",
+                      :index_small => false)
+        end
+      end
+
+      assert_equal([
+                     true,
+                     false,
+                     false,
+                   ],
+                   [
+                     context["Tags.true"].index_small?,
+                     context["Tags.false"].index_small?,
+                     context["Tags.default"].index_small?,
+                   ])
+    end
+
+    def test_index_medium?
+      Groonga::Schema.define do |schema|
+        schema.create_table("Tags",
+                            :type => :patricia_trie,
+                            :key_type => "ShortText",
+                            :default_tokenizer => "TokenDelimit") do |table|
+          table.index("Articles.tags",
+                      :name => "true",
+                      :index_medium => true)
+          table.index("Articles.tags",
+                      :name => "default")
+          table.index("Articles.tags",
+                      :name => "false",
+                      :index_medium => false)
+        end
+      end
+
+      assert_equal([
+                     true,
+                     false,
+                     false,
+                   ],
+                   [
+                     context["Tags.true"].index_medium?,
+                     context["Tags.false"].index_medium?,
+                     context["Tags.default"].index_medium?,
+                   ])
+    end
   end
 
   class SourceTest < self
-------------- next part --------------
HTML����������������������������...
Download 



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