[Groonga-commit] groonga/groonga at 479b2e8 [master] Add token filter plugin API

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Oct 2 22:51:25 JST 2014


Kouhei Sutou	2014-10-02 22:51:25 +0900 (Thu, 02 Oct 2014)

  New Revision: 479b2e8faf34dac18e594e9d84d17b58694e6ffa
  https://github.com/groonga/groonga/commit/479b2e8faf34dac18e594e9d84d17b58694e6ffa

  Merged fec9865: Merge pull request #209 from groonga/support-token-filters

  Message:
    Add token filter plugin API

  Added files:
    include/groonga/token_filter.h
    lib/token_filter.c
  Modified files:
    include/groonga.h
    include/groonga/Makefile.am
    lib/util.c

  Modified: include/groonga.h (+3 -1)
===================================================================
--- include/groonga.h    2014-10-02 22:50:19 +0900 (55a4e71)
+++ include/groonga.h    2014-10-02 22:51:25 +0900 (5796eca)
@@ -116,6 +116,7 @@ typedef enum {
   GRN_CAS_ERROR = -70,
   GRN_UNSUPPORTED_COMMAND_VERSION = -71,
   GRN_NORMALIZER_ERROR = -72,
+  GRN_TOKEN_FILTER_ERROR = -73,
 } grn_rc;
 
 GRN_API grn_rc grn_init(void);
@@ -478,7 +479,8 @@ typedef enum {
   GRN_PROC_COMMAND,
   GRN_PROC_FUNCTION,
   GRN_PROC_HOOK,
-  GRN_PROC_NORMALIZER
+  GRN_PROC_NORMALIZER,
+  GRN_PROC_TOKEN_FILTER
 } grn_proc_type;
 
 GRN_API grn_obj *grn_proc_create(grn_ctx *ctx,

  Modified: include/groonga/Makefile.am (+1 -0)
===================================================================
--- include/groonga/Makefile.am    2014-10-02 22:50:19 +0900 (baf9ca5)
+++ include/groonga/Makefile.am    2014-10-02 22:51:25 +0900 (5cfb619)
@@ -2,5 +2,6 @@ groonga_includedir = $(pkgincludedir)/groonga
 groonga_include_HEADERS =			\
 	plugin.h				\
 	tokenizer.h				\
+	token_filter.h				\
 	nfkc.h					\
 	normalizer.h

  Added: include/groonga/token_filter.h (+52 -0) 100644
===================================================================
--- /dev/null
+++ include/groonga/token_filter.h    2014-10-02 22:51:25 +0900 (347715a)
@@ -0,0 +1,52 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2014 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#ifndef GRN_PLUGIN_TOKEN_FILTER_H
+#define GRN_PLUGIN_TOKEN_FILTER_H
+
+#include <stddef.h>
+
+#include <groonga/tokenizer.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif  /* __cplusplus */
+
+/*
+  grn_token_filter_register() registers a plugin to the database which is
+  associated with `ctx'. `plugin_name_ptr' and `plugin_name_length' specify the
+  plugin name. Alphabetic letters ('A'-'Z' and 'a'-'z'), digits ('0'-'9') and
+  an underscore ('_') are capable characters. `init', `next' and `fin' specify
+  the plugin functions. `init' is called for initializing a token_filter for a
+  document or query. `next' is called for extracting tokens one by one. `fin'
+  is called for finalizing a token_filter. grn_token_filter_register() returns
+  GRN_SUCCESS on success, an error code on failure. See "groonga.h" for more
+  details of grn_proc_func and grn_user_data, that is used as an argument of
+  grn_proc_func.
+ */
+GRN_PLUGIN_EXPORT grn_rc grn_token_filter_register(grn_ctx *ctx,
+                                                   const char *plugin_name_ptr,
+                                                   int plugin_name_length,
+                                                   grn_proc_func *init,
+                                                   grn_proc_func *next,
+                                                   grn_proc_func *fin);
+
+#ifdef __cplusplus
+}  /* extern "C" */
+#endif  /* __cplusplus */
+
+#endif  /* GRN_PLUGIN_TOKEN_FILTER_H */

  Added: lib/token_filter.c (+56 -0) 100644
===================================================================
--- /dev/null
+++ lib/token_filter.c    2014-10-02 22:51:25 +0900 (470f9f1)
@@ -0,0 +1,56 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2014 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include <string.h>
+
+#include "groonga_in.h"
+#include <groonga/token_filter.h>
+
+grn_rc
+grn_token_filter_register(grn_ctx *ctx,
+                          const char *plugin_name_ptr,
+                          int plugin_name_length,
+                          grn_proc_func *init,
+                          grn_proc_func *next,
+                          grn_proc_func *fin)
+{
+  grn_expr_var vars[] = {
+    { NULL, 0 },
+    { NULL, 0 },
+    { NULL, 0 }
+  };
+  GRN_TEXT_INIT(&vars[0].value, 0);
+  GRN_TEXT_INIT(&vars[1].value, 0);
+  GRN_UINT32_INIT(&vars[2].value, 0);
+
+  if (plugin_name_length == -1) {
+    plugin_name_length = strlen(plugin_name_ptr);
+  }
+  {
+    grn_obj * const obj = grn_proc_create(ctx,
+                                          plugin_name_ptr,
+                                          plugin_name_length,
+                                          GRN_PROC_TOKENIZER,
+                                          init, next, fin, 3, vars);
+    if (obj == NULL) {
+      GRN_PLUGIN_ERROR(ctx, GRN_TOKEN_FILTER_ERROR, "grn_proc_create() failed");
+      return ctx->rc;
+    }
+  }
+  return GRN_SUCCESS;
+}

  Modified: lib/util.c (+4 -1)
===================================================================
--- lib/util.c    2014-10-02 22:50:19 +0900 (62794ab)
+++ lib/util.c    2014-10-02 22:51:25 +0900 (837f6d2)
@@ -1,5 +1,5 @@
 /* -*- c-basic-offset: 2 -*- */
-/* Copyright(C) 2010-2013 Brazil
+/* Copyright(C) 2010-2014 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -251,6 +251,9 @@ grn_proc_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj)
   case GRN_PROC_NORMALIZER :
     GRN_TEXT_PUTS(ctx, buf, "normalizer");
     break;
+  case GRN_PROC_TOKEN_FILTER :
+    GRN_TEXT_PUTS(ctx, buf, "token-filter");
+    break;
   }
   GRN_TEXT_PUTS(ctx, buf, " ");
 
-------------- next part --------------
HTML����������������������������...
Descargar 



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