[Groonga-commit] groonga/groonga at 2142db8 [master] grn_obj_search: support GRN_OP_FUZZY for grn_pat

Back to archive index

naoa null+****@clear*****
Tue Feb 2 14:22:04 JST 2016


naoa	2016-02-02 14:22:04 +0900 (Tue, 02 Feb 2016)

  New Revision: 2142db8b161f94050cc15a58e0775f2b2b0c35f9
  https://github.com/groonga/groonga/commit/2142db8b161f94050cc15a58e0775f2b2b0c35f9

  Merged e4e194e: Merge pull request #463 from naoa/op-fuzzy

  Message:
    grn_obj_search: support GRN_OP_FUZZY for grn_pat

  Modified files:
    include/groonga/groonga.h
    lib/db.c
    lib/grn_pat.h
    lib/pat.c

  Modified: include/groonga/groonga.h (+7 -1)
===================================================================
--- include/groonga/groonga.h    2016-02-02 14:15:56 +0900 (f55e8e3)
+++ include/groonga/groonga.h    2016-02-02 14:22:04 +0900 (b796130)
@@ -733,7 +733,8 @@ typedef enum {
   GRN_OP_TABLE_GROUP,
   GRN_OP_JSON_PUT,
   GRN_OP_GET_MEMBER,
-  GRN_OP_REGEXP
+  GRN_OP_REGEXP,
+  GRN_OP_FUZZY
 } grn_operator;
 
 GRN_API const char *grn_operator_to_string(grn_operator op);
@@ -932,6 +933,8 @@ GRN_API grn_obj *grn_obj_db(grn_ctx *ctx, grn_obj *obj);
 
 GRN_API grn_id grn_obj_id(grn_ctx *ctx, grn_obj *obj);
 
+#define GRN_TABLE_FUZZY_WITH_TRANSPOSITION                  (0x01)
+
 typedef struct _grn_search_optarg grn_search_optarg;
 
 struct _grn_search_optarg {
@@ -945,6 +948,9 @@ struct _grn_search_optarg {
   grn_obj *scorer;
   grn_obj *scorer_args_expr;
   unsigned int scorer_args_expr_offset;
+  unsigned int fuzzy_prefix_match_size;
+  unsigned int fuzzy_max_distance;
+  int fuzzy_flags;
 };
 
 GRN_API grn_rc grn_obj_search(grn_ctx *ctx, grn_obj *obj, grn_obj *query,

  Modified: lib/db.c (+11 -1)
===================================================================
--- lib/db.c    2016-02-02 14:15:56 +0900 (d0dae2f)
+++ lib/db.c    2016-02-02 14:22:04 +0900 (4c145be)
@@ -3449,6 +3449,9 @@ grn_obj_search(grn_ctx *ctx, grn_obj *obj, grn_obj *query,
               case GRN_OP_TERM_EXTRACT :
                 tag = "[table][term-extract]";
                 break;
+              case GRN_OP_FUZZY :
+                tag = "[table][fuzzy]";
+                break;
               default :
                 tag = "[table][unknown]";
                 break;
@@ -3458,7 +3461,14 @@ grn_obj_search(grn_ctx *ctx, grn_obj *obj, grn_obj *query,
             }
             grn_obj_search_index_report(ctx, tag, obj);
           }
-          rc = grn_table_search(ctx, obj, key, key_size, mode, res, op);
+          if (optarg && optarg->mode == GRN_OP_FUZZY) {
+            rc = grn_table_fuzzy_search(ctx, obj, key, key_size,
+                                        optarg->fuzzy_prefix_match_size,
+                                        optarg->fuzzy_max_distance,
+                                        optarg->fuzzy_flags, res);
+          } else {
+            rc = grn_table_search(ctx, obj, key, key_size, mode, res, op);
+          }
         }
       }
       break;

  Modified: lib/grn_pat.h (+0 -2)
===================================================================
--- lib/grn_pat.h    2016-02-02 14:15:56 +0900 (82b57be)
+++ lib/grn_pat.h    2016-02-02 14:22:04 +0900 (c228949)
@@ -107,8 +107,6 @@ void grn_pat_cursor_inspect(grn_ctx *ctx, grn_pat_cursor *c, grn_obj *buf);
 grn_rc grn_pat_cache_enable(grn_ctx *ctx, grn_pat *pat, uint32_t cache_size);
 void grn_pat_cache_disable(grn_ctx *ctx, grn_pat *pat);
 
-#define GRN_PAT_FUZZY_WITH_TRANSPOSITION                  (0x01)
-
 GRN_API grn_rc grn_pat_fuzzy_search(grn_ctx *ctx, grn_pat *pat,
                                     const void *key, unsigned int key_size,
                                     unsigned int prefix_match_size,

  Modified: lib/pat.c (+1 -1)
===================================================================
--- lib/pat.c    2016-02-02 14:15:56 +0900 (75a66ed)
+++ lib/pat.c    2016-02-02 14:22:04 +0900 (75e350d)
@@ -1261,7 +1261,7 @@ calc_edit_distance_by_offset(grn_ctx *ctx,
         b = DIST(x, y - 1) + 1;
         c = DIST(x - 1, y - 1) + 1;
         DIST(x, y) = ((a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c));
-        if (flags == GRN_PAT_FUZZY_WITH_TRANSPOSITION
+        if (flags == GRN_TABLE_FUZZY_WITH_TRANSPOSITION
             && x > 1 && y > 1
             && cx == cy
             && memcmp(px, py - cy, cx) == 0
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index