[Groonga-commit] groonga/groonga [master] [tool][suggest] use 2 as max size for similar search. fixes #1049

Back to archive index

null+****@clear***** null+****@clear*****
2011年 8月 16日 (火) 18:20:42 JST


Kouhei Sutou	2011-08-16 09:20:42 +0000 (Tue, 16 Aug 2011)

  New Revision: a227981884e75aec9a62385249de60cb459d8591

  Log:
    [tool][suggest] use 2 as max size for similar search. fixes #1049

  Modified files:
    plugins/suggest/suggest.c
    test/unit/story/test-rurema.c

  Modified: plugins/suggest/suggest.c (+10 -0)
===================================================================
--- plugins/suggest/suggest.c    2011-08-16 08:46:17 +0000 (2de3c74)
+++ plugins/suggest/suggest.c    2011-08-16 09:20:42 +0000 (c9946bc)
@@ -299,6 +299,7 @@ correct(grn_ctx *ctx, grn_obj *items, grn_obj *items_boost,
           memset(&optarg, 0, sizeof(grn_select_optarg));
           optarg.mode = GRN_OP_SIMILAR;
           optarg.similarity_threshold = 0;
+          optarg.max_size = 2;
           grn_ii_select(ctx, (grn_ii *)index, TEXT_VALUE_LEN(query),
                         (grn_hash *)res, GRN_OP_OR, &optarg);
           grn_obj_unlink(ctx, index);
@@ -358,9 +359,18 @@ correct(grn_ctx *ctx, grn_obj *items, grn_obj *items_boost,
               grn_expr_append_op(ctx, expr, GRN_OP_MINUS_ASSIGN, 2);
 
               if ((tc = grn_table_cursor_open(ctx, res, NULL, 0, NULL, 0, 0, -1, 0))) {
+                grn_obj score_value;
+                GRN_INT32_INIT(&score_value, 0);
                 while (!grn_table_cursor_next_o(ctx, tc, var)) {
                   grn_expr_exec(ctx, expr, 0);
+                  GRN_BULK_REWIND(&score_value);
+                  grn_obj_get_value(ctx, score, GRN_RECORD_VALUE(var),
+                                    &score_value);
+                  if (GRN_INT32_VALUE(&score_value) < threshold) {
+                    grn_table_cursor_delete(ctx, tc);
+                  }
                 }
+                grn_obj_unlink(ctx, &score_value);
                 grn_table_cursor_close(ctx, tc);
               }
               grn_obj_unlink(ctx, score);

  Modified: test/unit/story/test-rurema.c (+2 -2)
===================================================================
--- test/unit/story/test-rurema.c    2011-08-16 08:46:17 +0000 (84af3ec)
+++ test/unit/story/test-rurema.c    2011-08-16 09:20:42 +0000 (2b472fa)
@@ -290,14 +290,14 @@ test_correct_similar(void)
      "[[1],"
       "[[\"_key\",\"ShortText\"],"
        "[\"_score\",\"Int32\"]],"
-      "[\"file.join\",1048573]]}",
+      "[\"kernel.\",1]]}",
     send_command(
         "suggest "
         "--table item_rurema "
         "--column kana "
         "--types correct "
         "--threshold 1 "
-        "--query 'join'"));
+        "--query 'kernel'"));
 }
 
 void




Groonga-commit メーリングリストの案内
Back to archive index