[Groonga-commit] groonga/groonga [master] Added prefix search on suggest completion.

Back to archive index

null+****@clear***** null+****@clear*****
2010年 8月 26日 (木) 16:08:16 JST


Tasuku SUENAGA a.k.a. gunyarakun	2010-08-26 07:08:16 +0000 (Thu, 26 Aug 2010)

  New Revision: f305e6493adc94af2a893a75cd8e460cab60646d

  Log:
    Added prefix search on suggest completion.

  Modified files:
    modules/suggest/suggest.c

  Modified: modules/suggest/suggest.c (+11 -1)
===================================================================
--- modules/suggest/suggest.c    2010-08-26 06:34:30 +0000 (994af46)
+++ modules/suggest/suggest.c    2010-08-26 07:08:16 +0000 (56dc239)
@@ -42,7 +42,7 @@ command_suggest(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_dat
           if ((norm = grn_str_open(ctx, GRN_TEXT_VALUE(VAR(2)), GRN_TEXT_LEN(VAR(2)),
                                    GRN_STR_NORMALIZE))) {
 #if 1
-            /* RK search */
+            /* RK search + prefix search */
             grn_obj *index;
             /* FIXME: support index selection */
             if (grn_column_index(ctx, col, GRN_OP_PREFIX,
@@ -71,6 +71,16 @@ command_suggest(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_dat
                 ERR(GRN_UNKNOWN_ERROR, "cannot open cursor for pk.");
                 goto exit;
               }
+
+              if ((cur = grn_table_cursor_open(ctx, table,
+                                               GRN_TEXT_VALUE(VAR(2)), GRN_TEXT_LEN(VAR(2)),
+                                               NULL, 0, 0, -1, GRN_CURSOR_PREFIX))) {
+                grn_id id;
+                while ((id = grn_table_cursor_next(ctx, cur))) {
+                  grn_hash_add(ctx, (grn_hash *)res, &id, sizeof(grn_id), NULL, NULL);
+                }
+                grn_table_cursor_close(ctx, cur);
+              }
             } else {
               ERR(GRN_UNKNOWN_ERROR, "cannot find index for prefix search.");
               goto exit;




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