[Groonga-commit] groonga/groonga at c8d1154 [master] highlighter: fix a wrong highlight bug

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Aug 7 15:00:50 JST 2018


Kouhei Sutou	2018-08-07 15:00:50 +0900 (Tue, 07 Aug 2018)

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

  Message:
    highlighter: fix a wrong highlight bug
    
    It's caused when lexicon is hash table and keyword is less than N of
    N-gram.

  Added files:
    test/command/suite/select/function/highlight_html/lexicon/hash_table.expected
    test/command/suite/select/function/highlight_html/lexicon/hash_table.test
  Modified files:
    lib/highlighter.c

  Modified: lib/highlighter.c (+2 -1)
===================================================================
--- lib/highlighter.c    2018-08-07 14:42:25 +0900 (8d9da019c)
+++ lib/highlighter.c    2018-08-07 15:00:50 +0900 (0bffb4d73)
@@ -307,7 +307,8 @@ grn_highlighter_prepare_lexicon(grn_ctx *ctx,
     GRN_BULK_REWIND(token_id_chunk);
     while ((token_id = grn_token_cursor_next(ctx, cursor)) != GRN_ID_NIL) {
       GRN_TEXT_PUT(ctx, token_id_chunk, &token_id, sizeof(grn_id));
-      if (cursor->force_prefix) {
+      if (cursor->force_prefix &&
+          highlighter->lexicon.object->header.type != GRN_TABLE_HASH_KEY) {
         grn_token *token;
         const char *data;
         size_t data_length;

  Added: test/command/suite/select/function/highlight_html/lexicon/hash_table.expected (+44 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/highlight_html/lexicon/hash_table.expected    2018-08-07 15:00:50 +0900 (adb4e130a)
@@ -0,0 +1,44 @@
+table_create Entries TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Entries title COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+column_create Entries body COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+table_create Terms TABLE_HASH_KEY ShortText   --default_tokenizer 'TokenNgram("report_source_location", true)'   --normalizer 'NormalizerNFKC100'
+[[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
+[
+{"title": "タイトル", "body": "あ"}
+]
+[[0,0.0,0.0],1]
+select Entries   --match_columns body   --query 'あ'   --output_columns 'highlight_html(title, Terms),                     highlight_html(body, Terms)'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "highlight_html",
+          null
+        ],
+        [
+          "highlight_html",
+          null
+        ]
+      ],
+      [
+        "タイトル",
+        "<span class=\"keyword\">あ</span>"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/function/highlight_html/lexicon/hash_table.test (+19 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/highlight_html/lexicon/hash_table.test    2018-08-07 15:00:50 +0900 (61752dc4e)
@@ -0,0 +1,19 @@
+table_create Entries TABLE_NO_KEY
+column_create Entries title COLUMN_SCALAR ShortText
+column_create Entries body COLUMN_SCALAR ShortText
+
+table_create Terms TABLE_HASH_KEY ShortText \
+  --default_tokenizer 'TokenNgram("report_source_location", true)' \
+  --normalizer 'NormalizerNFKC100'
+column_create Terms document_index COLUMN_INDEX|WITH_POSITION Entries body
+
+load --table Entries
+[
+{"title": "タイトル", "body": "あ"}
+]
+
+select Entries \
+  --match_columns body \
+  --query 'あ' \
+  --output_columns 'highlight_html(title, Terms), \
+                    highlight_html(body, Terms)'
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180807/21416b7a/attachment-0001.htm 



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