[Groonga-commit] ranguba/rroonga at ebf3ad8 [master] Enable with_position flag by default for a table that has the default tokenizer

Back to archive index

Kouhei Sutou null+****@clear*****
Fri May 30 18:42:38 JST 2014


Kouhei Sutou	2014-05-30 18:42:38 +0900 (Fri, 30 May 2014)

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

  Message:
    Enable with_position flag by default for a table that has the default tokenizer

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

  Modified: ext/groonga/rb-grn-table.c (+1 -22)
===================================================================
--- ext/groonga/rb-grn-table.c    2014-05-30 18:42:03 +0900 (2e656ba)
+++ ext/groonga/rb-grn-table.c    2014-05-30 18:42:38 +0900 (3ab1552)
@@ -335,27 +335,6 @@ rb_grn_table_define_column (int argc, VALUE *argv, VALUE self)
     return rb_column;
 }
 
-static grn_bool
-n_gram_tokenizer_p(grn_ctx *context, grn_obj *tokenizer)
-{
-    char tokenizer_name[GRN_TABLE_MAX_KEY_SIZE];
-    int name_size;
-
-    name_size = grn_obj_name(context, tokenizer,
-                             tokenizer_name, sizeof(tokenizer_name) - 1);
-    if (name_size == 0)
-        return GRN_FALSE;
-
-    tokenizer_name[name_size] = '\0';
-
-#define HAVE_PREFIX_P(prefix) \
-    (strncmp(tokenizer_name, prefix, strlen(prefix)) == 0)
-    return (HAVE_PREFIX_P("TokenUnigram") ||
-            HAVE_PREFIX_P("TokenBigram") ||
-            HAVE_PREFIX_P("TokenTrigram"));
-#undef HAVE_PREFIX_P
-}
-
 /*
  * テーブルに名前が _name_ で型が _value_type_ のインデックスカ
  * ラムを定義し、新しく定義されたカラムを返す。
@@ -454,7 +433,7 @@ rb_grn_table_define_index_column (int argc, VALUE *argv, VALUE self)
         tokenizer = grn_obj_get_info(context, table,
                                      GRN_INFO_DEFAULT_TOKENIZER,
                                      NULL);
-        if (tokenizer && n_gram_tokenizer_p(context, tokenizer)) {
+        if (tokenizer) {
             rb_with_position = Qtrue;
         }
     }

  Modified: lib/groonga/schema.rb (+4 -2)
===================================================================
--- lib/groonga/schema.rb    2014-05-30 18:42:03 +0900 (9397220)
+++ lib/groonga/schema.rb    2014-05-30 18:42:38 +0900 (751bb11)
@@ -962,8 +962,10 @@ module Groonga
       #   - :with_position :=
       #     +true+ を指定すると転置索引に出現位置情報を合わせて
       #     格納する。未指定または +nil+ を指定した場合、テーブル
-      #     がN-gram系のトークナイザーを利用している場合は
-      #     自動的に有効になる。 =:
+      #     がトークナイザー利用している場合は自動的に有効になる。
+      #     +TokenDelimit+ など全文検索用ではないトークナイザーを
+      #     使う場合は明示的に +false+ を指定することで使用リソース
+      #     を少なくできる。=:
       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)

  Modified: test/test-database-dumper.rb (+2 -2)
===================================================================
--- test/test-database-dumper.rb    2014-05-30 18:42:03 +0900 (4dee37b)
+++ test/test-database-dumper.rb    2014-05-30 18:42:38 +0900 (93535cd)
@@ -50,7 +50,7 @@ class DatabaseDumperTest < Test::Unit::TestCase
       end
 
       schema.change_table("Tags") do |table|
-        table.index("Posts.tag_text")
+        table.index("Posts.tag_text", :with_position => false)
       end
     end
   end
@@ -298,7 +298,7 @@ load --table Users
                             :type => :hash,
                             :key_type => :short_text,
                             :default_tokenizer => :delimit) do |table|
-          table.index("Posts.tag_text")
+          table.index("Posts.tag_text", :with_position => false)
         end
       end
     end

  Modified: test/test-index-column.rb (+9 -4)
===================================================================
--- test/test-index-column.rb    2014-05-30 18:42:03 +0900 (c4c2aa6)
+++ test/test-index-column.rb    2014-05-30 18:42:38 +0900 (9231552)
@@ -287,20 +287,25 @@ class IndexColumnTest < Test::Unit::TestCase
                             :key_type => "ShortText",
                             :default_tokenizer => "TokenDelimit") do |table|
           table.index("Articles.tags",
-                      :name => "position",
+                      :name => "true",
                       :with_position => true)
           table.index("Articles.tags",
-                      :name => "no_position")
+                      :name => "default")
+          table.index("Articles.tags",
+                      :name => "false",
+                      :with_position => false)
         end
       end
 
       assert_equal([
                      true,
                      false,
+                     true,
                    ],
                    [
-                     context["Tags.position"].with_position?,
-                     context["Tags.no_position"].with_position?,
+                     context["Tags.true"].with_position?,
+                     context["Tags.false"].with_position?,
+                     context["Tags.default"].with_position?,
                    ])
     end
   end
-------------- next part --------------
HTML����������������������������...
Download 



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