[Groonga-commit] groonga/groonga at b348c30 [master] Use charactor_length instead of bytes for prefix_length in fuzzy_search()

Back to archive index

naoa null+****@clear*****
Fri Feb 5 13:27:07 JST 2016


naoa	2016-02-05 13:27:07 +0900 (Fri, 05 Feb 2016)

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

  Merged a300aa1: Merge pull request #464 from naoa/master

  Message:
    Use charactor_length instead of bytes for prefix_length in fuzzy_search()

  Copied files:
    test/command/suite/select/function/fuzzy_search/pat/prefix_length.expected
      (from test/command/suite/select/function/fuzzy_search/pat/prefix_match_size.expected)
    test/command/suite/select/function/fuzzy_search/pat/prefix_length.test
      (from test/command/suite/select/function/fuzzy_search/pat/prefix_match_size.test)
    test/command/suite/select/function/fuzzy_search/sequential/prefix_length.expected
      (from test/command/suite/select/function/fuzzy_search/sequential/prefix_match_size.expected)
    test/command/suite/select/function/fuzzy_search/sequential/prefix_length.test
      (from test/command/suite/select/function/fuzzy_search/sequential/prefix_match_size.test)
  Modified files:
    lib/proc.c
  Renamed files:
    test/command/suite/select/function/fuzzy_search/pat/prefix_length_ja.expected
      (from test/command/suite/select/function/fuzzy_search/pat/prefix_match_size.expected)
    test/command/suite/select/function/fuzzy_search/pat/prefix_length_ja.test
      (from test/command/suite/select/function/fuzzy_search/pat/prefix_match_size.test)
    test/command/suite/select/function/fuzzy_search/sequential/prefix_length_ja.expected
      (from test/command/suite/select/function/fuzzy_search/sequential/prefix_match_size.expected)
    test/command/suite/select/function/fuzzy_search/sequential/prefix_length_ja.test
      (from test/command/suite/select/function/fuzzy_search/sequential/prefix_match_size.test)
    test/command/suite/select/function/fuzzy_search/sequential/reference.expected
      (from test/command/suite/select/function/fuzzy_search/sequential/reference.expeected)

  Modified: lib/proc.c (+16 -1)
===================================================================
--- lib/proc.c    2016-02-05 13:03:40 +0900 (0c21915)
+++ lib/proc.c    2016-02-05 13:27:07 +0900 (74d7369)
@@ -7018,6 +7018,7 @@ selector_fuzzy_search(grn_ctx *ctx, grn_obj *table, grn_obj *index,
   grn_obj *obj;
   grn_obj *query;
   uint32_t max_distance = 1;
+  uint32_t prefix_length = 0;
   uint32_t prefix_match_size = 0;
   uint32_t max_expansion = 0;
   int flags = 0;
@@ -7036,7 +7037,7 @@ selector_fuzzy_search(grn_ctx *ctx, grn_obj *table, grn_obj *index,
     max_distance = GRN_UINT32_VALUE(args[3]);
   }
   if (nargs >= 5) {
-    prefix_match_size = GRN_UINT32_VALUE(args[4]);
+    prefix_length = GRN_UINT32_VALUE(args[4]);
   }
   if (nargs >= 6) {
     max_expansion = GRN_UINT32_VALUE(args[5]);
@@ -7064,6 +7065,20 @@ selector_fuzzy_search(grn_ctx *ctx, grn_obj *table, grn_obj *index,
       }
     }
   }
+  if (prefix_length) {
+    const char *s = GRN_TEXT_VALUE(query);
+    const char *e = GRN_BULK_CURR(query);
+    const char *p;
+    unsigned int cl = 0;
+    unsigned int length = 0;
+    for (p = s; p < e && (cl = grn_charlen(ctx, p, e)); p += cl) {
+      length++;
+      if (length > prefix_length) {
+        break;
+      }
+    }
+    prefix_match_size = p - s;
+  }
 
   if (use_sequential_search) {
     grn_obj *hash;

  Copied: test/command/suite/select/function/fuzzy_search/pat/prefix_length.expected (+0 -0) 100%
===================================================================

  Copied: test/command/suite/select/function/fuzzy_search/pat/prefix_length.test (+0 -0) 100%
===================================================================

  Renamed: test/command/suite/select/function/fuzzy_search/pat/prefix_length_ja.expected (+7 -7) 69%
===================================================================
--- test/command/suite/select/function/fuzzy_search/pat/prefix_match_size.expected    2016-02-05 13:03:40 +0900 (55c11d9)
+++ test/command/suite/select/function/fuzzy_search/pat/prefix_length_ja.expected    2016-02-05 13:27:07 +0900 (39ee32d)
@@ -8,12 +8,12 @@ column_create Tags tag COLUMN_INDEX Users name
 [[0,0.0,0.0],true]
 load --table Users
 [
-{"name": "Tom"},
-{"name": "Tomy"},
-{"name": "Ken"}
+{"name": "とむ"},
+{"name": "とみー"},
+{"name": "けん"}
 ]
 [[0,0.0,0.0],3]
-select Tags --filter 'fuzzy_search(_key, "To", 5, 1)'   --output_columns '_key, _score'   --match_escalation_threshold -1
+select Tags --filter 'fuzzy_search(_key, "とむ", 5, 1)'   --output_columns '_key, _score'   --match_escalation_threshold -1
 [
   [
     0,
@@ -36,11 +36,11 @@ select Tags --filter 'fuzzy_search(_key, "To", 5, 1)'   --output_columns '_key,
         ]
       ],
       [
-        "Tom",
-        1
+        "とむ",
+        0
       ],
       [
-        "Tomy",
+        "とみー",
         2
       ]
     ]

  Renamed: test/command/suite/select/function/fuzzy_search/pat/prefix_length_ja.test (+4 -4) 68%
===================================================================
--- test/command/suite/select/function/fuzzy_search/pat/prefix_match_size.test    2016-02-05 13:03:40 +0900 (d757302)
+++ test/command/suite/select/function/fuzzy_search/pat/prefix_length_ja.test    2016-02-05 13:27:07 +0900 (47929ba)
@@ -6,11 +6,11 @@ column_create Tags tag COLUMN_INDEX Users name
 
 load --table Users
 [
-{"name": "Tom"},
-{"name": "Tomy"},
-{"name": "Ken"}
+{"name": "とむ"},
+{"name": "とみー"},
+{"name": "けん"}
 ]
 
-select Tags --filter 'fuzzy_search(_key, "To", 5, 1)' \
+select Tags --filter 'fuzzy_search(_key, "とむ", 5, 1)' \
   --output_columns '_key, _score' \
   --match_escalation_threshold -1

  Copied: test/command/suite/select/function/fuzzy_search/sequential/prefix_length.expected (+0 -0) 100%
===================================================================

  Copied: test/command/suite/select/function/fuzzy_search/sequential/prefix_length.test (+0 -0) 100%
===================================================================

  Renamed: test/command/suite/select/function/fuzzy_search/sequential/prefix_length_ja.expected (+7 -7) 63%
===================================================================
--- test/command/suite/select/function/fuzzy_search/sequential/prefix_match_size.expected    2016-02-05 13:03:40 +0900 (4594a0e)
+++ test/command/suite/select/function/fuzzy_search/sequential/prefix_length_ja.expected    2016-02-05 13:27:07 +0900 (4630c63)
@@ -4,12 +4,12 @@ column_create Users name COLUMN_SCALAR ShortText
 [[0,0.0,0.0],true]
 load --table Users
 [
-{"name": "Tom"},
-{"name": "Tomy"},
-{"name": "Ken"}
+{"name": "とむ"},
+{"name": "とみー"},
+{"name": "けん"}
 ]
 [[0,0.0,0.0],3]
-select Users --filter 'fuzzy_search(name, "To", 5, 1)'   --output_columns 'name, _score'   --match_escalation_threshold -1
+select Users --filter 'fuzzy_search(name, "とむ", 5, 1)'   --output_columns 'name, _score'   --match_escalation_threshold -1
 [
   [
     0,
@@ -32,11 +32,11 @@ select Users --filter 'fuzzy_search(name, "To", 5, 1)'   --output_columns 'name,
         ]
       ],
       [
-        "Tom",
-        1
+        "とむ",
+        0
       ],
       [
-        "Tomy",
+        "とみー",
         2
       ]
     ]

  Renamed: test/command/suite/select/function/fuzzy_search/sequential/prefix_length_ja.test (+4 -4) 58%
===================================================================
--- test/command/suite/select/function/fuzzy_search/sequential/prefix_match_size.test    2016-02-05 13:03:40 +0900 (ea1cd5e)
+++ test/command/suite/select/function/fuzzy_search/sequential/prefix_length_ja.test    2016-02-05 13:27:07 +0900 (cc94171)
@@ -3,11 +3,11 @@ column_create Users name COLUMN_SCALAR ShortText
 
 load --table Users
 [
-{"name": "Tom"},
-{"name": "Tomy"},
-{"name": "Ken"}
+{"name": "とむ"},
+{"name": "とみー"},
+{"name": "けん"}
 ]
 
-select Users --filter 'fuzzy_search(name, "To", 5, 1)' \
+select Users --filter 'fuzzy_search(name, "とむ", 5, 1)' \
   --output_columns 'name, _score' \
   --match_escalation_threshold -1

  Renamed: test/command/suite/select/function/fuzzy_search/sequential/reference.expected (+0 -0) 100%
===================================================================
-------------- next part --------------
HTML����������������������������...
Download 



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