rroonga 4.0.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8fdfe9138a4546d1c3d4f7475d92f57d664f23a8
4
- data.tar.gz: 39eab083625dc558c5287aa34eb202b2f7e418b7
3
+ metadata.gz: 53910c50882ceba0c8c1fd10471076e0c9adb48e
4
+ data.tar.gz: 97c9676d4436ce853b7d684e3c8a70fabb9bf023
5
5
  SHA512:
6
- metadata.gz: d345881451aecc7c1fefdfeb15f62f7df6a01de07c478b372496828aec5dc74789369fac4b4185c514ac44d8fa43914974cfc966fb57736ea19169e31706c388
7
- data.tar.gz: 30216dcfe16899e6647cb084dcdff4b5742c8ae67859bb79c4bd4221e3af123388e68680a1a222a0658e1cb36b79a8b712ae4d62cced0fdb1748db0fb55501c4
6
+ metadata.gz: 05cd87977c479c0c95d4fcab3bb0d6e41b2f9f798dda965f671066d55e3b495bcbf5e41677bccdb539f1041739528ed5f520bb8c738ac6f088973cc56ab900da
7
+ data.tar.gz: 2b359a701d8d188b155e7dbc2a334930221df42d243811468b60f67e3acd89da3c2e7c1bb51d14233c6bab3d60dec58894405863bb53f949954065794717741b
data/.yardopts ADDED
@@ -0,0 +1,6 @@
1
+ --output-dir doc/reference/en
2
+ --markup textile
3
+ lib/**/*.rb
4
+ ext/**/*.c
5
+ -
6
+ doc/text/*
@@ -1,5 +1,31 @@
1
1
  h1. NEWS
2
2
 
3
+ h2(#4-0-1). 4.0.1: 2014-04-04
4
+
5
+ h3. Improvements
6
+
7
+ * Supported Groonga 4.0.1. Groonga 4.0.0 or older are not supported.
8
+ * Supported no weight match column case.
9
+ <pre>
10
+ table.select do |record|
11
+ match_target = record.match_target do |target|
12
+ target.column
13
+ end
14
+ match_target =~ keyword
15
+ end
16
+ </pre>
17
+ * Supported weight vector.
18
+ * grndump: Changed to use @--normalizer@ instead of @KEY_NORMALIZE@.
19
+ Old Groonga can't restore dumped database.
20
+ * {Groonga::IndexClumn#search}: Added @mode@ option.
21
+ * {Groonga::IndexClumn#search}: Added @weight@ option.
22
+ * Accepted String as option key.
23
+
24
+ h3. Fixes
25
+
26
+ * Fixed a bug that index dump drops index options in Ruby syntax.
27
+
28
+
3
29
  h2(#4-0-0). 4.0.0: 2014-02-09
4
30
 
5
31
  h3. Improvements
@@ -1,7 +1,7 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /* vim: set sts=4 sw=4 ts=8 noet: */
3
3
  /*
4
- Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
4
+ Copyright (C) 2009-2014 Kouhei Sutou <kou@clear-code.com>
5
5
 
6
6
  This library is free software; you can redistribute it and/or
7
7
  modify it under the terms of the GNU Lesser General Public
@@ -71,10 +71,29 @@ rb_grn_column_bind (RbGrnColumn *rb_column,
71
71
  grn_ctx *context, grn_obj *column)
72
72
  {
73
73
  RbGrnObject *rb_grn_object;
74
+ int column_type;
75
+ unsigned char value_type;
74
76
 
75
77
  rb_grn_object = RB_GRN_OBJECT(rb_column);
76
78
  rb_grn_named_object_bind(RB_GRN_NAMED_OBJECT(rb_column), context, column);
77
- rb_column->value = grn_obj_open(context, GRN_BULK, 0,
79
+
80
+ column_type = (column->header.flags & GRN_OBJ_COLUMN_TYPE_MASK);
81
+ if (column_type == GRN_OBJ_COLUMN_VECTOR) {
82
+ switch (rb_grn_object->range->header.type) {
83
+ case GRN_TABLE_HASH_KEY:
84
+ case GRN_TABLE_PAT_KEY:
85
+ case GRN_TABLE_DAT_KEY:
86
+ case GRN_TABLE_NO_KEY:
87
+ value_type = GRN_UVECTOR;
88
+ break;
89
+ default:
90
+ value_type = GRN_VECTOR;
91
+ break;
92
+ }
93
+ } else {
94
+ value_type = GRN_BULK;
95
+ }
96
+ rb_column->value = grn_obj_open(context, value_type, 0,
78
97
  rb_grn_object->range_id);
79
98
  }
80
99
 
@@ -674,6 +693,24 @@ rb_grn_column_scalar_p (VALUE self)
674
693
  }
675
694
  }
676
695
 
696
+ /*
697
+ * @overload with_weight?
698
+ * @return [Boolean] @true@ if the column is vector and created with
699
+ * @:with_weight => true@ flag, @false@ otherwise.
700
+ * @since 4.0.1
701
+ */
702
+ static VALUE
703
+ rb_grn_column_with_weight_p(VALUE self)
704
+ {
705
+ grn_obj *column;
706
+
707
+ rb_grn_column_deconstruct(SELF(self), &column, NULL,
708
+ NULL, NULL,
709
+ NULL, NULL, NULL);
710
+
711
+ return CBOOL2RVAL(column->header.flags & GRN_OBJ_WITH_WEIGHT);
712
+ }
713
+
677
714
  /*
678
715
  * _operator_ を実行できる _column_ のインデックスを返す。
679
716
  * @since 1.0.9
@@ -772,6 +809,9 @@ rb_grn_init_column (VALUE mGrn)
772
809
  rb_define_method(rb_cGrnColumn, "vector?", rb_grn_column_vector_p, 0);
773
810
  rb_define_method(rb_cGrnColumn, "scalar?", rb_grn_column_scalar_p, 0);
774
811
 
812
+ rb_define_method(rb_cGrnColumn, "with_weight?",
813
+ rb_grn_column_with_weight_p, 0);
814
+
775
815
  rb_define_method(rb_cGrnColumn, "indexes", rb_grn_column_get_indexes, -1);
776
816
 
777
817
  rb_define_method(rb_cGrnColumn, "rename", rb_grn_column_rename, 1);
@@ -1,6 +1,6 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /*
3
- Copyright (C) 2009-2013 Kouhei Sutou <kou@clear-code.com>
3
+ Copyright (C) 2009-2014 Kouhei Sutou <kou@clear-code.com>
4
4
 
5
5
  This library is free software; you can redistribute it and/or
6
6
  modify it under the terms of the GNU Lesser General Public
@@ -44,6 +44,7 @@ rb_grn_index_column_finalizer (grn_ctx *context, grn_obj *object,
44
44
  grn_obj_unlink(context, rb_grn_index_column->id_query);
45
45
  grn_obj_unlink(context, rb_grn_index_column->string_query);
46
46
  grn_obj_unlink(context, rb_grn_index_column->old_value);
47
+ grn_obj_unlink(context, rb_grn_index_column->set_value);
47
48
 
48
49
  rb_grn_column_finalizer(context, object, RB_GRN_COLUMN(rb_grn_index_column));
49
50
  }
@@ -59,6 +60,9 @@ rb_grn_index_column_bind (RbGrnIndexColumn *rb_grn_index_column,
59
60
 
60
61
  rb_grn_index_column->old_value = grn_obj_open(context, GRN_BULK, 0,
61
62
  rb_grn_object->range_id);
63
+ rb_grn_index_column->set_value =
64
+ grn_obj_open(context, GRN_VECTOR, 0,
65
+ rb_grn_object->range->header.domain);
62
66
 
63
67
  rb_grn_index_column->id_query = grn_obj_open(context, GRN_BULK, 0,
64
68
  rb_grn_object->domain_id);
@@ -75,6 +79,7 @@ rb_grn_index_column_deconstruct (RbGrnIndexColumn *rb_grn_index_column,
75
79
  grn_obj **domain,
76
80
  grn_obj **value,
77
81
  grn_obj **old_value,
82
+ grn_obj **set_value,
78
83
  grn_id *range_id,
79
84
  grn_obj **range,
80
85
  grn_obj **id_query,
@@ -89,138 +94,14 @@ rb_grn_index_column_deconstruct (RbGrnIndexColumn *rb_grn_index_column,
89
94
 
90
95
  if (old_value)
91
96
  *old_value = rb_grn_index_column->old_value;
97
+ if (set_value)
98
+ *set_value = rb_grn_index_column->set_value;
92
99
  if (id_query)
93
100
  *id_query = rb_grn_index_column->id_query;
94
101
  if (string_query)
95
102
  *string_query = rb_grn_index_column->string_query;
96
103
  }
97
104
 
98
- /*
99
- * IDが _id_ であるレコードを高速に全文検索するため転置索引を作
100
- * 成する。多くの場合、 {Groonga::Table#define_index_column} で
101
- * +:source+ オプションを指定することにより、自動的に全文検索
102
- * 用の索引は更新されるので、明示的にこのメソッドを使うこと
103
- * は少ない。
104
- *
105
- * @example 記事の段落毎に索引を作成する。
106
- * articles = Groonga::Array.create(:name => "<articles>")
107
- * articles.define_column("title", "ShortText")
108
- * articles.define_column("content", "Text")
109
- *
110
- * terms = Groonga::Hash.create(:name => "<terms>",
111
- * :default_tokenizer => "TokenBigram")
112
- * content_index = terms.define_index_column("content", articles,
113
- * :with_section => true)
114
- *
115
- * content = <<-EOC
116
- * groonga は組み込み型の全文検索エンジンライブラリです。
117
- * DBMSやスクリプト言語処理系等に組み込むことによって、その
118
- * 全文検索機能を強化することができます。また、リレーショナ
119
- * ルモデルに基づくデータストア機能を内包しており、groonga
120
- * 単体でも高速なデータストアサーバとして使用することができ
121
- * ます。
122
- *
123
- * ■全文検索方式
124
- * 転置索引型の全文検索エンジンです。転置索引は圧縮されてファ
125
- * イルに格納され、検索時のディスク読み出し量を小さく、かつ
126
- * 局所的に抑えるように設計されています。用途に応じて以下の
127
- * 索引タイプを選択できます。
128
- * EOC
129
- *
130
- * groonga = articles.add(:title => "groonga", :content => content)
131
- *
132
- * content.split(/\n{2,}/).each_with_index do |sentence, i|
133
- * content_index[groonga] = {:value => sentence, :section => i + 1}
134
- * end
135
- *
136
- * content_index.search("エンジン").collect do |record|
137
- * p record.key["title"] # -> "groonga"
138
- * end
139
- *
140
- * @overload []=(id, value)
141
- * @param [String] value 新しい値
142
- * @overload []=(id, options)
143
- * _options_ を指定することにより、 _value_ を指定したときよりも索引の作
144
- * 成を制御できる。
145
- * @param [::Hash] options The name and value
146
- * pairs. Omitted names are initialized as the default value
147
- * @option options :section
148
- * 段落番号を指定する。省略した場合は1を指定したとみなされ
149
- * る。
150
- * {Groonga::Table#define_index_column} で
151
- * @{:with_section => true}@ を指定していなければい
152
- * けない。
153
- * @option options :old_value
154
- * 以前の値を指定する。省略した場合は現在の値が用いられる。
155
- * 通常は指定する必要はない。
156
- * @option options :value
157
- * 新しい値を指定する。 _value_ を指定した場合と _options_ で
158
- * @{:value => value}@ を指定した場合は同じ動作とな
159
- * る。
160
- *
161
- * @deprecated Since 3.0.2. Use {#add}, {#delete} or {#update} instead.
162
- */
163
- static VALUE
164
- rb_grn_index_column_array_set (VALUE self, VALUE rb_id, VALUE rb_value)
165
- {
166
- grn_ctx *context = NULL;
167
- grn_obj *column, *range;
168
- grn_rc rc;
169
- grn_id id;
170
- unsigned int section;
171
- grn_obj *old_value, *new_value;
172
- VALUE original_rb_value, rb_section, rb_old_value, rb_new_value;
173
-
174
- original_rb_value = rb_value;
175
-
176
- rb_grn_index_column_deconstruct(SELF(self), &column, &context,
177
- NULL, NULL,
178
- &new_value, &old_value,
179
- NULL, &range,
180
- NULL, NULL);
181
-
182
- id = RVAL2GRNID(rb_id, context, range, self);
183
-
184
- if (!RVAL2CBOOL(rb_obj_is_kind_of(rb_value, rb_cHash))) {
185
- VALUE hash_value;
186
- hash_value = rb_hash_new();
187
- rb_hash_aset(hash_value, RB_GRN_INTERN("value"), rb_value);
188
- rb_value = hash_value;
189
- }
190
-
191
- rb_grn_scan_options(rb_value,
192
- "section", &rb_section,
193
- "old_value", &rb_old_value,
194
- "value", &rb_new_value,
195
- NULL);
196
-
197
- if (NIL_P(rb_section))
198
- section = 1;
199
- else
200
- section = NUM2UINT(rb_section);
201
-
202
- if (NIL_P(rb_old_value)) {
203
- old_value = NULL;
204
- } else {
205
- GRN_BULK_REWIND(old_value);
206
- RVAL2GRNBULK(rb_old_value, context, old_value);
207
- }
208
-
209
- if (NIL_P(rb_new_value)) {
210
- new_value = NULL;
211
- } else {
212
- GRN_BULK_REWIND(new_value);
213
- RVAL2GRNBULK(rb_new_value, context, new_value);
214
- }
215
-
216
- rc = grn_column_index_update(context, column,
217
- id, section, old_value, new_value);
218
- rb_grn_context_check(context, self);
219
- rb_grn_rc_check(rc, self);
220
-
221
- return original_rb_value;
222
- }
223
-
224
105
  /*
225
106
  * Adds a record that has @value@ content to inverted index for fast
226
107
  * fulltext serach. Normally, this method is not used
@@ -304,7 +185,7 @@ rb_grn_index_column_add (int argc, VALUE *argv, VALUE self)
304
185
 
305
186
  rb_grn_index_column_deconstruct(SELF(self), &column, &context,
306
187
  NULL, NULL,
307
- &new_value, NULL,
188
+ &new_value, NULL, NULL,
308
189
  NULL, &range,
309
190
  NULL, NULL);
310
191
 
@@ -418,7 +299,7 @@ rb_grn_index_column_delete (int argc, VALUE *argv, VALUE self)
418
299
 
419
300
  rb_grn_index_column_deconstruct(SELF(self), &column, &context,
420
301
  NULL, NULL,
421
- NULL, &old_value,
302
+ NULL, &old_value, NULL,
422
303
  NULL, &range,
423
304
  NULL, NULL);
424
305
 
@@ -526,7 +407,7 @@ rb_grn_index_column_update (int argc, VALUE *argv, VALUE self)
526
407
 
527
408
  rb_grn_index_column_deconstruct(SELF(self), &column, &context,
528
409
  NULL, NULL,
529
- &new_value, &old_value,
410
+ &new_value, &old_value, NULL,
530
411
  NULL, &range,
531
412
  NULL, NULL);
532
413
 
@@ -583,7 +464,7 @@ rb_grn_index_column_get_sources (VALUE self)
583
464
 
584
465
  rb_grn_index_column_deconstruct(SELF(self), &column, &context,
585
466
  NULL, NULL,
586
- NULL, NULL, NULL, NULL,
467
+ NULL, NULL, NULL, NULL, NULL,
587
468
  NULL, NULL);
588
469
 
589
470
  GRN_OBJ_INIT(&sources, GRN_BULK, 0, GRN_ID_NIL);
@@ -702,7 +583,7 @@ rb_grn_index_column_set_sources (VALUE self, VALUE rb_sources)
702
583
 
703
584
  rb_grn_index_column_deconstruct(SELF(self), &column, &context,
704
585
  NULL, NULL,
705
- NULL, NULL,
586
+ NULL, NULL, NULL,
706
587
  &range_id, NULL,
707
588
  NULL, NULL);
708
589
 
@@ -785,15 +666,16 @@ rb_grn_index_column_search (int argc, VALUE *argv, VALUE self)
785
666
  grn_obj *query = NULL, *id_query = NULL, *string_query = NULL;
786
667
  grn_obj *result;
787
668
  grn_operator operator;
669
+ grn_search_optarg options;
788
670
  grn_rc rc;
789
- VALUE rb_query, options, rb_result, rb_operator;
671
+ VALUE rb_query, rb_options, rb_result, rb_operator, rb_mode, rb_weight;
790
672
 
791
673
  rb_grn_index_column_deconstruct(SELF(self), &column, &context,
792
674
  NULL, NULL,
793
- NULL, NULL, NULL, &range,
675
+ NULL, NULL, NULL, NULL, &range,
794
676
  &id_query, &string_query);
795
677
 
796
- rb_scan_args(argc, argv, "11", &rb_query, &options);
678
+ rb_scan_args(argc, argv, "11", &rb_query, &rb_options);
797
679
 
798
680
  if (CBOOL2RVAL(rb_obj_is_kind_of(rb_query, rb_cInteger))) {
799
681
  grn_id id;
@@ -807,9 +689,11 @@ rb_grn_index_column_search (int argc, VALUE *argv, VALUE self)
807
689
  query = string_query;
808
690
  }
809
691
 
810
- rb_grn_scan_options(options,
692
+ rb_grn_scan_options(rb_options,
811
693
  "result", &rb_result,
812
694
  "operator", &rb_operator,
695
+ "mode", &rb_mode,
696
+ "weight", &rb_weight,
813
697
  NULL);
814
698
 
815
699
  if (NIL_P(rb_result)) {
@@ -824,7 +708,23 @@ rb_grn_index_column_search (int argc, VALUE *argv, VALUE self)
824
708
 
825
709
  operator = RVAL2GRNOPERATOR(rb_operator);
826
710
 
827
- rc = grn_obj_search(context, column, query, result, operator, NULL);
711
+ if (NIL_P(rb_mode)) {
712
+ options.mode = GRN_OP_EXACT;
713
+ } else {
714
+ options.mode = RVAL2GRNOPERATOR(rb_mode);
715
+ }
716
+ options.similarity_threshold = 0;
717
+ options.max_interval = 0;
718
+ options.weight_vector = NULL;
719
+ if (NIL_P(rb_weight)) {
720
+ options.vector_size = 1;
721
+ } else {
722
+ options.vector_size = NUM2UINT(rb_weight);
723
+ }
724
+ options.proc = NULL;
725
+ options.max_size = 0;
726
+
727
+ rc = grn_obj_search(context, column, query, result, operator, &options);
828
728
  rb_grn_rc_check(rc, self);
829
729
 
830
730
  return rb_result;
@@ -842,7 +742,7 @@ rb_grn_index_column_with_section_p (VALUE self)
842
742
 
843
743
  rb_grn_index_column_deconstruct(SELF(self), &column, NULL,
844
744
  NULL, NULL,
845
- NULL, NULL, NULL, NULL,
745
+ NULL, NULL, NULL, NULL, NULL,
846
746
  NULL, NULL);
847
747
 
848
748
  return CBOOL2RVAL(column->header.flags & GRN_OBJ_WITH_SECTION);
@@ -860,7 +760,7 @@ rb_grn_index_column_with_weight_p (VALUE self)
860
760
 
861
761
  rb_grn_index_column_deconstruct(SELF(self), &column, NULL,
862
762
  NULL, NULL,
863
- NULL, NULL, NULL, NULL,
763
+ NULL, NULL, NULL, NULL, NULL,
864
764
  NULL, NULL);
865
765
 
866
766
  return CBOOL2RVAL(column->header.flags & GRN_OBJ_WITH_WEIGHT);
@@ -878,7 +778,7 @@ rb_grn_index_column_with_position_p (VALUE self)
878
778
 
879
779
  rb_grn_index_column_deconstruct(SELF(self), &column, NULL,
880
780
  NULL, NULL,
881
- NULL, NULL, NULL, NULL,
781
+ NULL, NULL, NULL, NULL, NULL,
882
782
  NULL, NULL);
883
783
 
884
784
  return CBOOL2RVAL(column->header.flags & GRN_OBJ_WITH_POSITION);
@@ -906,24 +806,24 @@ rb_grn_index_column_with_position_p (VALUE self)
906
806
  static VALUE
907
807
  rb_grn_index_column_open_cursor (int argc, VALUE *argv, VALUE self)
908
808
  {
909
- grn_ctx *context;
910
- grn_obj *column;
911
- grn_obj *range_object;
809
+ grn_ctx *context;
810
+ grn_obj *column;
811
+ grn_obj *range_object;
912
812
  grn_table_cursor *table_cursor;
913
- grn_id rid_min = GRN_ID_NIL;
914
- grn_id rid_max = GRN_ID_MAX;
915
- int flags = 0;
916
- grn_obj *index_cursor;
917
- VALUE rb_table_cursor;
918
- VALUE options;
919
- VALUE rb_with_section, rb_with_weight, rb_with_position;
920
- VALUE rb_table;
921
- VALUE rb_lexicon;
922
- VALUE rb_cursor;
813
+ grn_id rid_min = GRN_ID_NIL;
814
+ grn_id rid_max = GRN_ID_MAX;
815
+ int flags = 0;
816
+ grn_obj *index_cursor;
817
+ VALUE rb_table_cursor;
818
+ VALUE options;
819
+ VALUE rb_with_section, rb_with_weight, rb_with_position;
820
+ VALUE rb_table;
821
+ VALUE rb_lexicon;
822
+ VALUE rb_cursor;
923
823
 
924
824
  rb_grn_index_column_deconstruct(SELF(self), &column, &context,
925
825
  NULL, NULL,
926
- NULL, NULL,
826
+ NULL, NULL, NULL,
927
827
  NULL, &range_object,
928
828
  NULL, NULL);
929
829
 
@@ -935,8 +835,8 @@ rb_grn_index_column_open_cursor (int argc, VALUE *argv, VALUE self)
935
835
  NULL);
936
836
 
937
837
  table_cursor = RVAL2GRNTABLECURSOR(rb_table_cursor, NULL);
938
- rb_table = GRNOBJECT2RVAL(Qnil, context, range_object, GRN_FALSE);
939
- rb_lexicon = rb_iv_get(rb_table_cursor, "@table");
838
+ rb_table = GRNOBJECT2RVAL(Qnil, context, range_object, GRN_FALSE);
839
+ rb_lexicon = rb_iv_get(rb_table_cursor, "@table");
940
840
 
941
841
  if (NIL_P(rb_with_section)) {
942
842
  flags |= column->header.flags & GRN_OBJ_WITH_SECTION;
@@ -973,9 +873,6 @@ rb_grn_init_index_column (VALUE mGrn)
973
873
  rb_cGrnIndexColumn =
974
874
  rb_define_class_under(mGrn, "IndexColumn", rb_cGrnColumn);
975
875
 
976
- rb_define_method(rb_cGrnIndexColumn, "[]=",
977
- rb_grn_index_column_array_set, 2);
978
-
979
876
  rb_define_method(rb_cGrnIndexColumn, "add",
980
877
  rb_grn_index_column_add, -1);
981
878
  rb_define_method(rb_cGrnIndexColumn, "delete",
@@ -999,6 +896,7 @@ rb_grn_init_index_column (VALUE mGrn)
999
896
  rb_grn_index_column_with_weight_p, 0);
1000
897
  rb_define_method(rb_cGrnIndexColumn, "with_position?",
1001
898
  rb_grn_index_column_with_position_p, 0);
899
+
1002
900
  rb_define_method(rb_cGrnIndexColumn, "open_cursor",
1003
901
  rb_grn_index_column_open_cursor, -1);
1004
902
  }