null+****@clear*****
null+****@clear*****
2011年 1月 25日 (火) 15:26:30 JST
Kouhei Sutou 2011-01-25 06:26:30 +0000 (Tue, 25 Jan 2011)
New Revision: 970667ed6b844014e13d4ad1c82c7802095896f8
Log:
implement "keyword*" syntax prefix search. #837.
Modified files:
lib/expr.c
test/unit/core/test-command-select-query.c
Modified: lib/expr.c (+2 -2)
===================================================================
--- lib/expr.c 2011-02-07 06:29:01 +0000 (d8ed4b7)
+++ lib/expr.c 2011-01-25 06:26:30 +0000 (569818a)
@@ -4775,7 +4775,6 @@ grn_expr_parser_open(grn_ctx *ctx)
static grn_rc
get_word_(grn_ctx *ctx, efs_info *q)
{
- grn_operator mode;
const char *start = q->cur, *end;
unsigned int len;
for (end = q->cur;; ) {
@@ -4790,6 +4789,7 @@ get_word_(grn_ctx *ctx, efs_info *q)
break;
}
if (q->flags & GRN_EXPR_ALLOW_COLUMN && *end == GRN_QUERY_COLUMN) {
+ grn_operator mode;
grn_obj *c = grn_obj_column(ctx, q->table, start, end - start);
if (c && end + 1 < q->str_end) {
// efs_op op;
@@ -4856,8 +4856,8 @@ get_word_(grn_ctx *ctx, efs_info *q)
return GRN_SUCCESS;
} else if (*end == GRN_QUERY_PREFIX) {
- mode = GRN_OP_PREFIX;
q->cur = end + 1;
+ GRN_INT32_PUT(ctx, &q->mode_stack, GRN_OP_PREFIX);
break;
}
end += len;
Modified: test/unit/core/test-command-select-query.c (+20 -1)
===================================================================
--- test/unit/core/test-command-select-query.c 2011-02-07 06:29:01 +0000 (e8b7590)
+++ test/unit/core/test-command-select-query.c 2011-01-25 06:26:30 +0000 (d12240d)
@@ -1,6 +1,6 @@
/* -*- c-basic-offset: 2; coding: utf-8 -*- */
/*
- Copyright(C) 2010 Kouhei Sutou <kou****@clear*****>
+ Copyright(C) 2010-2011 Kouhei Sutou <kou****@clear*****>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -26,6 +26,7 @@
void test_int64_compare_over_int32(void);
void test_int64_compare_float_literal(void);
void test_int32_key_table_reference_compare(void);
+void test_prefix_search(void);
static gchar *tmp_directory;
@@ -128,3 +129,21 @@ test_int32_key_table_reference_compare(void)
send_command("select Users --query id:<30"));
}
+void
+test_prefix_search(void)
+{
+ assert_send_command("table_create Users TABLE_PAT_KEY ShortText");
+ assert_send_command("load --table Users\n"
+ "[\n"
+ "{\"_key\":\"mori\"},\n"
+ "{\"_key\":\"morita\"},\n"
+ "{\"_key\":\"mona\"}\n"
+ "]");
+ cut_assert_equal_string(
+ "[[[2],"
+ "[[\"_id\",\"UInt32\"],[\"_key\",\"ShortText\"]],"
+ "[2,\"morita\"],"
+ "[1,\"mori\"]]]",
+ send_command("select Users --match_columns _key --query mor*"));
+}
+