null+****@clear*****
null+****@clear*****
2011年 8月 14日 (日) 22:55:51 JST
Kouhei Sutou 2011-08-14 13:55:51 +0000 (Sun, 14 Aug 2011)
New Revision: d740b051e76b146684107d83cb5f1e1056be680c
Log:
[suggest][complete] support threshold in prefix search. refs #1042
Modified files:
plugins/suggest/suggest.c
test/unit/story/test-rurema.c
Modified: plugins/suggest/suggest.c (+8 -6)
===================================================================
--- plugins/suggest/suggest.c 2011-08-14 13:52:03 +0000 (1cf80a1)
+++ plugins/suggest/suggest.c 2011-08-14 13:55:51 +0000 (e63511a)
@@ -1,5 +1,5 @@
/* -*- c-basic-offset: 2 -*- */
-/* Copyright(C) 2010 Brazil
+/* Copyright(C) 2010-2011 Brazil
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -256,13 +256,15 @@ complete(grn_ctx *ctx, grn_obj *items, grn_obj *items_boost, grn_obj *col,
if (GRN_INT32_VALUE(&item_boost) >= 0) {
void *value;
int32_t score;
- grn_rset_recinfo *ri;
- grn_hash_add(ctx, (grn_hash *)res, &id, sizeof(grn_id),
- &value, NULL);
score = GRN_INT32_VALUE(&item_freq) +
GRN_INT32_VALUE(&item_boost);
- ri = value;
- ri->score += score;
+ if (score >= threshold) {
+ grn_rset_recinfo *ri;
+ grn_hash_add(ctx, (grn_hash *)res, &id, sizeof(grn_id),
+ &value, NULL);
+ ri = value;
+ ri->score += score;
+ }
}
}
grn_table_cursor_close(ctx, cur);
Modified: test/unit/story/test-rurema.c (+76 -0)
===================================================================
--- test/unit/story/test-rurema.c 2011-08-14 13:52:03 +0000 (59874ce)
+++ test/unit/story/test-rurema.c 2011-08-14 13:55:51 +0000 (6d74090)
@@ -26,6 +26,10 @@ void test_complete_prefix_rk_search(gconstpointer data);
void test_complete_prefix_rk_search_threshold_found(void);
void test_complete_prefix_rk_search_threshold_not_found(void);
void test_complete_cooccurrence(void);
+void data_complete_prefix_search(void);
+void test_complete_prefix_search(gconstpointer data);
+void test_complete_prefix_search_threshold_found(void);
+void test_complete_prefix_search_threshold_not_found(void);
void test_correct_cooccurrence(void);
void test_suggest_cooccurrence(void);
@@ -188,6 +192,78 @@ test_complete_coocurrence(void)
}
void
+test_complete_prefix_search_force(void)
+{
+ cut_assert_equal_string(
+ "{\"complete\":"
+ "[[1],"
+ "[[\"_key\",\"ShortText\"],"
+ "[\"_score\",\"Int32\"]],"
+ "[\"置換\",0]]}",
+ send_command(
+ "suggest "
+ "--table item_rurema "
+ "--column kana "
+ "--types complete "
+ "--prefix_search yes "
+ "--threshold 0 "
+ "--query '置'"));
+}
+
+void
+test_complete_prefix_search_disable(void)
+{
+ cut_assert_equal_string(
+ "{\"complete\":"
+ "[[0],"
+ "[[\"_key\",\"ShortText\"],"
+ "[\"_score\",\"Int32\"]]]}",
+ send_command(
+ "suggest "
+ "--table item_rurema "
+ "--column kana "
+ "--types complete "
+ "--prefix_search no "
+ "--threshold -1 "
+ "--query '置'"));
+}
+
+void
+test_complete_prefix_search_threshold_found(void)
+{
+ cut_assert_equal_string(
+ "{\"complete\":"
+ "[[1],"
+ "[[\"_key\",\"ShortText\"],"
+ "[\"_score\",\"Int32\"]],"
+ "[\"変数\",100]]}",
+ send_command(
+ "suggest "
+ "--table item_rurema "
+ "--column kana "
+ "--types complete "
+ "--threshold 100 "
+ "--query '変'"));
+}
+
+void
+test_complete_prefix_search_threshold_not_fuond(void)
+{
+ cut_assert_equal_string(
+ "{\"complete\":"
+ "[[0],"
+ "[[\"_key\",\"ShortText\"],"
+ "[\"_score\",\"Int32\"]]]}",
+ send_command(
+ "suggest "
+ "--table item_rurema "
+ "--column kana "
+ "--types complete "
+ "--threshold 101 "
+ "--query '変'"));
+}
+
+void
test_correct_coocurrence(void)
{
cut_assert_equal_string(