[Groonga-commit] ranguba/rroonga at 5147c63 [bind-grn_obj_reindex] Bind grn_obj_reindex()

Back to archive index

Masafumi Yokoyama null+****@clear*****
Tue Jan 5 18:36:52 JST 2016


Masafumi Yokoyama	2016-01-05 18:36:52 +0900 (Tue, 05 Jan 2016)

  New Revision: 5147c63459a00737d5e3deb7be44c1089fd0f1a3
  https://github.com/ranguba/rroonga/commit/5147c63459a00737d5e3deb7be44c1089fd0f1a3

  Message:
    Bind grn_obj_reindex()
    
    TODO:
    
      * Add more tests.
      * Add examples.

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

  Modified: ext/groonga/rb-grn-object.c (+35 -0)
===================================================================
--- ext/groonga/rb-grn-object.c    2016-01-05 15:44:13 +0900 (2f20c25)
+++ ext/groonga/rb-grn-object.c    2016-01-05 18:36:52 +0900 (28cee07)
@@ -1718,6 +1718,39 @@ rb_grn_object_key_accessor_p (VALUE self)
     return CBOOL2RVAL(key_accessor_p);
 }
 
+/*
+ * Recreates one or more index columns.
+ *
+ * This method is a useful when your index column is broken. The
+ * target object is one of database, table and column.
+ *
+ * * If target object is a database, all index columns are recreated.
+ * * If target object is a table, all index columns in the table are recreated.
+ * * If target object is a data column, all index columns for the data column are recreated.
+ * * If target object is an index column, the index column is recreated.
+ *
+ * @overload reindex
+ *   @return void
+ *
+ * @since 5.1.1
+ */
+static VALUE
+rb_grn_object_reindex (VALUE self)
+{
+    grn_ctx *context;
+    grn_obj *object;
+    grn_rc rc;
+
+    rb_grn_object_deconstruct(SELF(self), &object, &context,
+                              NULL, NULL, NULL, NULL);
+
+    rc = grn_obj_reindex(context, object);
+    rb_grn_context_check(context, self);
+    rb_grn_rc_check(rc, self);
+
+    return Qnil;
+}
+
 void
 rb_grn_init_object (VALUE mGrn)
 {
@@ -1767,4 +1800,6 @@ rb_grn_init_object (VALUE mGrn)
                      rb_grn_object_accessor_p, 0);
     rb_define_method(rb_cGrnObject, "key_accessor?",
                      rb_grn_object_key_accessor_p, 0);
+
+    rb_define_method(rb_cGrnObject, "reindex", rb_grn_object_reindex, 0);
 }

  Modified: test/test-column.rb (+37 -0)
===================================================================
--- test/test-column.rb    2016-01-05 15:44:13 +0900 (17d03ea)
+++ test/test-column.rb    2016-01-05 18:36:52 +0900 (662e52a)
@@ -348,6 +348,43 @@ class ColumnTest < Test::Unit::TestCase
     end
   end
 
+  def test_reindex
+    Groonga::Schema.define do |schema|
+      schema.create_table("Memos",
+                          :type => :array) do |table|
+        table.column("content", "Text")
+      end
+      schema.create_table("Terms",
+                          :type => :patricia_trie,
+                          :key_type => "ShortText",
+                          :default_tokenizer => "TokenBigram",
+                          :normalizer => "NormalizerAuto") do |table|
+        table.index("Memos.content")
+      end
+    end
+
+    memos = Groonga["Memos"]
+    memos.add(:content => "This is a memo")
+
+    terms = Groonga["Terms"]
+    terms.delete("this")
+    assert_equal([
+                   "a",
+                   "is",
+                   "memo",
+                 ],
+                 terms.collect(&:_key).sort)
+
+    memos.column(:content).reindex
+    assert_equal([
+                   "a",
+                   "is",
+                   "memo",
+                   "this",
+                 ],
+                 terms.collect(&:_key).sort)
+  end
+
   private
   def assert_content_search(expected_records, term)
     records = @bookmarks_index_content.search(term).records
-------------- next part --------------
HTML����������������������������...
Download 



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