[Groonga-commit] groonga/groonga at eda9c5b [master] db: support operation for grn_table_fuzzy_search()

Back to archive index

naoa null+****@clear*****
Tue Feb 16 04:38:29 JST 2016


naoa	2016-02-16 04:38:29 +0900 (Tue, 16 Feb 2016)

  New Revision: eda9c5bb154f2a44172d7b4ea0d050d9235ca021
  https://github.com/groonga/groonga/commit/eda9c5bb154f2a44172d7b4ea0d050d9235ca021

  Merged 167aa02: Merge pull request #478 from naoa/table-fuzzy-support-op

  Message:
    db: support operation for grn_table_fuzzy_search()

  Added files:
    test/command/suite/select/function/fuzzy_search/pat/and.expected
    test/command/suite/select/function/fuzzy_search/pat/and.test
    test/command/suite/select/function/fuzzy_search/pat/or.expected
    test/command/suite/select/function/fuzzy_search/pat/or.test
  Modified files:
    lib/db.c
    lib/grn_db.h
    lib/ii.c

  Modified: lib/db.c (+11 -3)
===================================================================
--- lib/db.c    2016-02-14 15:40:24 +0900 (4d849ea)
+++ lib/db.c    2016-02-16 04:38:29 +0900 (aa0246c)
@@ -2915,7 +2915,7 @@ grn_table_search(grn_ctx *ctx, grn_obj *table, const void *key, uint32_t key_siz
 
 grn_rc
 grn_table_fuzzy_search(grn_ctx *ctx, grn_obj *table, const void *key, uint32_t key_size,
-                       grn_fuzzy_search_optarg *args, grn_obj *res)
+                       grn_fuzzy_search_optarg *args, grn_obj *res, grn_operator op)
 {
   grn_rc rc = GRN_SUCCESS;
   GRN_API_ENTER;
@@ -2923,10 +2923,18 @@ grn_table_fuzzy_search(grn_ctx *ctx, grn_obj *table, const void *key, uint32_t k
   case GRN_TABLE_PAT_KEY :
     {
       grn_pat *pat = (grn_pat *)table;
+      grn_obj *hash;
+      hash = grn_table_create(ctx, NULL, 0, NULL,
+                              GRN_OBJ_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC,
+                              table, NULL);
       WITH_NORMALIZE(pat, key, key_size, {
         rc = grn_pat_fuzzy_search(ctx, pat, key, key_size,
-                                  args, (grn_hash *)res);
+                                  args, (grn_hash *)hash);
       });
+      if (rc == GRN_SUCCESS) {
+        rc = grn_table_setoperation(ctx, res, hash, res, op);
+      }
+      grn_obj_unlink(ctx, hash);
     }
     break;
   default :
@@ -3462,7 +3470,7 @@ grn_obj_search(grn_ctx *ctx, grn_obj *obj, grn_obj *query,
           }
           if (optarg && optarg->mode == GRN_OP_FUZZY) {
             rc = grn_table_fuzzy_search(ctx, obj, key, key_size,
-                                        &(optarg->fuzzy), res);
+                                        &(optarg->fuzzy), res, op);
           } else {
             rc = grn_table_search(ctx, obj, key, key_size, mode, res, op);
           }

  Modified: lib/grn_db.h (+1 -1)
===================================================================
--- lib/grn_db.h    2016-02-14 15:40:24 +0900 (cd623d7)
+++ lib/grn_db.h    2016-02-16 04:38:29 +0900 (cc8e2cd)
@@ -85,7 +85,7 @@ grn_rc grn_table_search(grn_ctx *ctx, grn_obj *table,
 
 grn_rc grn_table_fuzzy_search(grn_ctx *ctx, grn_obj *table,
                               const void *key, uint32_t key_size,
-                              grn_fuzzy_search_optarg *args, grn_obj *res);
+                              grn_fuzzy_search_optarg *args, grn_obj *res, grn_operator op);
 
 grn_id grn_table_next(grn_ctx *ctx, grn_obj *table, grn_id id);
 

  Modified: lib/ii.c (+1 -1)
===================================================================
--- lib/ii.c    2016-02-14 15:40:24 +0900 (07a7c24)
+++ lib/ii.c    2016-02-16 04:38:29 +0900 (7f56d1b)
@@ -5612,7 +5612,7 @@ token_info_open(grn_ctx *ctx, grn_obj *lexicon, grn_ii *ii,
         GRN_OBJ_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC,
         grn_ctx_at(ctx, GRN_DB_UINT32), NULL))) {
       grn_table_fuzzy_search(ctx, lexicon, key, key_size,
-                             args, (grn_obj *)h);
+                             args, (grn_obj *)h, GRN_OP_OR);
       if (GRN_HASH_SIZE(h)) {
         if ((ti->cursors = cursor_heap_open(ctx, GRN_HASH_SIZE(h)))) {
           grn_rset_recinfo *ri;

  Added: test/command/suite/select/function/fuzzy_search/pat/and.expected (+11 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/fuzzy_search/pat/and.expected    2016-02-16 04:38:29 +0900 (5e92352)
@@ -0,0 +1,11 @@
+table_create Users TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+load --table Users
+[
+{"_key": "Tom"},
+{"_key": "Tomy"},
+{"_key": "Ken"}
+]
+[[0,0.0,0.0],3]
+select Users --filter '_key @^ "T" && fuzzy_search(_key, "To", 1)'   --output_columns '_key, _score'   --match_escalation_threshold -1
+[[0,0.0,0.0],[[[1],[["_key","ShortText"],["_score","Int32"]],["Tom",2]]]]

  Added: test/command/suite/select/function/fuzzy_search/pat/and.test (+12 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/fuzzy_search/pat/and.test    2016-02-16 04:38:29 +0900 (32e89c0)
@@ -0,0 +1,12 @@
+table_create Users TABLE_PAT_KEY ShortText
+
+load --table Users
+[
+{"_key": "Tom"},
+{"_key": "Tomy"},
+{"_key": "Ken"}
+]
+
+select Users --filter '_key @^ "T" && fuzzy_search(_key, "To", 1)' \
+  --output_columns '_key, _score' \
+  --match_escalation_threshold -1

  Added: test/command/suite/select/function/fuzzy_search/pat/or.expected (+46 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/fuzzy_search/pat/or.expected    2016-02-16 04:38:29 +0900 (11ff741)
@@ -0,0 +1,46 @@
+table_create Users TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+load --table Users
+[
+{"_key": "Tom"},
+{"_key": "Tomy"},
+{"_key": "Ken"}
+]
+[[0,0.0,0.0],3]
+select Users --filter '_key @^ "T" || fuzzy_search(_key, "Ke", 1)'   --output_columns '_key, _score'   --match_escalation_threshold -1
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "_score",
+          "Int32"
+        ]
+      ],
+      [
+        "Tomy",
+        1
+      ],
+      [
+        "Tom",
+        1
+      ],
+      [
+        "Ken",
+        1
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/function/fuzzy_search/pat/or.test (+12 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/fuzzy_search/pat/or.test    2016-02-16 04:38:29 +0900 (0be7e4f)
@@ -0,0 +1,12 @@
+table_create Users TABLE_PAT_KEY ShortText
+
+load --table Users
+[
+{"_key": "Tom"},
+{"_key": "Tomy"},
+{"_key": "Ken"}
+]
+
+select Users --filter '_key @^ "T" || fuzzy_search(_key, "Ke", 1)' \
+  --output_columns '_key, _score' \
+  --match_escalation_threshold -1
-------------- next part --------------
HTML����������������������������...
Download 



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