null+****@clear*****
null+****@clear*****
2011年 8月 14日 (日) 22:37:23 JST
Kouhei Sutou 2011-08-14 13:37:23 +0000 (Sun, 14 Aug 2011)
New Revision: 2fe403822a23b4fcd19ced88701faa715d5c6e78
Log:
[suggest] support threshold in suggest's prefix RK search. refs #1042
Modified files:
plugins/suggest/suggest.c
test/unit/story/test-rurema.c
Modified: plugins/suggest/suggest.c (+6 -4)
===================================================================
--- plugins/suggest/suggest.c 2011-08-14 13:33:16 +0000 (fa7cb22)
+++ plugins/suggest/suggest.c 2011-08-14 13:37:23 +0000 (d2887a0)
@@ -220,10 +220,12 @@ complete(grn_ctx *ctx, grn_obj *items, grn_obj *items_boost, grn_obj *col,
grn_rset_recinfo *ri;
score = GRN_INT32_VALUE(&item_freq) +
GRN_INT32_VALUE(&item_boost);
- grn_hash_add(ctx, (grn_hash *)res,
- &p->rid, sizeof(grn_id), &value, NULL);
- ri = value;
- ri->score += score;
+ if (score >= threshold) {
+ grn_hash_add(ctx, (grn_hash *)res,
+ &p->rid, sizeof(grn_id), &value, NULL);
+ ri = value;
+ ri->score += score;
+ }
}
}
grn_ii_cursor_close(ctx, icur);
Modified: test/unit/story/test-rurema.c (+37 -0)
===================================================================
--- test/unit/story/test-rurema.c 2011-08-14 13:33:16 +0000 (9d2a035)
+++ test/unit/story/test-rurema.c 2011-08-14 13:37:23 +0000 (bdf614c)
@@ -23,6 +23,8 @@
void data_complete_prefix_rk_search(void);
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 test_correct_cooccurrence(void);
void test_suggest_cooccurrence(void);
@@ -133,6 +135,41 @@ test_complete_prefix_rk_search(gconstpointer data)
}
void
+test_complete_prefix_rk_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 'hen'"));
+}
+
+void
+test_complete_prefix_rk_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 'hen'"));
+}
+
+void
test_complete_coocurrence(void)
{
cut_assert_equal_string(