[Groonga-commit] groonga/groonga at 33490a2 [master] highlighter: add duplicated keyword check

Back to archive index

Kouhei Sutou null+****@clear*****
Tue May 15 11:22:54 JST 2018


Kouhei Sutou	2018-05-15 11:22:54 +0900 (Tue, 15 May 2018)

  New Revision: 33490a2fb7c78928933267f19e41c44e103eb760
  https://github.com/groonga/groonga/commit/33490a2fb7c78928933267f19e41c44e103eb760

  Message:
    highlighter: add duplicated keyword check

  Modified files:
    lib/highlighter.c

  Modified: lib/highlighter.c (+21 -1)
===================================================================
--- lib/highlighter.c    2018-05-15 11:07:46 +0900 (127718fcf)
+++ lib/highlighter.c    2018-05-15 11:22:54 +0900 (d9e730c3c)
@@ -767,6 +767,9 @@ grn_highlighter_add_keyword(grn_ctx *ctx,
                             const char *keyword,
                             int64_t keyword_length)
 {
+  unsigned int i, n_keywords;
+  grn_obj *raw_keywords = &(highlighter->raw_keywords);
+
   GRN_API_ENTER;
 
   if (keyword_length < 0) {
@@ -777,8 +780,25 @@ grn_highlighter_add_keyword(grn_ctx *ctx,
     goto exit;
   }
 
+  n_keywords = grn_vector_size(ctx, raw_keywords);
+  for (i = 0; i < n_keywords; i++) {
+    const char *existing_keyword;
+    unsigned int length;
+
+    length = grn_vector_get_element(ctx,
+                                    raw_keywords,
+                                    i,
+                                    &existing_keyword,
+                                    NULL,
+                                    NULL);
+    if (length == keyword_length &&
+        memcmp(keyword, existing_keyword, length) == 0) {
+      goto exit;
+    }
+  }
+
   grn_vector_add_element(ctx,
-                         &(highlighter->raw_keywords),
+                         raw_keywords,
                          keyword,
                          keyword_length,
                          0,
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180515/9043d4e5/attachment.htm 



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