[Groonga-commit] groonga/groonga at 9f8019e [master] grn_string_open: accept lexicon instead of normalizer

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Apr 11 16:15:05 JST 2018


Kouhei Sutou	2018-04-11 16:15:05 +0900 (Wed, 11 Apr 2018)

  New Revision: 9f8019e58d3bc19fb2b4b5e7ff88c44db345cb7a
  https://github.com/groonga/groonga/commit/9f8019e58d3bc19fb2b4b5e7ff88c44db345cb7a

  Message:
    grn_string_open: accept lexicon instead of normalizer

  Modified files:
    include/groonga/string.h
    lib/grn_string.h
    lib/string.c

  Modified: include/groonga/string.h (+3 -1)
===================================================================
--- include/groonga/string.h    2018-04-11 14:34:11 +0900 (4adc5783a)
+++ include/groonga/string.h    2018-04-11 16:15:05 +0900 (609d95097)
@@ -76,7 +76,8 @@ GRN_API const char *grn_char_type_to_string(grn_char_type type);
 GRN_API grn_obj *grn_string_open(grn_ctx *ctx,
                                  const char *string,
                                  unsigned int length_in_bytes,
-                                 grn_obj *normalizer, int flags);
+                                 grn_obj *lexicon_or_normalizer,
+                                 int flags);
 GRN_API grn_rc grn_string_get_original(grn_ctx *ctx, grn_obj *string,
                                        const char **original,
                                        unsigned int *length_in_bytes);
@@ -98,6 +99,7 @@ GRN_API grn_rc grn_string_set_types(grn_ctx *ctx,
                                     grn_obj *string,
                                     unsigned char *types);
 GRN_API grn_encoding grn_string_get_encoding(grn_ctx *ctx, grn_obj *string);
+GRN_API grn_obj *grn_string_get_table(grn_ctx *ctx, grn_obj *string);
 
 
 GRN_API int grn_charlen(grn_ctx *ctx, const char *str, const char *end);

  Modified: lib/grn_string.h (+8 -3)
===================================================================
--- lib/grn_string.h    2018-04-11 14:34:11 +0900 (95454ef0e)
+++ lib/grn_string.h    2018-04-11 16:15:05 +0900 (c7e7bad06)
@@ -1,6 +1,6 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
-  Copyright(C) 2012-2016 Brazil
+  Copyright(C) 2012-2018 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -39,10 +39,15 @@ typedef struct {
   unsigned char *ctypes;
   grn_encoding encoding;
   int flags;
+  grn_obj *lexicon;
 } grn_string;
 
-grn_obj *grn_string_open_(grn_ctx *ctx, const char *str, unsigned int str_len,
-                          grn_obj *normalizer, int flags, grn_encoding encoding);
+grn_obj *grn_string_open_(grn_ctx *ctx,
+                          const char *str,
+                          unsigned int str_len,
+                          grn_obj *lexicon_or_normalizer,
+                          int flags,
+                          grn_encoding encoding);
 grn_rc grn_string_close(grn_ctx *ctx, grn_obj *string);
 grn_rc grn_string_inspect(grn_ctx *ctx, grn_obj *buffer, grn_obj *string);
 

  Modified: lib/string.c (+49 -12)
===================================================================
--- lib/string.c    2018-04-11 14:34:11 +0900 (cbe42ac24)
+++ lib/string.c    2018-04-11 16:15:05 +0900 (01eb9273f)
@@ -180,8 +180,12 @@ grn_fake_string_open(grn_ctx *ctx, grn_string *string)
 }
 
 grn_obj *
-grn_string_open_(grn_ctx *ctx, const char *str, unsigned int str_len,
-                 grn_obj *normalizer, int flags, grn_encoding encoding)
+grn_string_open_(grn_ctx *ctx,
+                 const char *str,
+                 unsigned int str_len,
+                 grn_obj *lexicon_or_normalizer,
+                 int flags,
+                 grn_encoding encoding)
 {
   grn_string *string;
   grn_obj *obj;
@@ -191,10 +195,10 @@ grn_string_open_(grn_ctx *ctx, const char *str, unsigned int str_len,
     return NULL;
   }
 
-  is_normalizer_auto = (normalizer == GRN_NORMALIZER_AUTO);
+  is_normalizer_auto = (lexicon_or_normalizer == GRN_NORMALIZER_AUTO);
   if (is_normalizer_auto) {
-    normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1);
-    if (!normalizer) {
+    lexicon_or_normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1);
+    if (!lexicon_or_normalizer) {
       ERR(GRN_INVALID_ARGUMENT,
           "[string][open] NormalizerAuto normalizer isn't available");
       return NULL;
@@ -204,7 +208,7 @@ grn_string_open_(grn_ctx *ctx, const char *str, unsigned int str_len,
   string = GRN_MALLOCN(grn_string, 1);
   if (!string) {
     if (is_normalizer_auto) {
-      grn_obj_unlink(ctx, normalizer);
+      grn_obj_unlink(ctx, lexicon_or_normalizer);
     }
     GRN_LOG(ctx, GRN_LOG_ALERT,
             "[string][open] failed to allocate memory");
@@ -222,29 +226,50 @@ grn_string_open_(grn_ctx *ctx, const char *str, unsigned int str_len,
   string->ctypes = NULL;
   string->encoding = encoding;
   string->flags = flags;
+  string->lexicon = NULL;
 
-  if (!normalizer) {
+  if (!lexicon_or_normalizer) {
     return (grn_obj *)grn_fake_string_open(ctx, string);
   }
 
-  grn_normalizer_normalize(ctx, normalizer, (grn_obj *)string);
+  {
+    grn_obj *normalizer;
+    if (grn_obj_is_table(ctx, lexicon_or_normalizer)) {
+      string->lexicon = lexicon_or_normalizer;
+      normalizer = grn_obj_get_info(ctx,
+                                    string->lexicon,
+                                    GRN_INFO_NORMALIZER,
+                                    NULL);
+    } else {
+      normalizer = lexicon_or_normalizer;
+    }
+    grn_normalizer_normalize(ctx, normalizer, (grn_obj *)string);
+  }
   if (ctx->rc) {
     grn_obj_close(ctx, obj);
     obj = NULL;
   }
 
   if (is_normalizer_auto) {
-    grn_obj_unlink(ctx, normalizer);
+    grn_obj_unlink(ctx, lexicon_or_normalizer);
   }
 
   return obj;
 }
 
 grn_obj *
-grn_string_open(grn_ctx *ctx, const char *str, unsigned int str_len,
-                grn_obj *normalizer, int flags)
+grn_string_open(grn_ctx *ctx,
+                const char *str,
+                unsigned int str_len,
+                grn_obj *lexicon_or_normalizer,
+                int flags)
 {
-  return grn_string_open_(ctx, str, str_len, normalizer, flags, ctx->encoding);
+  return grn_string_open_(ctx,
+                          str,
+                          str_len,
+                          lexicon_or_normalizer,
+                          flags,
+                          ctx->encoding);
 }
 
 grn_rc
@@ -396,6 +421,18 @@ grn_string_get_encoding(grn_ctx *ctx, grn_obj *string)
   GRN_API_RETURN(encoding);
 }
 
+grn_obj *
+grn_string_get_table(grn_ctx *ctx, grn_obj *string)
+{
+  grn_obj *table = NULL;
+  grn_string *string_ = (grn_string *)string;
+  GRN_API_ENTER;
+  if (string_) {
+    table = string_->lexicon;
+  }
+  GRN_API_RETURN(table);
+}
+
 grn_rc
 grn_string_inspect(grn_ctx *ctx, grn_obj *buffer, grn_obj *string)
 {
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180411/6c889096/attachment-0001.htm 



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