[Groonga-commit] ranguba/rroonga at 32098f7 [bind-grn_obj_reindex] Add Groonga::Database#reindex to bind grn_obj_reindex()

Back to archive index

Hiroshi Hatake hatak****@clear*****
Wed Jan 6 17:00:04 JST 2016


データベースに関するインデックスの再作成なので、

> + * Recreates all index columns.

ではなく、

Recreates all index columns in the database.

のように対象範囲を明確に書いた方が良いと思いました。

--
Hiroshi Hatake <hatak****@clear*****>



2016/01/05 18:36、Masafumi Yokoyama <null+****@clear*****> のメール:

> Author
> Masafumi Yokoyama <yokoy****@clear*****>
> Date
> 2016-01-05 18:36:52 +0900 (Tue, 05 Jan 2016)
> New Revision
> 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)
> ===================================================================
> ...
> 1
> 2
> 3
>  
> 4
> 5
> 6
> ...
> 623
> 624
> 625
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
> 626
> 627
> 628
> ...
> 657
> 658
> 659
>  
> 660
> ...
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> ...
> 624
> 625
> 626
> 627
> 628
> 629
> 630
> 631
> 632
> 633
> 634
> 635
> 636
> 637
> 638
> 639
> 640
> 641
> 642
> 643
> 644
> 645
> 646
> 647
> 648
> 649
> 650
> 651
> 652
> 653
> 654
> 655
> 656
> 657
> 658
> 659
> ...
> 688
> 689
> 690
> 691
> 692
> @@ -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*****>
> +  Copyright (C) 2016  Masafumi Yokoyama <yokoy****@clear*****>
>  
>    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)
> ===================================================================
> ...
> 237
> 238
> 239
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
> 240
> 241
> 242
> ...
> 237
> 238
> 239
> 240
> 241
> 242
> 243
> 244
> 245
> 246
> 247
> 248
> 249
> 250
> 251
> 252
> 253
> 254
> 255
> 256
> 257
> 258
> 259
> 260
> 261
> 262
> 263
> 264
> 265
> 266
> 267
> 268
> 269
> 270
> 271
> 272
> 273
> 274
> 275
> 276
> 277
> 278
> 279
> 280
> 281
> 282
> @@ -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
>  
> _______________________________________________
> Groonga-commit mailing list
> Groon****@lists*****
> http://lists.osdn.me/mailman/listinfo/groonga-commit

-------------- next part --------------
An HTML attachment was scrubbed...
Download 



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