[Groonga-commit] groonga/groonga at 528c32a [master] grn_pat_scan: fix a bug that garbage leading space is added

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Mar 30 11:25:07 JST 2017


Kouhei Sutou	2017-03-30 11:25:07 +0900 (Thu, 30 Mar 2017)

  New Revision: 528c32afba096c477348112e222f69071e7b6fde
  https://github.com/groonga/groonga/commit/528c32afba096c477348112e222f69071e7b6fde

  Message:
    grn_pat_scan: fix a bug that garbage leading space is added
    
    It's occurred when keyword doesn't start with single byte character.

  Added files:
    test/command/suite/select/function/highlight_html/space_before_target.expected
    test/command/suite/select/function/highlight_html/space_before_target.test
  Modified files:
    lib/pat.c

  Modified: lib/pat.c (+6 -3)
===================================================================
--- lib/pat.c    2017-03-30 10:24:13 +0900 (5b168ff)
+++ lib/pat.c    2017-03-30 11:25:07 +0900 (8e20fde)
@@ -1,5 +1,6 @@
 /* -*- c-basic-offset: 2 -*- */
-/* Copyright(C) 2009-2016 Brazil
+/*
+  Copyright(C) 2009-2017 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -2180,13 +2181,15 @@ grn_pat_scan(grn_ctx *ctx, grn_pat *pat, const char *str, unsigned int str_len,
         if ((tid = grn_pat_lcp_search(ctx, pat, sp, se - sp))) {
           const char *key;
           uint32_t len;
+          int first_key_char_len;
           key = _grn_pat_key(ctx, pat, tid, &len);
           sh[n].id = tid;
           sh[n].offset = (*cp > 0) ? offset : offset0;
+          first_key_char_len = grn_charlen(ctx, key, key + len);
           if (sh[n].offset > 0 &&
               GRN_CHAR_IS_BLANK(tp[-1]) &&
-              grn_charlen(ctx, key, key + len) == 1 &&
-              key[0] != ' ') {
+              ((first_key_char_len == 1 && key[0] != ' ') ||
+               first_key_char_len > 1)){
             /* Remove leading spaces. */
             const char *original_str = str + sh[n].offset;
             while (grn_charlen(ctx, original_str, str + str_len) == 1 &&

  Added: test/command/suite/select/function/highlight_html/space_before_target.expected (+37 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/highlight_html/space_before_target.expected    2017-03-30 11:25:07 +0900 (8cbf283)
@@ -0,0 +1,37 @@
+table_create Entries TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Entries body COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
+[[0,0.0,0.0],true]
+column_create Terms document_index COLUMN_INDEX|WITH_POSITION Entries body
+[[0,0.0,0.0],true]
+load --table Entries
+[
+{"body": "Groonga 高速!"}
+]
+[[0,0.0,0.0],1]
+select Entries --output_columns   --match_columns body --query '高速'   --output_columns 'highlight_html(body)'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "highlight_html",
+          null
+        ]
+      ],
+      [
+        "Groonga <span class=\"keyword\">高速</span>!"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/function/highlight_html/space_before_target.test (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/highlight_html/space_before_target.test    2017-03-30 11:25:07 +0900 (480a29b)
@@ -0,0 +1,14 @@
+table_create Entries TABLE_NO_KEY
+column_create Entries body COLUMN_SCALAR ShortText
+
+table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
+column_create Terms document_index COLUMN_INDEX|WITH_POSITION Entries body
+
+load --table Entries
+[
+{"body": "Groonga 高速!"}
+]
+
+select Entries --output_columns \
+  --match_columns body --query '高速' \
+  --output_columns 'highlight_html(body)'
-------------- next part --------------
HTML����������������������������...
Download 



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