Skip to content

Commit

Permalink
Hide grn_tokenizer_query internal
Browse files Browse the repository at this point in the history
Direct grn_tokenizer_query field access is deprecated. Use
grn_tokenizer_query_* instead.
  • Loading branch information
kou committed May 8, 2018
1 parent 57862cf commit 5d7ed50
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 153 deletions.
44 changes: 24 additions & 20 deletions include/groonga/tokenizer.h
@@ -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
Expand All @@ -20,6 +20,7 @@

#include <groonga/plugin.h>
#include <groonga/token.h>
#include <groonga/tokenizer_query_deprecated.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -69,25 +70,6 @@ GRN_PLUGIN_EXPORT grn_bool grn_tokenizer_have_tokenized_delimiter(grn_ctx *ctx,
unsigned int str_length,
grn_encoding encoding);

/*
grn_tokenizer_query is a structure for storing a query. See the following
functions.
*/
typedef struct _grn_tokenizer_query grn_tokenizer_query;

struct _grn_tokenizer_query {
grn_obj *normalized_query;
char *query_buf;
const char *ptr;
unsigned int length;
grn_encoding encoding;
unsigned int flags;
grn_bool have_tokenized_delimiter;
/* Deprecated since 4.0.8. Use tokenize_mode instead. */
grn_token_mode token_mode;
grn_tokenize_mode tokenize_mode;
};

/*
grn_tokenizer_query_open() parses `args' and returns a new object of
grn_tokenizer_query. The new object stores information of the query.
Expand Down Expand Up @@ -122,6 +104,28 @@ GRN_PLUGIN_EXPORT void grn_tokenizer_query_close(grn_ctx *ctx, grn_tokenizer_que
*/
void grn_tokenizer_query_destroy(grn_ctx *ctx, grn_tokenizer_query *query);

GRN_PLUGIN_EXPORT grn_obj *
grn_tokenizer_query_get_normalized_string(grn_ctx *ctx,
grn_tokenizer_query *query);

GRN_PLUGIN_EXPORT const char *
grn_tokenizer_query_get_raw_string(grn_ctx *ctx,
grn_tokenizer_query *query,
size_t *length);

GRN_PLUGIN_EXPORT grn_encoding
grn_tokenizer_query_get_encoding(grn_ctx *ctx, grn_tokenizer_query *query);

GRN_PLUGIN_EXPORT unsigned int
grn_tokenizer_query_get_flags(grn_ctx *ctx, grn_tokenizer_query *query);

GRN_PLUGIN_EXPORT grn_bool
grn_tokenizer_query_have_tokenized_delimiter(grn_ctx *ctx,
grn_tokenizer_query *query);

GRN_PLUGIN_EXPORT grn_tokenize_mode
grn_tokenizer_query_get_mode(grn_ctx *ctx, grn_tokenizer_query *query);

/*
grn_tokenizer_token is needed to return tokens. A grn_tokenizer_token object
stores a token to be returned and it must be maintained until a request for
Expand Down
3 changes: 3 additions & 0 deletions lib/db.c
Expand Up @@ -15,7 +15,10 @@
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 "grn.h"
#include "grn_tokenizer.h"

#include "grn_config.h"
#include "grn_db.h"
#include "grn_obj.h"
Expand Down
3 changes: 3 additions & 0 deletions lib/expr.c
Expand Up @@ -15,7 +15,10 @@
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 "grn.h"
#include "grn_tokenizer.h"

#include "grn_db.h"
#include "grn_ctx_impl.h"
#include "grn_ctx_impl_mrb.h"
Expand Down
3 changes: 1 addition & 2 deletions lib/grn_token_cursor.h
Expand Up @@ -19,10 +19,9 @@
#pragma once

#include "grn_ctx.h"
#include "grn_tokenizer.h"
#include "grn_db.h"

#include <groonga/tokenizer.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
48 changes: 46 additions & 2 deletions lib/tokenizer.c
@@ -1,6 +1,6 @@
/* -*- c-basic-offset: 2 -*- */
/*
Copyright(C) 2012-2014 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
Expand All @@ -15,8 +15,9 @@
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 "grn.h"
#include <groonga/tokenizer.h>
#include "grn_tokenizer.h"

#include <string.h>

Expand Down Expand Up @@ -218,6 +219,49 @@ grn_tokenizer_query_destroy(grn_ctx *ctx, grn_tokenizer_query *query)
grn_tokenizer_query_close(ctx, query);
}

grn_obj *
grn_tokenizer_query_get_normalized_string(grn_ctx *ctx,
grn_tokenizer_query *query)
{
return query->normalized_query;
}

const char *
grn_tokenizer_query_get_raw_string(grn_ctx *ctx,
grn_tokenizer_query *query,
size_t *length)
{
if (length) {
*length = query->length;
}
return query->ptr;
}

grn_encoding
grn_tokenizer_query_get_encoding(grn_ctx *ctx, grn_tokenizer_query *query)
{
return query->encoding;
}

unsigned int
grn_tokenizer_query_get_flags(grn_ctx *ctx, grn_tokenizer_query *query)
{
return query->flags;
}

grn_bool
grn_tokenizer_query_have_tokenized_delimiter(grn_ctx *ctx,
grn_tokenizer_query *query)
{
return query->have_tokenized_delimiter;
}

grn_tokenize_mode
grn_tokenizer_query_get_mode(grn_ctx *ctx, grn_tokenizer_query *query)
{
return query->tokenize_mode;
}

void
grn_tokenizer_token_init(grn_ctx *ctx, grn_tokenizer_token *token)
{
Expand Down

0 comments on commit 5d7ed50

Please sign in to comment.