[Groonga-commit] groonga/groonga at f7939a4 [master] proc_fuzzy_search: use same result table for sequential_search

Back to archive index

naoa null+****@clear*****
Sat Feb 6 12:21:49 JST 2016


naoa	2016-02-06 12:21:49 +0900 (Sat, 06 Feb 2016)

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

  Merged 872834a: Merge pull request #469 from naoa/proc-fuzzy-use-same-res

  Message:
    proc_fuzzy_search: use same result table for sequential_search

  Added files:
    test/command/suite/select/function/fuzzy_search/index/and.test
    test/command/suite/select/function/fuzzy_search/index/or.test
  Copied files:
    test/command/suite/select/function/fuzzy_search/index/and.expected
      (from test/command/suite/select/function/fuzzy_search/sequential/max_expansion.expected)
    test/command/suite/select/function/fuzzy_search/index/or.expected
      (from test/command/suite/select/function/fuzzy_search/index/hash.expected)
  Modified files:
    lib/proc/proc_fuzzy_search.c
    test/command/suite/select/function/fuzzy_search/index/hash.expected
    test/command/suite/select/function/fuzzy_search/sequential/max_distance.expected
    test/command/suite/select/function/fuzzy_search/sequential/max_expansion.expected
    test/command/suite/select/function/fuzzy_search/sequential/prefix_length.expected
    test/command/suite/select/function/fuzzy_search/sequential/prefix_length_ja.expected
    test/command/suite/select/function/fuzzy_search/sequential/reference.expected
    test/command/suite/select/function/fuzzy_search/sequential/reference_vector.expected
    test/command/suite/select/function/fuzzy_search/sequential/text.expected
    test/command/suite/select/function/fuzzy_search/sequential/vector.expected

  Modified: lib/proc/proc_fuzzy_search.c (+19 -30)
===================================================================
--- lib/proc/proc_fuzzy_search.c    2016-02-05 22:41:43 +0900 (5397592)
+++ lib/proc/proc_fuzzy_search.c    2016-02-06 12:21:49 +0900 (be15bc1)
@@ -18,6 +18,7 @@
 
 #include "../grn_proc.h"
 #include "../grn_rset.h"
+#include "../grn_ii.h"
 
 #include <groonga/plugin.h>
 
@@ -161,13 +162,18 @@ score_heap_close(grn_ctx *ctx, score_heap *h)
 static grn_rc
 sequential_fuzzy_search(grn_ctx *ctx, grn_obj *table, grn_obj *column, grn_obj *query,
                         uint32_t max_distance, uint32_t prefix_match_size,
-                        uint32_t max_expansion, int flags, grn_obj *hash)
+                        uint32_t max_expansion, int flags, grn_obj *res, grn_operator op)
 {
   grn_table_cursor *tc;
   char *sx = GRN_TEXT_VALUE(query);
   char *ex = GRN_BULK_CURR(query);
 
-  if ((tc = grn_table_cursor_open(ctx, table, NULL, 0, NULL, 0, 0, -1, GRN_CURSOR_BY_ID))) {
+  if (op == GRN_OP_AND) {
+    tc = grn_table_cursor_open(ctx, res, NULL, 0, NULL, 0, 0, -1, GRN_CURSOR_BY_ID);
+  } else {
+    tc = grn_table_cursor_open(ctx, table, NULL, 0, NULL, 0, 0, -1, GRN_CURSOR_BY_ID);
+  }
+  if (tc) {
     grn_id id;
     grn_obj value;
     score_heap *heap;
@@ -263,12 +269,16 @@ sequential_fuzzy_search(grn_ctx *ctx, grn_obj *table, grn_obj *column, grn_obj *
       if (max_expansion > 0 && i >= max_expansion) {
         break;
       }
-      /* TODO: use grn_ii_posting_add() */
-      grn_rset_recinfo *ri;
-      if (grn_hash_add(ctx, (grn_hash *)hash, &(heap->nodes[i].id), sizeof(grn_id), (void **)&ri, NULL)) {
-        ri->score = heap->nodes[i].score;
+      {
+        grn_posting posting;
+        posting.rid = heap->nodes[i].id;
+        posting.sid = 1;
+        posting.pos = 0;
+        posting.weight = max_distance - heap->nodes[i].score;
+        grn_ii_posting_add(ctx, &posting, (grn_hash *)res, op);
       }
     }
+    grn_ii_resolve_sel_and(ctx, (grn_hash *)res, op);
     score_heap_close(ctx, heap);
   }
 
@@ -357,30 +367,9 @@ selector_fuzzy_search(grn_ctx *ctx, grn_obj *table, grn_obj *index,
   }
 
   if (use_sequential_search) {
-    grn_obj *hash;
-    hash = grn_table_create(ctx, NULL, 0, NULL,
-                            GRN_OBJ_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC,
-                            table, NULL);
-    if (!hash) {
-      return GRN_NO_MEMORY_AVAILABLE;
-    }
-
-    /* TODO: use grn_ii_posting_add() in sequential_fuzzy_search() and
-       grn_ii_resolve_sel_and(). */
-    if (op == GRN_OP_AND) {
-      rc = sequential_fuzzy_search(ctx, res, obj, query,
-                                   max_distance, prefix_match_size,
-                                   max_expansion, flags, hash);
-    } else {
-      rc = sequential_fuzzy_search(ctx, table, obj, query,
-                                   max_distance, prefix_match_size,
-                                   max_expansion, flags, hash);
-    }
-
-    if (rc == GRN_SUCCESS) {
-      rc = grn_table_setoperation(ctx, res, hash, res, op);
-    }
-    grn_obj_unlink(ctx, hash);
+    rc = sequential_fuzzy_search(ctx, table, obj, query,
+                                 max_distance, prefix_match_size,
+                                 max_expansion, flags, res, op);
     goto exit;
   }
 

  Copied: test/command/suite/select/function/fuzzy_search/index/and.expected (+6 -2) 50%
===================================================================
--- test/command/suite/select/function/fuzzy_search/sequential/max_expansion.expected    2016-02-05 22:41:43 +0900 (d90c752)
+++ test/command/suite/select/function/fuzzy_search/index/and.expected    2016-02-06 12:21:49 +0900 (7aadd7f)
@@ -2,6 +2,10 @@ table_create Users TABLE_NO_KEY
 [[0,0.0,0.0],true]
 column_create Users name COLUMN_SCALAR ShortText
 [[0,0.0,0.0],true]
+table_create Tags TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Tags tag COLUMN_INDEX Users name
+[[0,0.0,0.0],true]
 load --table Users
 [
 {"name": "Tom"},
@@ -9,5 +13,5 @@ load --table Users
 {"name": "Ken"}
 ]
 [[0,0.0,0.0],3]
-select Users --filter 'fuzzy_search(name, "To", 2, 0, 1)'   --output_columns 'name, _score'   --match_escalation_threshold -1
-[[0,0.0,0.0],[[[1],[["name","ShortText"],["_score","Int32"]],["Tom",1]]]]
+select Users --filter 'name @^ "T" && fuzzy_search(name, "To", 1)'   --output_columns 'name, _score'   --match_escalation_threshold -1
+[[0,0.0,0.0],[[[1],[["name","ShortText"],["_score","Int32"]],["Tom",2]]]]

  Added: test/command/suite/select/function/fuzzy_search/index/and.test (+16 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/fuzzy_search/index/and.test    2016-02-06 12:21:49 +0900 (5c7d5a0)
@@ -0,0 +1,16 @@
+table_create Users TABLE_NO_KEY
+column_create Users name COLUMN_SCALAR ShortText
+
+table_create Tags TABLE_PAT_KEY ShortText
+column_create Tags tag COLUMN_INDEX Users name
+
+load --table Users
+[
+{"name": "Tom"},
+{"name": "Tomy"},
+{"name": "Ken"}
+]
+
+select Users --filter 'name @^ "T" && fuzzy_search(name, "To", 1)' \
+  --output_columns 'name, _score' \
+  --match_escalation_threshold -1

  Modified: test/command/suite/select/function/fuzzy_search/index/hash.expected (+1 -1)
===================================================================
--- test/command/suite/select/function/fuzzy_search/index/hash.expected    2016-02-05 22:41:43 +0900 (76346a2)
+++ test/command/suite/select/function/fuzzy_search/index/hash.expected    2016-02-06 12:21:49 +0900 (ec46aff)
@@ -37,7 +37,7 @@ select Users --filter 'fuzzy_search(name, "Tom", 1)'   --output_columns 'name, _
       ],
       [
         "Tom",
-        0
+        2
       ],
       [
         "Tomy",

  Copied: test/command/suite/select/function/fuzzy_search/index/or.expected (+9 -5) 70%
===================================================================
--- test/command/suite/select/function/fuzzy_search/index/hash.expected    2016-02-05 22:41:43 +0900 (76346a2)
+++ test/command/suite/select/function/fuzzy_search/index/or.expected    2016-02-06 12:21:49 +0900 (929f6eb)
@@ -2,7 +2,7 @@ table_create Users TABLE_NO_KEY
 [[0,0.0,0.0],true]
 column_create Users name COLUMN_SCALAR ShortText
 [[0,0.0,0.0],true]
-table_create Tags TABLE_HASH_KEY ShortText
+table_create Tags TABLE_PAT_KEY ShortText
 [[0,0.0,0.0],true]
 column_create Tags tag COLUMN_INDEX Users name
 [[0,0.0,0.0],true]
@@ -13,7 +13,7 @@ load --table Users
 {"name": "Ken"}
 ]
 [[0,0.0,0.0],3]
-select Users --filter 'fuzzy_search(name, "Tom", 1)'   --output_columns 'name, _score'   --match_escalation_threshold -1
+select Users --filter 'name @^ "T" || fuzzy_search(name, "Ke", 1)'   --output_columns 'name, _score'   --match_escalation_threshold -1
 [
   [
     0,
@@ -23,7 +23,7 @@ select Users --filter 'fuzzy_search(name, "Tom", 1)'   --output_columns 'name, _
   [
     [
       [
-        2
+        3
       ],
       [
         [
@@ -36,11 +36,15 @@ select Users --filter 'fuzzy_search(name, "Tom", 1)'   --output_columns 'name, _
         ]
       ],
       [
+        "Tomy",
+        1
+      ],
+      [
         "Tom",
-        0
+        1
       ],
       [
-        "Tomy",
+        "Ken",
         1
       ]
     ]

  Added: test/command/suite/select/function/fuzzy_search/index/or.test (+16 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/fuzzy_search/index/or.test    2016-02-06 12:21:49 +0900 (a795b27)
@@ -0,0 +1,16 @@
+table_create Users TABLE_NO_KEY
+column_create Users name COLUMN_SCALAR ShortText
+
+table_create Tags TABLE_PAT_KEY ShortText
+column_create Tags tag COLUMN_INDEX Users name
+
+load --table Users
+[
+{"name": "Tom"},
+{"name": "Tomy"},
+{"name": "Ken"}
+]
+
+select Users --filter 'name @^ "T" || fuzzy_search(name, "Ke", 1)' \
+  --output_columns 'name, _score' \
+  --match_escalation_threshold -1

  Modified: test/command/suite/select/function/fuzzy_search/sequential/max_distance.expected (+2 -2)
===================================================================
--- test/command/suite/select/function/fuzzy_search/sequential/max_distance.expected    2016-02-05 22:41:43 +0900 (32da2f9)
+++ test/command/suite/select/function/fuzzy_search/sequential/max_distance.expected    2016-02-06 12:21:49 +0900 (a4c1cfd)
@@ -33,11 +33,11 @@ select Users --filter 'fuzzy_search(name, "To", 2)'   --output_columns 'name, _s
       ],
       [
         "Tom",
-        1
+        2
       ],
       [
         "Tomy",
-        2
+        1
       ]
     ]
   ]

  Modified: test/command/suite/select/function/fuzzy_search/sequential/max_expansion.expected (+1 -1)
===================================================================
--- test/command/suite/select/function/fuzzy_search/sequential/max_expansion.expected    2016-02-05 22:41:43 +0900 (d90c752)
+++ test/command/suite/select/function/fuzzy_search/sequential/max_expansion.expected    2016-02-06 12:21:49 +0900 (dd4bedb)
@@ -10,4 +10,4 @@ load --table Users
 ]
 [[0,0.0,0.0],3]
 select Users --filter 'fuzzy_search(name, "To", 2, 0, 1)'   --output_columns 'name, _score'   --match_escalation_threshold -1
-[[0,0.0,0.0],[[[1],[["name","ShortText"],["_score","Int32"]],["Tom",1]]]]
+[[0,0.0,0.0],[[[1],[["name","ShortText"],["_score","Int32"]],["Tom",2]]]]

  Modified: test/command/suite/select/function/fuzzy_search/sequential/prefix_length.expected (+2 -2)
===================================================================
--- test/command/suite/select/function/fuzzy_search/sequential/prefix_length.expected    2016-02-05 22:41:43 +0900 (4594a0e)
+++ test/command/suite/select/function/fuzzy_search/sequential/prefix_length.expected    2016-02-06 12:21:49 +0900 (8213bd8)
@@ -33,11 +33,11 @@ select Users --filter 'fuzzy_search(name, "To", 5, 1)'   --output_columns 'name,
       ],
       [
         "Tom",
-        1
+        5
       ],
       [
         "Tomy",
-        2
+        4
       ]
     ]
   ]

  Modified: test/command/suite/select/function/fuzzy_search/sequential/prefix_length_ja.expected (+2 -2)
===================================================================
--- test/command/suite/select/function/fuzzy_search/sequential/prefix_length_ja.expected    2016-02-05 22:41:43 +0900 (4630c63)
+++ test/command/suite/select/function/fuzzy_search/sequential/prefix_length_ja.expected    2016-02-06 12:21:49 +0900 (bdf80bb)
@@ -33,11 +33,11 @@ select Users --filter 'fuzzy_search(name, "とむ", 5, 1)'   --output_columns 'n
       ],
       [
         "とむ",
-        0
+        6
       ],
       [
         "とみー",
-        2
+        4
       ]
     ]
   ]

  Modified: test/command/suite/select/function/fuzzy_search/sequential/reference.expected (+1 -1)
===================================================================
--- test/command/suite/select/function/fuzzy_search/sequential/reference.expected    2016-02-05 22:41:43 +0900 (5371ffa)
+++ test/command/suite/select/function/fuzzy_search/sequential/reference.expected    2016-02-06 12:21:49 +0900 (1a8d5fe)
@@ -12,4 +12,4 @@ load --table Users
 ]
 [[0,0.0,0.0],3]
 select Users --filter 'fuzzy_search(name, "Tom", 2)'   --output_columns 'name, _score'   --match_escalation_threshold -1
-[[0,0.0,0.0],[[[2],[["name","Tag"],["_score","Int32"]],["Tom",0],["Tomy",1]]]]
+[[0,0.0,0.0],[[[2],[["name","Tag"],["_score","Int32"]],["Tom",3],["Tomy",2]]]]

  Modified: test/command/suite/select/function/fuzzy_search/sequential/reference_vector.expected (+2 -2)
===================================================================
--- test/command/suite/select/function/fuzzy_search/sequential/reference_vector.expected    2016-02-05 22:41:43 +0900 (9611f8c)
+++ test/command/suite/select/function/fuzzy_search/sequential/reference_vector.expected    2016-02-06 12:21:49 +0900 (c1c5a3b)
@@ -38,14 +38,14 @@ select Users --filter 'fuzzy_search(name, "Tom", 2)'   --output_columns 'name, _
           "Tom",
           "Tomy"
         ],
-        0
+        3
       ],
       [
         [
           "Tomy",
           "Tomas"
         ],
-        1
+        2
       ]
     ]
   ]

  Modified: test/command/suite/select/function/fuzzy_search/sequential/text.expected (+1 -1)
===================================================================
--- test/command/suite/select/function/fuzzy_search/sequential/text.expected    2016-02-05 22:41:43 +0900 (c6806c6)
+++ test/command/suite/select/function/fuzzy_search/sequential/text.expected    2016-02-06 12:21:49 +0900 (eaca3d9)
@@ -33,7 +33,7 @@ select Users --filter 'fuzzy_search(name, "Tom", 1)'   --output_columns 'name, _
       ],
       [
         "Tom",
-        0
+        2
       ],
       [
         "Tomy",

  Modified: test/command/suite/select/function/fuzzy_search/sequential/vector.expected (+2 -2)
===================================================================
--- test/command/suite/select/function/fuzzy_search/sequential/vector.expected    2016-02-05 22:41:43 +0900 (62ac73b)
+++ test/command/suite/select/function/fuzzy_search/sequential/vector.expected    2016-02-06 12:21:49 +0900 (4e3e521)
@@ -36,14 +36,14 @@ select Users --filter 'fuzzy_search(name, "Tom", 2)'   --output_columns 'name, _
           "Tom",
           "Tomy"
         ],
-        0
+        3
       ],
       [
         [
           "Tomy",
           "Tomas"
         ],
-        1
+        2
       ]
     ]
   ]
-------------- next part --------------
HTML����������������������������...
Download 



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