static VALUE rb_grn_double_array_trie_update_by_key (VALUE self, VALUE rb_current_key, VALUE rb_new_key) { grn_ctx *context; grn_obj *table; grn_id domain_id; grn_obj *current_key, *new_key, *domain; grn_rc rc; rb_grn_double_array_trie_deconstruct(SELF(self), &table, &context, ¤t_key, &new_key, &domain_id, &domain, NULL, NULL, NULL, NULL); RVAL2GRNKEY(rb_current_key, context, current_key, domain_id, domain, self); RVAL2GRNKEY(rb_new_key, context, new_key, domain_id, domain, self); rc = grn_table_update(context, table, GRN_BULK_HEAD(current_key), GRN_BULK_VSIZE(current_key), GRN_BULK_HEAD(new_key), GRN_BULK_VSIZE(new_key)); rb_grn_rc_check(rc, self); return Qnil; }
/* * call-seq: * patricia_trie.prefix_search(prefix) -> Groonga::Hash * * キーが_prefix_に前方一致するレコードのIDがキーに入っている * Groonga::Hashを返す。マッチするレコードがない場合は空の * Groonga::Hashが返る。 * */ static VALUE rb_grn_patricia_trie_prefix_search (VALUE self, VALUE rb_prefix) { grn_ctx *context; grn_obj *table, *key, *domain, *result; grn_id domain_id; VALUE rb_result; rb_grn_table_key_support_deconstruct(SELF(self), &table, &context, &key, &domain_id, &domain, NULL, NULL, NULL, NULL); result = grn_table_create(context, NULL, 0, NULL, GRN_OBJ_TABLE_HASH_KEY, table, 0); rb_grn_context_check(context, self); rb_result = GRNOBJECT2RVAL(Qnil, context, result, GRN_TRUE); GRN_BULK_REWIND(key); RVAL2GRNKEY(rb_prefix, context, key, domain_id, domain, self); grn_pat_prefix_search(context, (grn_pat *)table, GRN_BULK_HEAD(key), GRN_BULK_VSIZE(key), (grn_hash *)result); rb_grn_context_check(context, self); return rb_result; }
/* * _key_ にマッチするレコードのIDがキーに入っている * {Groonga::Hash} を返す。マッチするレコードがない場合は空の * {fGroonga::Hash} が返る。 * _options_ で +:result+ を指定することにより、そのテーブルにマッ * チしたレコードIDがキーのレコードを追加することができる。 * +:result+ にテーブルを指定した場合は、そのテーブルが返る。 * * @example 複数のキーで検索し、結果を1つのテーブルに集める。 * result = nil * keys = ["morita", "gunyara-kun", "yu"] * keys.each do |key| * result = users.search(key, :result => result) * end * result.each do |record| * user = record.key * p user.key # -> "morita"または"gunyara-kun"または"yu" * end * * @overload search(key, options=nil) * @return [Groonga::Hash] * @param key [String] レコードにマッチさせる値 * @param options [::Hash] The name and value * pairs. Omitted names are initialized as the default value. * @option options :result The result * 結果を格納するテーブル。 * @option options :operator (Groonga::Operator::OR) * マッチしたレコードをどのように扱うか。指定可能な値は以 * 下の通り。 * * - Groonga::Operator::OR := * マッチしたレコードを追加。すでにレコードが追加され * ている場合は何もしない。 =: * - Groonga::Operator::AND := * マッチしたレコードのスコアを増加。マッチしなかった * レコードを削除。 =: * - Groonga::Operator::AND_NOT := * マッチしたレコードを削除。 =: * - Groonga::Operator::ADJUST := * マッチしたレコードのスコアを増加。 =: * - +:type+ := * ????? =: * */ static VALUE rb_grn_double_array_trie_search (int argc, VALUE *argv, VALUE self) { grn_rc rc; grn_ctx *context; grn_obj *table; grn_id domain_id; grn_obj *key, *domain, *result; grn_operator operator; grn_search_optarg search_options; grn_bool search_options_is_set = GRN_FALSE; VALUE rb_key, options, rb_result, rb_operator, rb_type; rb_grn_double_array_trie_deconstruct(SELF(self), &table, &context, &key, NULL, &domain_id, &domain, NULL, NULL, NULL, NULL); rb_scan_args(argc, argv, "11", &rb_key, &options); RVAL2GRNKEY(rb_key, context, key, domain_id, domain, self); rb_grn_scan_options(options, "result", &rb_result, "operator", &rb_operator, "type", &rb_type, NULL); if (NIL_P(rb_result)) { result = grn_table_create(context, NULL, 0, NULL, GRN_OBJ_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC, table, 0); rb_grn_context_check(context, self); rb_result = GRNOBJECT2RVAL(Qnil, context, result, GRN_TRUE); } else { result = RVAL2GRNOBJECT(rb_result, &context); } operator = RVAL2GRNOPERATOR(rb_operator); rc = grn_obj_search(context, table, key, result, operator, search_options_is_set ? &search_options : NULL); rb_grn_rc_check(rc, self); return rb_result; }
/* * テーブルに主キーが _key_ のレコードがあるならtrueを返す。 * * @overload has_key?(key) */ static VALUE rb_grn_table_key_support_has_key (VALUE self, VALUE rb_key) { grn_ctx *context; grn_obj *table, *key, *domain; grn_id id, domain_id; rb_grn_table_key_support_deconstruct(SELF(self), &table, &context, &key, &domain_id, &domain, NULL, NULL, NULL, NULL); GRN_BULK_REWIND(key); RVAL2GRNKEY(rb_key, context, key, domain_id, domain, self); id = grn_table_get(context, table, GRN_BULK_HEAD(key), GRN_BULK_VSIZE(key)); return id == GRN_ID_NIL ? Qfalse : Qtrue; }
static grn_id rb_grn_table_key_support_add_raw (VALUE self, VALUE rb_key, int *added) { grn_ctx *context; grn_obj *table; grn_id id, domain_id; grn_obj *key, *domain; rb_grn_table_key_support_deconstruct(SELF(self), &table, &context, &key, &domain_id, &domain, NULL, NULL, NULL, NULL); GRN_BULK_REWIND(key); RVAL2GRNKEY(rb_key, context, key, domain_id, domain, self); id = grn_table_add(context, table, GRN_BULK_HEAD(key), GRN_BULK_VSIZE(key), added); rb_grn_context_check(context, self); return id; }
/* * _key_ にマッチするレコードのIDがキーに入っている * {Groonga::Hash} を返す。マッチするレコードがない場合は空の * {Groonga::Hash} が返る。 * * _options_ で +:result+ を指定することにより、そのテーブルにマッ * チしたレコードIDがキーのレコードを追加することができる。 * +:result+ にテーブルを指定した場合は、そのテーブルが返る。 * * @example 複数のキーで検索し、結果を1つのテーブルに集める。 * result = nil * keys = ["morita", "gunyara-kun", "yu"] * keys.each do |key| * result = users.search(key, :result => result) * end * result.each do |record| * user = record.key * p user.key # -> "morita"または"gunyara-kun"または"yu" * end * * @overload search(key, options=nil) * @param [::Hash] options The name and value * pairs. Omitted names are initialized as the default value * @option options :result * 結果を格納するテーブル。 * @return [Groonga::Hash] */ static VALUE rb_grn_hash_search (int argc, VALUE *argv, VALUE self) { grn_rc rc; grn_ctx *context; grn_obj *table; grn_id domain_id; grn_obj *key, *domain, *result; VALUE rb_key, options, rb_result; rb_grn_table_key_support_deconstruct(SELF(self), &table, &context, &key, &domain_id, &domain, NULL, NULL, NULL, NULL); rb_scan_args(argc, argv, "11", &rb_key, &options); RVAL2GRNKEY(rb_key, context, key, domain_id, domain, self); rb_grn_scan_options(options, "result", &rb_result, NULL); if (NIL_P(rb_result)) { result = grn_table_create(context, NULL, 0, NULL, GRN_OBJ_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC, table, 0); rb_grn_context_check(context, self); rb_result = GRNOBJECT2RVAL(Qnil, context, result, GRN_TRUE); } else { result = RVAL2GRNOBJECT(rb_result, &context); } rc = grn_obj_search(context, table, key, result, GRN_OP_OR, NULL); rb_grn_rc_check(rc, self); return rb_result; }
static VALUE rb_grn_table_key_support_delete_by_key (VALUE self, VALUE rb_key) { grn_ctx *context; grn_obj *table; grn_id domain_id; grn_obj *key, *domain; grn_rc rc; rb_grn_table_key_support_deconstruct(SELF(self), &table, &context, &key, &domain_id, &domain, NULL, NULL, NULL, NULL); GRN_BULK_REWIND(key); RVAL2GRNKEY(rb_key, context, key, domain_id, domain, self); rc = grn_table_delete(context, table, GRN_BULK_HEAD(key), GRN_BULK_VSIZE(key)); rb_grn_context_check(context, self); rb_grn_rc_check(rc, self); return Qnil; }