/* * 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; }
void test_prefix_search(gconstpointer data) { const grn_trie_test_data *test_data = data; const gchar key1[] = "セナ"; const gchar key2[] = "ナセナセ"; const gchar key3[] = "Groonga"; const gchar key4[] = "セナ + Ruby"; const gchar key5[] = "セナセナ"; trie_test_data_set_parameters(test_data); cut_assert_create_trie(); cut_assert_lookup_add(key1); cut_assert_lookup_add(key2); cut_assert_lookup_add(key3); cut_assert_lookup_add(key4); cut_assert_lookup_add(key5); cut_assert_create_hash(); grn_test_assert_equal_rc(test_data->expected_rc, grn_pat_prefix_search(context, trie, test_data->search_key, strlen(test_data->search_key), hash)); gcut_assert_equal_list_string(test_data->expected_strings, retrieve_all_keys()); }