[Groonga-commit] ranguba/rroonga at 32098f7 [bind-grn_obj_reindex] Add Groonga::Database#reindex to 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: 32098f790cddd154e29ec624e23d806d530a888f
  https://github.com/ranguba/rroonga/commit/32098f790cddd154e29ec624e23d806d530a888f

  Message:
    Add Groonga::Database#reindex to bind grn_obj_reindex()
    
    GitHub: #110

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

  Modified: ext/groonga/rb-grn-database.c (+32 -0)
===================================================================
--- ext/groonga/rb-grn-database.c    2016-01-06 16:44:44 +0900 (93c92a5)
+++ ext/groonga/rb-grn-database.c    2016-01-05 18:36:52 +0900 (688be5a)
@@ -1,6 +1,7 @@
 /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
   Copyright (C) 2009-2015  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
@@ -623,6 +624,36 @@ rb_grn_database_unmap (VALUE self)
     return Qnil;
 }
 
+/*
+ * Recreates all index columns.
+ *
+ * This method is useful when your index column is broken.
+ *
+ * @example
+ *   database.reindex
+ *
+ * @overload reindex
+ *   @return [void]
+ *
+ * @since 5.1.1
+ */
+static VALUE
+rb_grn_database_reindex (VALUE self)
+{
+    grn_rc rc;
+    grn_ctx *context;
+    grn_obj *database;
+
+    rb_grn_database_deconstruct(SELF(self), &database, &context,
+                                NULL, NULL, NULL, NULL);
+
+    rc = grn_obj_reindex(context, database);
+    rb_grn_context_check(context, self);
+    rb_grn_rc_check(rc, self);
+
+    return Qnil;
+}
+
 void
 rb_grn_init_database (VALUE mGrn)
 {
@@ -657,4 +688,5 @@ rb_grn_init_database (VALUE mGrn)
     rb_define_method(rb_cGrnDatabase, "defrag", rb_grn_database_defrag, -1);
     rb_define_method(rb_cGrnDatabase, "recover", rb_grn_database_recover, 0);
     rb_define_method(rb_cGrnDatabase, "unmap", rb_grn_database_unmap, 0);
+    rb_define_method(rb_cGrnDatabase, "reindex", rb_grn_database_reindex, 0);
 }

  Modified: test/test-database.rb (+40 -0)
===================================================================
--- test/test-database.rb    2016-01-06 16:44:44 +0900 (22209bf)
+++ test/test-database.rb    2016-01-05 18:36:52 +0900 (f1dc0ef)
@@ -237,6 +237,46 @@ class DatabaseTest < Test::Unit::TestCase
                  @database.plugin_paths)
   end
 
+  def test_reindex
+    setup_database
+    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 = context["Memos"]
+    memos.add(:content => "This is a memo")
+
+    terms = context["Terms"]
+    terms.delete("this")
+
+    assert_equal([
+                   "a",
+                   "is",
+                   "memo",
+                 ],
+                 terms.collect(&:_key).sort)
+
+    @database.reindex
+
+    assert_equal([
+                   "a",
+                   "is",
+                   "memo",
+                   "this",
+                 ],
+                 terms.collect(&:_key).sort)
+  end
+
   class RemoveTest < self
     setup :setup_database
 
-------------- next part --------------
HTML����������������������������...
Download 



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