Kouhei Sutou
null+****@clear*****
Sat Dec 29 14:47:54 JST 2012
Kouhei Sutou 2012-12-29 14:47:54 +0900 (Sat, 29 Dec 2012) New Revision: b3e53b889385e98cf25b4ed080fe02449b50e89b https://github.com/groonga/groonga/commit/b3e53b889385e98cf25b4ed080fe02449b50e89b Log: Reference the default normalizer by name instead of ID Because ID of the default normalizer can't be fixed when we open a database that is created by old groonga. In the old database, we cannot use ID < 256 for normalizer because ID < 256 are already registered. :< Modified files: lib/dat.cpp lib/expr.c lib/hash.c lib/normalizer.c lib/normalizer_in.h lib/pat.c lib/string.c Modified: lib/dat.cpp (+7 -4) =================================================================== --- lib/dat.cpp 2012-12-28 17:48:05 +0900 (b5f7647) +++ lib/dat.cpp 2012-12-29 14:47:54 +0900 (728d797) @@ -23,6 +23,7 @@ #include "io.h" #include "dat.h" #include "util.h" +#include "normalizer_in.h" #include "dat/trie.hpp" #include "dat/cursor-factory.hpp" @@ -303,8 +304,8 @@ grn_dat_create(grn_ctx *ctx, const char *path, uint32_t, dat->header->file_id = 0; if (dat->header->flags & GRN_OBJ_KEY_NORMALIZE) { dat->header->flags &= ~GRN_OBJ_KEY_NORMALIZE; - dat->header->normalizer = GRN_DB_NORMALIZER_AUTO; - dat->normalizer = grn_ctx_at(ctx, dat->header->normalizer); + dat->normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1); + dat->header->normalizer = grn_obj_id(ctx, dat->normalizer); } else { dat->header->normalizer = GRN_ID_NIL; dat->normalizer = NULL; @@ -349,9 +350,11 @@ grn_dat_open(grn_ctx *ctx, const char *path) dat->tokenizer = grn_ctx_at(ctx, dat->header->tokenizer); if (dat->header->flags & GRN_OBJ_KEY_NORMALIZE) { dat->header->flags &= ~GRN_OBJ_KEY_NORMALIZE; - dat->header->normalizer = GRN_DB_NORMALIZER_AUTO; + dat->normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1); + dat->header->normalizer = grn_obj_id(ctx, dat->normalizer); + } else { + dat->normalizer = grn_ctx_at(ctx, dat->header->normalizer); } - dat->normalizer = grn_ctx_at(ctx, dat->header->normalizer); return dat; } Modified: lib/expr.c (+2 -1) =================================================================== --- lib/expr.c 2012-12-28 17:48:05 +0900 (496c2b8) +++ lib/expr.c 2012-12-29 14:47:54 +0900 (6893b76) @@ -23,6 +23,7 @@ #include "ii.h" #include "geo.h" #include "util.h" +#include "normalizer_in.h" static inline int function_proc_p(grn_obj *obj) @@ -2301,7 +2302,7 @@ pseudo_query_scan(grn_ctx *ctx, grn_obj *x, grn_obj *y, grn_obj *res) grn_obj *normalizer; grn_obj *a = NULL, *b = NULL; - normalizer = grn_ctx_at(ctx, GRN_DB_NORMALIZER_AUTO); + normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1); switch (x->header.domain) { case GRN_DB_SHORT_TEXT: case GRN_DB_TEXT: Modified: lib/hash.c (+7 -4) =================================================================== --- lib/hash.c 2012-12-28 17:48:05 +0900 (3267179) +++ lib/hash.c 2012-12-29 14:47:54 +0900 (050ec2b) @@ -21,6 +21,7 @@ #include <limits.h> #include "store.h" +#include "normalizer_in.h" /* grn_tiny_array */ @@ -1484,8 +1485,8 @@ grn_io_hash_init(grn_ctx *ctx, grn_hash *hash, const char *path, header->tokenizer = GRN_ID_NIL; if (header->flags & GRN_OBJ_KEY_NORMALIZE) { header->flags &= ~GRN_OBJ_KEY_NORMALIZE; - header->normalizer = GRN_DB_NORMALIZER_AUTO; - hash->normalizer = grn_ctx_at(ctx, header->normalizer); + hash->normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1); + header->normalizer = grn_obj_id(ctx, hash->normalizer); } else { header->normalizer = GRN_ID_NIL; hash->normalizer = NULL; @@ -1632,9 +1633,11 @@ grn_hash_open(grn_ctx *ctx, const char *path) hash->tokenizer = grn_ctx_at(ctx, header->tokenizer); if (header->flags & GRN_OBJ_KEY_NORMALIZE) { header->flags &= ~GRN_OBJ_KEY_NORMALIZE; - header->normalizer = GRN_DB_NORMALIZER_AUTO; + hash->normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1); + header->normalizer = grn_obj_id(ctx, hash->normalizer); + } else { + hash->normalizer = grn_ctx_at(ctx, header->normalizer); } - hash->normalizer = grn_ctx_at(ctx, header->normalizer); return hash; } else { GRN_LOG(ctx, GRN_LOG_NOTICE, Modified: lib/normalizer.c (+2 -3) =================================================================== --- lib/normalizer.c 2012-12-28 17:48:05 +0900 (e08aae3) +++ lib/normalizer.c 2012-12-29 14:47:54 +0900 (ecd30f0) @@ -1175,11 +1175,10 @@ grn_rc grn_db_init_builtin_normalizers(grn_ctx *ctx) { grn_rc rc; - const char *normalizer_auto_name = "NormalizerAuto"; const char *normalizer_nfkc51_name = "NormalizerNFKC51"; - rc = grn_normalizer_register(ctx, normalizer_auto_name, -1, - NULL, auto_next, NULL); + rc = grn_normalizer_register(ctx, GRN_NORMALIZER_AUTO_NAME, -1, + NULL, auto_next, NULL); if (rc == GRN_SUCCESS) { grn_obj *obj; obj = grn_ctx_get(ctx, normalizer_auto_name, -1); Modified: lib/normalizer_in.h (+2 -0) =================================================================== --- lib/normalizer_in.h 2012-12-28 17:48:05 +0900 (e3411f3) +++ lib/normalizer_in.h 2012-12-29 14:47:54 +0900 (201c789) @@ -34,6 +34,8 @@ extern "C" { #endif +#define GRN_NORMALIZER_AUTO_NAME "NormalizerAuto" + grn_rc grn_normalizer_init(void); grn_rc grn_normalizer_fin(void); Modified: lib/pat.c (+7 -4) =================================================================== --- lib/pat.c 2012-12-28 17:48:05 +0900 (8ab4e22) +++ lib/pat.c 2012-12-29 14:47:54 +0900 (cd1eb3d) @@ -20,6 +20,7 @@ #include "pat.h" #include "output.h" #include "util.h" +#include "normalizer_in.h" #define GRN_PAT_DELETED (GRN_ID_MAX + 1) @@ -425,8 +426,8 @@ _grn_pat_create(grn_ctx *ctx, grn_pat *pat, header->tokenizer = GRN_ID_NIL; if (header->flags & GRN_OBJ_KEY_NORMALIZE) { header->flags &= ~GRN_OBJ_KEY_NORMALIZE; - header->normalizer = GRN_DB_NORMALIZER_AUTO; - pat->normalizer = grn_ctx_at(ctx, header->normalizer); + pat->normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1); + header->normalizer = grn_obj_id(ctx, pat->normalizer); } else { header->normalizer = GRN_ID_NIL; pat->normalizer = NULL; @@ -528,9 +529,11 @@ grn_pat_open(grn_ctx *ctx, const char *path) pat->tokenizer = grn_ctx_at(ctx, header->tokenizer); if (header->flags & GRN_OBJ_KEY_NORMALIZE) { header->flags &= ~GRN_OBJ_KEY_NORMALIZE; - header->normalizer = GRN_DB_NORMALIZER_AUTO; + pat->normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1); + header->normalizer = grn_obj_id(ctx, pat->normalizer); + } else { + pat->normalizer = grn_ctx_at(ctx, header->normalizer); } - pat->normalizer = grn_ctx_at(ctx, header->normalizer); PAT_AT(pat, 0, node0); if (!node0) { grn_io_close(ctx, io); Modified: lib/string.c (+1 -1) =================================================================== --- lib/string.c 2012-12-28 17:48:05 +0900 (2119a70) +++ lib/string.c 2012-12-29 14:47:54 +0900 (f0fcf56) @@ -165,7 +165,7 @@ grn_string_open_(grn_ctx *ctx, const char *str, unsigned int str_len, is_normalizer_auto = (normalizer == GRN_NORMALIZER_AUTO); if (is_normalizer_auto) { - normalizer = grn_ctx_at(ctx, GRN_DB_NORMALIZER_AUTO); + normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1); } /* TODO: check rc */ -------------- next part -------------- HTML����������������������������... ダウンロード