[Groonga-commit] groonga/groonga at f1185e2 [master] Add grn_table_tokenize.

Back to archive index

Daijiro MORI null+****@clear*****
Sat Sep 14 15:44:20 JST 2013


Daijiro MORI	2013-09-14 15:44:20 +0900 (Sat, 14 Sep 2013)

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

  Message:
    Add grn_table_tokenize.

  Modified files:
    include/groonga.h
    lib/db.c

  Modified: include/groonga.h (+4 -0)
===================================================================
--- include/groonga.h    2013-09-13 12:43:13 +0900 (c8db6df)
+++ include/groonga.h    2013-09-14 15:44:20 +0900 (e7ce421)
@@ -1709,6 +1709,10 @@ GRN_API unsigned int grn_table_get_subrecs(grn_ctx *ctx, grn_obj *table,
                                            grn_id id, grn_id *subrecbuf,
                                            int *scorebuf, int buf_size);
 
+GRN_API grn_obj *grn_table_tokenize(grn_ctx *ctx, grn_obj *table,
+                                    const char *str, unsigned int str_len,
+                                    grn_obj *buf, grn_bool addp);
+
 GRN_API grn_rc grn_load(grn_ctx *ctx, grn_content_type input_type,
                         const char *table, unsigned int table_len,
                         const char *columns, unsigned int columns_len,

  Modified: lib/db.c (+31 -0)
===================================================================
--- lib/db.c    2013-09-13 12:43:13 +0900 (2a4f7ab)
+++ lib/db.c    2013-09-14 15:44:20 +0900 (d992ea1)
@@ -9107,6 +9107,37 @@ grn_table_max_n_subrecs(grn_ctx *ctx, grn_obj *table)
   return 0;
 }
 
+grn_obj *
+grn_table_tokenize(grn_ctx *ctx, grn_obj *table,
+                   const char *str, unsigned int str_len,
+                   grn_obj *buf, grn_bool addp)
+{
+  grn_token *token = NULL;
+  grn_token_mode mode = addp ? GRN_TOKEN_ADD : GRN_TOKEN_GET;
+  GRN_API_ENTER;
+  if (!(token = grn_token_open(ctx, table, str, str_len, mode, 0))) {
+    goto exit;
+  }
+  if (buf) {
+    GRN_BULK_REWIND(buf);
+  } else {
+    if (!(buf = grn_obj_open(ctx, GRN_UVECTOR, 0, DB_OBJ(table)->id))) {
+      goto exit;
+    }
+  }
+  while (!token->status) {
+    grn_id tid;
+    if ((tid = grn_token_next(ctx, token))) {
+      GRN_RECORD_PUT(ctx, buf, tid);
+    }
+  }
+exit :
+  if (token) {
+    grn_token_close(ctx, token);
+  }
+  GRN_API_RETURN(buf);
+}
+
 /* grn_load */
 
 static grn_obj *
-------------- next part --------------
HTML����������������������������...
Download 



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