[Groonga-commit] ranguba/rroonga at ef9271a [master] Deprecate Groonga::Column#indexes

Back to archive index

Kouhei Sutou null+****@clear*****
Sat Mar 5 17:32:25 JST 2016


Kouhei Sutou	2016-03-05 17:32:25 +0900 (Sat, 05 Mar 2016)

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

  Message:
    Deprecate Groonga::Column#indexes
    
    Use Groonga::Column#find_indexes instead.

  Modified files:
    ext/groonga/rb-grn-column.c
    lib/groonga/column.rb
    test/test-column.rb

  Modified: ext/groonga/rb-grn-column.c (+0 -46)
===================================================================
--- ext/groonga/rb-grn-column.c    2016-03-05 16:49:59 +0900 (4a98ea6)
+++ ext/groonga/rb-grn-column.c    2016-03-05 17:32:25 +0900 (1a3889f)
@@ -710,51 +710,6 @@ rb_grn_column_with_weight_p(VALUE self)
 }
 
 /*
- * Return indexes on `column` which can execute `operator`.
- * @since 1.0.9
- * @return [Array<index_column>] Indexes on `column` which can execute `operator`.
- * @overload indexes(operator=Groonga::Operator::MATCH)
- *   @param [Groonga::Operator::XXX] operator
- */
-static VALUE
-rb_grn_column_get_indexes (int argc, VALUE *argv, VALUE self)
-{
-    grn_ctx *context;
-    grn_obj *column;
-    grn_index_datum *index_data = NULL;
-    int i, n_indexes;
-    grn_operator operator = GRN_OP_MATCH;
-    VALUE rb_operator, rb_indexes;
-
-    rb_scan_args(argc, argv, "01", &rb_operator);
-
-    rb_grn_column_deconstruct(SELF(self), &column, &context,
-                             NULL, NULL,
-                             NULL, NULL, NULL);
-
-    if (!NIL_P(rb_operator)) {
-        operator = RVAL2GRNOPERATOR(rb_operator);
-    }
-
-    rb_indexes = rb_ary_new();
-    n_indexes = grn_column_find_index_data(context, column, operator, NULL, 0);
-    if (n_indexes == 0)
-        return rb_indexes;
-
-    index_data = xmalloc(sizeof(grn_index_datum) * n_indexes);
-    n_indexes = grn_column_find_index_data(context, column, operator,
-                                           index_data, n_indexes);
-    for (i = 0; i < n_indexes; i++) {
-        VALUE rb_index;
-        rb_index = GRNOBJECT2RVAL(Qnil, context, index_data[i].index, GRN_FALSE);
-        rb_ary_push(rb_indexes, rb_index);
-        grn_obj_unlink(context, index_data[i].index);
-    }
-    xfree(index_data);
-    return rb_indexes;
-}
-
-/*
  * Return indexes on `column`. If operator is specified, indexes that
  * can executes the operator are only returned. Otherwise, all indexes
  * are returned.
@@ -886,7 +841,6 @@ rb_grn_init_column (VALUE mGrn)
     rb_define_method(rb_cGrnColumn, "with_weight?",
                      rb_grn_column_with_weight_p, 0);
 
-    rb_define_method(rb_cGrnColumn, "indexes", rb_grn_column_get_indexes, -1);
     rb_define_method(rb_cGrnColumn, "find_indexes",
                      rb_grn_column_find_indexes, -1);
 

  Modified: lib/groonga/column.rb (+13 -0)
===================================================================
--- lib/groonga/column.rb    2016-03-05 16:49:59 +0900 (0b8b47f)
+++ lib/groonga/column.rb    2016-03-05 17:32:25 +0900 (58ef388)
@@ -21,5 +21,18 @@ module Groonga
       measurer = StatisticMeasurer.new
       measurer.measure_disk_usage(path)
     end
+
+    # @param [Groonga::Operator] operator (Groonga::Operator::MATCH)
+    # @return [Array<Groonga::IndexColumn>] Indexes on `column` which can
+    #    execute `operator`.
+    # @since 1.0.9
+    #
+    # @deprecated since 6.0.0. Use {Groonga::Column#find_indexes} instead.
+    def indexes(operator=nil)
+      operator ||= Operator::MATCH
+      find_indexes(:operator => operator).collect do |index|
+        index.column
+      end
+    end
   end
 end

  Modified: test/test-column.rb (+34 -0)
===================================================================
--- test/test-column.rb    2016-03-05 16:49:59 +0900 (af21691)
+++ test/test-column.rb    2016-03-05 17:32:25 +0900 (2124afd)
@@ -655,5 +655,39 @@ class ColumnTest < Test::Unit::TestCase
                      @title.find_indexes)
       end
     end
+
+    class OperatorTest < self
+      def setup
+        super
+        Groonga::Schema.define do |schema|
+          schema.create_table("Comments") do |table|
+            table.short_text("title")
+            table.short_text("body")
+          end
+        end
+        @title = Groonga["Comments.title"]
+      end
+
+      def test_equal
+        Groonga::Schema.define do |schema|
+          schema.create_table("Terms",
+                              :type => :patricia_trie,
+                              :key_type => :short_text,
+                              :default_tokenizer => "TokenBigram") do |table|
+            table.index("Comments.title")
+          end
+
+          schema.create_table("Titles",
+                              :type => :patricia_trie,
+                              :key_type => :short_text) do |table|
+            table.index("Comments.title")
+          end
+        end
+        assert_equal([
+                       Groonga::Index.new(Groonga["Titles.Comments_title"], 0),
+                     ],
+                     @title.find_indexes(:operator => :equal))
+      end
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
下载 



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