Exemplo n.º 1
0
Arquivo: mrb.c Projeto: XLPE/groonga
void
grn_mrb_init_from_env(void)
{
  grn_getenv("GRN_RUBY_SCRIPTS_DIR",
             grn_mrb_ruby_scripts_dir,
             GRN_ENV_BUFFER_SIZE);
}
Exemplo n.º 2
0
void
grn_plugin_init_from_env(void)
{
  grn_getenv("GRN_PLUGINS_DIR",
             grn_plugins_dir,
             GRN_ENV_BUFFER_SIZE);
}
Exemplo n.º 3
0
static void
load_synonyms(grn_ctx *ctx)
{
  static char path_env[GRN_ENV_BUFFER_SIZE];
  const char *path;
  grn_file_reader *file_reader;
  int number_of_lines;
  grn_encoding encoding;
  grn_obj line, key, value;

  grn_getenv("GRN_QUERY_EXPANDER_TSV_SYNONYMS_FILE",
             path_env,
             GRN_ENV_BUFFER_SIZE);
  if (path_env[0]) {
    path = path_env;
  } else {
    path = get_system_synonyms_file();
  }
  file_reader = grn_file_reader_open(ctx, path);
  if (!file_reader) {
    GRN_LOG(ctx, GRN_LOG_WARNING,
            "[plugin][query-expander][tsv] "
            "synonyms file doesn't exist: <%s>",
            path);
    return;
  }

  GRN_TEXT_INIT(&line, 0);
  GRN_TEXT_INIT(&key, 0);
  GRN_TEXT_INIT(&value, 0);
  grn_bulk_reserve(ctx, &value, MAX_SYNONYM_BYTES);
  number_of_lines = 0;
  while (grn_file_reader_read_line(ctx, file_reader, &line) == GRN_SUCCESS) {
    const char *line_value = GRN_TEXT_VALUE(&line);
    size_t line_length = GRN_TEXT_LEN(&line);

    if (line_length > 0 && line_value[line_length - 1] == '\n') {
      if (line_length > 1 && line_value[line_length - 2] == '\r') {
        line_length -= 2;
      } else {
        line_length -= 1;
      }
    }
    number_of_lines++;
    if (number_of_lines == 1) {
      encoding = guess_encoding(ctx, &line_value, &line_length);
    }
    GRN_BULK_REWIND(&key);
    GRN_BULK_REWIND(&value);
    parse_synonyms_file_line(ctx, line_value, line_length, &key, &value);
    GRN_BULK_REWIND(&line);
  }
  GRN_OBJ_FIN(ctx, &line);
  GRN_OBJ_FIN(ctx, &key);
  GRN_OBJ_FIN(ctx, &value);

  grn_file_reader_close(ctx, file_reader);
}
Exemplo n.º 4
0
/*
  This function initializes a plugin. This function fails if there is no
  dictionary that uses the context encoding of groonga.
 */
grn_rc
GRN_PLUGIN_INIT(grn_ctx *ctx)
{
  {
    char env[GRN_ENV_BUFFER_SIZE];

    grn_getenv("GRN_MECAB_CHUNKED_TOKENIZE_ENABLED",
               env,
               GRN_ENV_BUFFER_SIZE);
    grn_mecab_chunked_tokenize_enabled = (env[0] && strcmp(env, "yes") == 0);
  }

  {
    char env[GRN_ENV_BUFFER_SIZE];

    grn_getenv("GRN_MECAB_CHUNK_SIZE_THRESHOLD",
               env,
               GRN_ENV_BUFFER_SIZE);
    if (env[0]) {
      int threshold = -1;
      const char *end;
      const char *rest;

      end = env + strlen(env);
      threshold = grn_atoi(env, end, &rest);
      if (end > env && end == rest) {
        grn_mecab_chunk_size_threshold = threshold;
      }
    }
  }

  sole_mecab = NULL;
  sole_mecab_mutex = grn_plugin_mutex_open(ctx);
  if (!sole_mecab_mutex) {
    GRN_PLUGIN_ERROR(ctx, GRN_NO_MEMORY_AVAILABLE,
                     "[tokenizer][mecab] grn_plugin_mutex_open() failed");
    return ctx->rc;
  }

  check_mecab_dictionary_encoding(ctx);
  return ctx->rc;
}
Exemplo n.º 5
0
void
grn_ctx_impl_mrb_init_from_env(void)
{
  {
    char grn_mruby_enabled_env[GRN_ENV_BUFFER_SIZE];
    grn_getenv("GRN_MRUBY_ENABLED",
               grn_mruby_enabled_env,
               GRN_ENV_BUFFER_SIZE);
    if (grn_mruby_enabled_env[0] &&
        strcmp(grn_mruby_enabled_env, "no") == 0) {
      grn_ctx_impl_mrb_mruby_enabled = GRN_FALSE;
    }
  }
}
Exemplo n.º 6
0
grn_rc
GRN_PLUGIN_INIT(grn_ctx *ctx)
{
  {
    char grn_ii_overlap_token_skip_enable_env[GRN_ENV_BUFFER_SIZE];
    grn_getenv("GRN_II_OVERLAP_TOKEN_SKIP_ENABLE",
               grn_ii_overlap_token_skip_enable_env,
               GRN_ENV_BUFFER_SIZE);
    if (grn_ii_overlap_token_skip_enable_env[0]) {
      grn_ii_overlap_token_skip_enable = GRN_TRUE;
    } else {
      grn_ii_overlap_token_skip_enable = GRN_FALSE;
    }
  }

  return ctx->rc;
}
Exemplo n.º 7
0
void
grn_ctx_impl_mrb_init(grn_ctx *ctx)
{
  char grn_mruby_enabled[GRN_ENV_BUFFER_SIZE];
  grn_getenv("GRN_MRUBY_ENABLED",
             grn_mruby_enabled,
             GRN_ENV_BUFFER_SIZE);
  if (grn_mruby_enabled[0] && strcmp(grn_mruby_enabled, "no") == 0) {
    ctx->impl->mrb.state = NULL;
    ctx->impl->mrb.base_directory[0] = '\0';
    ctx->impl->mrb.module = NULL;
    ctx->impl->mrb.object_class = NULL;
    ctx->impl->mrb.checked_procs = NULL;
    ctx->impl->mrb.registered_plugins = NULL;
    ctx->impl->mrb.builtin.time_class = NULL;
    ctx->impl->mrb.groonga.operator_class = NULL;
  } else {
    mrb_state *mrb;

    mrb = mrb_open();
    ctx->impl->mrb.state = mrb;
    ctx->impl->mrb.base_directory[0] = '\0';
    grn_ctx_impl_mrb_init_bindings(ctx);
    /* TODO: Implement better error handling on init. */
    if (ctx->impl->mrb.state->exc) {
      mrb_print_error(mrb);
    }
    ctx->impl->mrb.checked_procs =
      grn_hash_create(ctx, NULL, sizeof(grn_id), 0, GRN_HASH_TINY);
    ctx->impl->mrb.registered_plugins =
      grn_hash_create(ctx, NULL, sizeof(grn_id), 0, GRN_HASH_TINY);
    GRN_VOID_INIT(&(ctx->impl->mrb.buffer.from));
    GRN_VOID_INIT(&(ctx->impl->mrb.buffer.to));
    ctx->impl->mrb.builtin.time_class = mrb_class_get(mrb, "Time");
  }
}
Exemplo n.º 8
0
static void
grn_init_from_env(void)
{
  {
    char grn_ctx_per_db_env[GRN_ENV_BUFFER_SIZE];
    grn_getenv("GRN_CTX_PER_DB",
               grn_ctx_per_db_env,
               GRN_ENV_BUFFER_SIZE);
    if (grn_ctx_per_db_env[0] && strcmp(grn_ctx_per_db_env, "yes") == 0) {
      grn_ctx_per_db = GRN_TRUE;
    }
  }

  grn_alloc_init_from_env();
  grn_mrb_init_from_env();
  grn_ctx_impl_mrb_init_from_env();
  grn_io_init_from_env();
  grn_ii_init_from_env();
  grn_db_init_from_env();
  grn_expr_init_from_env();
  grn_index_column_init_from_env();
  grn_proc_init_from_env();
  grn_plugin_init_from_env();
}