null+****@clear*****
null+****@clear*****
2011年 9月 14日 (水) 19:22:01 JST
Kouhei Sutou 2011-09-14 10:22:01 +0000 (Wed, 14 Sep 2011)
New Revision: ff554a5b4c3f2ea2ff13a8d3142f8f0cfdc0df47
Log:
query_expand -> query_expansion.
Modified files:
doc/source/commands/select.txt
doc/source/example/tutorialqe-3.log
doc/source/tutorial/tutorialqe.txt
lib/proc.c
test/unit/core/test-command-select-query-expansion.c
Modified: doc/source/commands/select.txt (+2 -2)
===================================================================
--- doc/source/commands/select.txt 2011-09-13 08:59:51 +0000 (621c50c)
+++ doc/source/commands/select.txt 2011-09-14 10:22:01 +0000 (11126d6)
@@ -17,7 +17,7 @@ select - テーブルの中から条件にマッチするレコードを検索
select table [match_columns [query [filter [scorer [sortby [output_columns
[offset [limit [drilldown [drilldown_sortby [drilldown_output_columns
[drilldown_offset [drilldown_limit [cache
- [match_escalation_threshold [query_expand]]]]]]]]]]]]]]]]
+ [match_escalation_threshold [query_expansion]]]]]]]]]]]]]]]]
説明
----
@@ -177,7 +177,7 @@ a - b
クエリのヒット件数が閾値を越えない場合は :doc:`/spec/search` で説明している方法で検索方法をエスカレーションしてきます。
-``query_expand``
+``query_expansion``
queryパラメータに指定された文字列を、置換(拡張)する条件を与えるテーブルとそのカラムを、「テーブル名.カラム名」という形式で設定します。指定するテーブルは文字列を主キーとするハッシュ型あるいはパトリシア木型のテーブルで、一つ以上の文字列型のカラムが定義されている必要があります。(ここでは置換テーブルと呼びます)。queryパラメータに指定された文字列が、指定されたテーブルの主キーと完全一致する場合、その文字列を指定されたカラム値の文字列に置換します。queryパラメータが、空白、括弧、演算子などを含む場合は、その演算子によって区切られた文字列の単位で置換が実行されます。ダブルクォート("")で括られた範囲は、その内部に空白を含んでいても一つの置換される単位と見なされます。検索
文字列と置換テーブルの主キー値との比較に際して大文字小文字等を区別したくない場合には、置換テーブルを定義する際にKEY_NORMALIZEを指定します。置換後の文字列となるカラムの値には、括弧や*, ORなど、queryパラメータで利用可能な全ての演算子を指定することができます。
Modified: doc/source/example/tutorialqe-3.log (+2 -2)
===================================================================
--- doc/source/example/tutorialqe-3.log 2011-09-13 08:59:51 +0000 (8f12757)
+++ doc/source/example/tutorialqe-3.log 2011-09-14 10:22:01 +0000 (cade93b)
@@ -1,6 +1,6 @@
実行例 ::
- > select Doc --match_columns body --query "シークァーサー" --query_expand Synonym.body
- > select Doc --match_columns body --query "シークヮーサー" --query_expand Synonym.body
+ > select Doc --match_columns body --query "シークァーサー" --query_expansion Synonym.body
+ > select Doc --match_columns body --query "シークヮーサー" --query_expansion Synonym.body
[[0,1315903097.36968,0.007449833],[[[2],[["_id","UInt32"],["_key","ShortText"],["body","ShortText"]],[1,"001","すっぱいブドウと甘いシークァーサー"],[2,"002","シークヮーサージュースとゴーヤチャンプル"]]]]
[[0,1315903109.46887,0.001223129],[[[2],[["_id","UInt32"],["_key","ShortText"],["body","ShortText"]],[1,"001","すっぱいブドウと甘いシークァーサー"],[2,"002","シークヮーサージュースとゴーヤチャンプル"]]]]
Modified: doc/source/tutorial/tutorialqe.txt (+8 -8)
===================================================================
--- doc/source/tutorial/tutorialqe.txt 2011-09-13 08:59:51 +0000 (5ba2705)
+++ doc/source/tutorial/tutorialqe.txt 2011-09-14 10:22:01 +0000 (4a49c0f)
@@ -2,17 +2,17 @@
.. highlightlang:: none
-selectコマンドのquery_expandパラメータの使い方
-==============================================
+selectコマンドのquery_expansionパラメータの使い方
+================================================
-groongaでは、selectコマンドにquery_expandパラメータを指定することによって、ユーザが指定した検索文字列を適宜拡張することが可能です。
+groongaでは、selectコマンドにquery_expansionパラメータを指定することによって、ユーザが指定した検索文字列を適宜拡張することが可能です。
たとえば、ユーザが'シークヮーサー'という文字列で検索した場合に、'シークヮーサー OR シークァーサー'で検索した場合と同一の結果を返すことによって、本来ユーザが必要とする結果をよりもれなく検索できるようになります。
準備
----
-query_expand機能を使用するためには、検索対象となる文書を格納するテーブル(ここでは文書テーブルと呼びます)以外に、ユーザの指定した検索文字列を置換するためのテーブル(ここでは置換テーブルと呼びます)を準備します。置換テーブルでは、その主キーが置換前の文字列となり、文字列型(ShortText等)のカラムの値が置換後の文字列となります。
+query_expansion機能を使用するためには、検索対象となる文書を格納するテーブル(ここでは文書テーブルと呼びます)以外に、ユーザの指定した検索文字列を置換するためのテーブル(ここでは置換テーブルと呼びます)を準備します。置換テーブルでは、その主キーが置換前の文字列となり、文字列型(ShortText等)のカラムの値が置換後の文字列となります。
実際に文書テーブルと置換テーブルを作成してみましょう。
@@ -40,18 +40,18 @@ query_expand機能を使用するためには、検索対象となる文書を
検索
----
-それでは実際に、準備した置換テーブルを使ってみましょう。まずは、query_expandパラメータを指定せずにselectコマンドを使って検索してみます。
+それでは実際に、準備した置換テーブルを使ってみましょう。まずは、query_expansionパラメータを指定せずにselectコマンドを使って検索してみます。
.. groonga-command
.. include:: ../example/tutorialqe-2.log
.. select Doc --match_columns body --query "シークァーサー"
.. select Doc --match_columns body --query "シークヮーサー"
-指定された文字列に完全に一致するレコードのみがそれぞれヒットします。次に、query_expandパラメータに、準備したSynonymテーブルのbodyカラムを指定してみましょう。
+指定された文字列に完全に一致するレコードのみがそれぞれヒットします。次に、query_expansionパラメータに、準備したSynonymテーブルのbodyカラムを指定してみましょう。
.. groonga-command
.. include:: ../example/tutorialqe-3.log
-.. select Doc --match_columns body --query "シークァーサー" --query_expand Synonym.body
-.. select Doc --match_columns body --query "シークヮーサー" --query_expand Synonym.body
+.. select Doc --match_columns body --query "シークァーサー" --query_expansion Synonym.body
+.. select Doc --match_columns body --query "シークヮーサー" --query_expansion Synonym.body
どちらのクエリ文字列も、"(シークァーサー OR シークヮーサー)"という文字列に置換されてから検索されるため、表記の揺れを吸収して検索できるようになりました。
Modified: lib/proc.c (+23 -23)
===================================================================
--- lib/proc.c 2011-09-13 08:59:51 +0000 (38ad378)
+++ lib/proc.c 2011-09-14 10:22:01 +0000 (1ae57ec)
@@ -187,7 +187,7 @@ grn_select(grn_ctx *ctx, const char *table, unsigned table_len,
int drilldown_offset, int drilldown_limit,
const char *cache, unsigned cache_len,
const char *match_escalation_threshold, unsigned match_escalation_threshold_len,
- const char *query_expand, unsigned query_expand_len)
+ const char *query_expansion, unsigned query_expansion_len)
{
uint32_t nkeys, nhits;
uint16_t cacheable = 1, taintable = 0;
@@ -200,7 +200,7 @@ grn_select(grn_ctx *ctx, const char *table, unsigned table_len,
uint32_t cache_key_size = table_len + 1 + match_columns_len + 1 + query_len + 1 +
filter_len + 1 + scorer_len + 1 + sortby_len + 1 + output_columns_len + 1 +
drilldown_len + 1 + drilldown_sortby_len + 1 + drilldown_output_columns_len +
- match_escalation_threshold_len + 1 + query_expand_len + 1 +
+ match_escalation_threshold_len + 1 + query_expansion_len + 1 +
sizeof(grn_content_type) + sizeof(int) * 4;
long long int threshold, original_threshold;
if (cache_key_size <= GRN_TABLE_MAX_KEY_SIZE) {
@@ -228,8 +228,8 @@ grn_select(grn_ctx *ctx, const char *table, unsigned table_len,
cp += drilldown_output_columns_len; *cp++ = '\0';
memcpy(cp, match_escalation_threshold, match_escalation_threshold_len);
cp += match_escalation_threshold_len; *cp++ = '\0';
- memcpy(cp, query_expand, query_expand_len);
- cp += query_expand_len; *cp++ = '\0';
+ memcpy(cp, query_expansion, query_expansion_len);
+ cp += query_expansion_len; *cp++ = '\0';
memcpy(cp, &output_type, sizeof(grn_content_type)); cp += sizeof(grn_content_type);
memcpy(cp, &offset, sizeof(int)); cp += sizeof(int);
memcpy(cp, &limit, sizeof(int)); cp += sizeof(int);
@@ -269,35 +269,35 @@ grn_select(grn_ctx *ctx, const char *table, unsigned table_len,
}
if (query_len) {
grn_expr_flags flags;
- grn_obj query_expand_buf;
- GRN_TEXT_INIT(&query_expand_buf, 0);
+ grn_obj query_expansion_buf;
+ GRN_TEXT_INIT(&query_expansion_buf, 0);
flags = GRN_EXPR_SYNTAX_QUERY|GRN_EXPR_ALLOW_PRAGMA|GRN_EXPR_ALLOW_COLUMN;
- if (query_expand_len) {
- grn_obj *query_expand_column;
- query_expand_column = grn_ctx_get(ctx, query_expand, query_expand_len);
- if (query_expand_column) {
- grn_obj *query_expand_table;
- query_expand_table = grn_column_table(ctx, query_expand_column);
- if (query_expand_table) {
- expand_query(ctx, query_expand_table, query_expand_column, flags,
- query, query_len, &query_expand_buf);
- query = GRN_TEXT_VALUE(&query_expand_buf);
- query_len = GRN_TEXT_LEN(&query_expand_buf);
- grn_obj_unlink(ctx, query_expand_table);
+ if (query_expansion_len) {
+ grn_obj *query_expansion_column;
+ query_expansion_column = grn_ctx_get(ctx, query_expansion, query_expansion_len);
+ if (query_expansion_column) {
+ grn_obj *query_expansion_table;
+ query_expansion_table = grn_column_table(ctx, query_expansion_column);
+ if (query_expansion_table) {
+ expand_query(ctx, query_expansion_table, query_expansion_column, flags,
+ query, query_len, &query_expansion_buf);
+ query = GRN_TEXT_VALUE(&query_expansion_buf);
+ query_len = GRN_TEXT_LEN(&query_expansion_buf);
+ grn_obj_unlink(ctx, query_expansion_table);
}
- grn_obj_unlink(ctx, query_expand_column);
+ grn_obj_unlink(ctx, query_expansion_column);
} else {
ERR(GRN_INVALID_ARGUMENT,
"nonexistent query expansion column: <%.*s>",
- query_expand_len, query_expand);
+ query_expansion_len, query_expansion);
grn_obj_unlink(ctx, cond);
- GRN_OBJ_FIN(ctx, &query_expand_buf);
+ GRN_OBJ_FIN(ctx, &query_expansion_buf);
goto exit;
}
}
grn_expr_parse(ctx, cond, query, query_len,
match_columns_, GRN_OP_MATCH, GRN_OP_AND, flags);
- GRN_OBJ_FIN(ctx, &query_expand_buf);
+ GRN_OBJ_FIN(ctx, &query_expansion_buf);
if (!ctx->rc && filter_len) {
grn_expr_parse(ctx, cond, filter, filter_len,
match_columns_, GRN_OP_MATCH, GRN_OP_AND,
@@ -2520,7 +2520,7 @@ grn_db_init_builtin_query(grn_ctx *ctx)
DEF_VAR(vars[14], "drilldown_limit");
DEF_VAR(vars[15], "cache");
DEF_VAR(vars[16], "match_escalation_threshold");
- DEF_VAR(vars[17], "query_expand");
+ DEF_VAR(vars[17], "query_expansion");
DEF_COMMAND("define_selector", proc_define_selector, 18, vars);
DEF_COMMAND("select", proc_select, 17, vars + 1);
Modified: test/unit/core/test-command-select-query-expansion.c (+18 -19)
===================================================================
--- test/unit/core/test-command-select-query-expansion.c 2011-09-13 08:59:51 +0000 (eb577e9)
+++ test/unit/core/test-command-select-query-expansion.c 2011-09-14 10:22:01 +0000 (4e66fef)
@@ -164,7 +164,7 @@ test_expand(void)
"[9,1316358000.0,\"Learning Ruby and groonga...\"]]]",
send_command("select Diaries --sortby _id "
"--match_columns content --query rroonga "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -179,7 +179,7 @@ test_expand_word_with_space(void)
"[6,1316098800.0,\"Setup groonga storage engine!\"]]]",
send_command("select Diaries --sortby _id "
"--match_columns content --query '\"groonga storage engine\"' "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -198,7 +198,7 @@ test_not_expand_recursively(void)
"[9,1316358000.0,\"Learning Ruby and groonga...\"]]]",
send_command("select Diaries --sortby _id "
"--match_columns content --query groonga "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -212,7 +212,7 @@ test_expand_OR_quoted(void)
"[10,1316444400.0,\"明日は日本語あるいは中国語を勉強します。\"]]]",
send_command("select Diaries --sortby _id "
"--match_columns content --query '\"OR\"' "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -227,7 +227,7 @@ test_expand_column_value(void)
"[9,1316358000.0,\"Learning Ruby and groonga...\"]]]",
send_command("select Diaries --sortby _id "
"--match_columns content --query 'content:@rroonga' "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -243,7 +243,7 @@ test_expand_column_value_with_space(void)
send_command("select Diaries --sortby _id "
"--match_columns content "
"--query 'content:@\"groonga storage engine\"' "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -257,7 +257,7 @@ test_expand_equal(void)
"[3,1315839600.0,\"Start rroonga!\"]]]",
send_command("select Diaries --sortby _id "
"--match_columns content --query 'content:=start-rroonga' "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -271,7 +271,7 @@ test_expand_prefix(void)
"[10,1316444400.0,\"明日は日本語あるいは中国語を勉強します。\"]]]",
send_command("select Diaries --sortby _id "
"--match_columns content --query 'Japan*' "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -289,7 +289,7 @@ test_not_expand_OR(void)
"[9,1316358000.0,\"Learning Ruby and groonga...\"]]]",
send_command("select Diaries --sortby _id "
"--match_columns content --query 'Ruby OR MySQL' "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -302,7 +302,7 @@ test_not_expand_OR_at_the_end(void)
"[\"content\",\"Text\"]]]]",
send_command("select Diaries --sortby _id "
"--match_columns content --query OR "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -315,7 +315,7 @@ test_not_expand_OR_with_leading_space(void)
"[\"content\",\"Text\"]]]]",
send_command("select Diaries --sortby _id "
"--match_columns content --query '\"OR \"' "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -329,7 +329,7 @@ test_not_expand_and(void)
"[9,1316358000.0,\"Learning Ruby and groonga...\"]]]",
send_command("select Diaries --sortby _id "
"--match_columns content --query 'Ruby + groonga' "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -343,7 +343,7 @@ test_not_expand_but(void)
"[9,1316358000.0,\"Learning Ruby and groonga...\"]]]",
send_command("select Diaries --sortby _id "
"--match_columns content --query 'Ruby - Start' "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -358,7 +358,7 @@ test_not_expand_paren(void)
"[9,1316358000.0,\"Learning Ruby and groonga...\"]]]",
send_command("select Diaries --sortby _id "
"--match_columns content --query '(Ruby)' "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -372,7 +372,7 @@ test_no_expand(void)
"[4,1315926000.0,\"Start Ruby!\"],"
"[9,1316358000.0,\"Learning Ruby and groonga...\"]]]",
send_command("select Diaries --match_columns content --query Ruby "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -386,7 +386,7 @@ test_no_expand_word_with_space(void)
"[9,1316358000.0,\"Learning Ruby and groonga...\"]]]",
send_command("select Diaries "
"--match_columns content --query '\"Ruby and groonga\"' "
- "--query_expand Synonyms.words"));
+ "--query_expansion Synonyms.words"));
}
void
@@ -397,7 +397,7 @@ test_nonexistent_expansion_column(void)
GRN_INVALID_ARGUMENT,
"nonexistent query expansion column: <Synonyms.nonexistent>",
"select Diaries --match_columns content --query groonga "
- "--query_expand Synonyms.nonexistent");
+ "--query_expansion Synonyms.nonexistent");
}
void
@@ -424,6 +424,5 @@ test_key_normalize(void)
send_command("select Diaries "
"--sortby _id "
"--match_columns content --query ruby "
- "--query_expand NormalizedSynonyms.words"));
+ "--query_expansion NormalizedSynonyms.words"));
}
-