43 unsigned int term_len,
54 #define VAR GRN_PROC_GET_VAR_BY_OFFSET
56 #define GRN_SELECT_INTERNAL_VAR_CONDITION "$condition"
57 #define GRN_SELECT_INTERNAL_VAR_MATCH_COLUMNS "$match_columns"
61 grn_bulk_put_from_file(
grn_ctx *ctx,
grn_obj *bulk,
const char *path)
77 "symbolic link is not allowed: <%s>", path);
86 if (fstat(fd, &stat) != -1) {
88 off_t rest = stat.st_size;
91 for (bp = buf; rest; rest -= ss, bp += ss) {
92 if ((ss =
GRN_READ(fd, bp, rest)) == -1) {
goto exit; }
113 substitute_term_by_func(
grn_ctx *ctx,
const char *term,
unsigned int term_len,
141 substitute_term_by_column(
grn_ctx *ctx,
const char *term,
unsigned int term_len,
160 for (i = 0; i < n; i++) {
182 substitute_terms(
grn_ctx *ctx,
const char *query,
unsigned int query_len,
190 const char *start, *cur = query, *query_end = query + (size_t)query_len;
194 if (!(len =
grn_charlen(ctx, cur, query_end))) {
goto exit; }
198 if (query_end <= cur) {
break; }
216 for (start = cur++; cur < query_end; cur += len) {
219 }
else if (len == 1) {
231 expanded_query, user_data)) {
236 if (cur + 2 <= query_end && cur[1] ==
'R' &&
244 for (start = cur; cur < query_end; cur += len) {
249 }
else if (len == 1) {
255 if (cur + 1 < query_end) {
268 cur += (cur + 2 < query_end && cur[2] ==
'=') ? 3 : 2;
284 if (substitute_term_func(ctx, start, cur - start,
285 expanded_query, user_data)) {
298 expand_query(
grn_ctx *ctx,
const char *query,
unsigned int query_len,
300 const char *query_expander_name,
301 unsigned int query_expander_name_len,
308 query_expander_name, query_expander_name_len);
309 if (!query_expander) {
311 "nonexistent query expansion column: <%.*s>",
312 query_expander_name_len, query_expander_name);
320 user_data.
ptr = query_expander;
321 substitute_terms(ctx, query, query_len, flags, expanded_query,
322 substitute_term_by_func, &user_data);
326 "[expand-query] must be function proc: <%.*s>",
327 query_expander_name_len, query_expander_name);
333 grn_obj *query_expansion_table;
335 if (query_expansion_table) {
338 user_data.
ptr = &data;
339 data.
table = query_expansion_table;
340 data.
column = query_expander;
341 substitute_terms(ctx, query, query_len, flags, expanded_query,
342 substitute_term_by_column, &user_data);
347 "[expand-query] failed to get table of column: <%.*s>",
348 query_expander_name_len, query_expander_name);
359 "[expand-query] must be a column or function proc: <%.*s>(%.*s)",
360 query_expander_name_len, query_expander_name,
374 #define DEFAULT_LIMIT 10
375 #define DEFAULT_OUTPUT_COLUMNS "_id, _key, *"
376 #define DEFAULT_DRILLDOWN_LIMIT 10
377 #define DEFAULT_DRILLDOWN_OUTPUT_COLUMNS "_key, _nsubrecs"
378 #define DUMP_COLUMNS "_id, _key, _value, *"
381 grn_parse_query_flags(
grn_ctx *ctx,
const char *query_flags,
382 unsigned int query_flags_len)
385 const char *query_flags_end = query_flags + query_flags_len;
387 while (query_flags < query_flags_end) {
388 if (*query_flags ==
'|' || *query_flags ==
' ') {
393 #define CHECK_EXPR_FLAG(name)\
394 if (((query_flags_end - query_flags) >= (sizeof(#name) - 1)) &&\
395 (!memcmp(query_flags, #name, sizeof(#name) - 1))) {\
396 flags |= GRN_EXPR_ ## name;\
397 query_flags += sizeof(#name);\
406 #define GRN_EXPR_NONE 0
411 (
int)(query_flags_end - query_flags), query_flags);
413 #undef CHECK_EXPR_FLAG
420 is_output_columns_format_v1(
grn_ctx *ctx,
421 const char *output_columns,
422 unsigned int output_columns_len)
432 for (i = 0; i < output_columns_len; i++) {
433 switch (output_columns[i]) {
447 const char *match_columns,
unsigned int match_columns_len,
448 const char *query,
unsigned int query_len,
449 const char *filter,
unsigned int filter_len,
450 const char *scorer,
unsigned int scorer_len,
451 const char *sortby,
unsigned int sortby_len,
452 const char *output_columns,
unsigned int output_columns_len,
453 int offset,
int limit,
454 const char *drilldown,
unsigned int drilldown_len,
455 const char *drilldown_sortby,
unsigned int drilldown_sortby_len,
456 const char *drilldown_output_columns,
unsigned int drilldown_output_columns_len,
457 int drilldown_offset,
int drilldown_limit,
458 const char *cache,
unsigned int cache_len,
459 const char *match_escalation_threshold,
unsigned int match_escalation_threshold_len,
460 const char *query_expander,
unsigned int query_expander_len,
461 const char *query_flags,
unsigned int query_flags_len)
463 uint32_t nkeys, nhits;
464 uint16_t cacheable = 1, taintable = 0;
469 grn_obj *table_, *match_columns_ = NULL, *cond = NULL, *scorer_, *res = NULL, *sorted;
471 uint32_t cache_key_size = table_len + 1 + match_columns_len + 1 + query_len + 1 +
472 filter_len + 1 + scorer_len + 1 + sortby_len + 1 + output_columns_len + 1 +
473 drilldown_len + 1 + drilldown_sortby_len + 1 +
474 drilldown_output_columns_len + 1 + match_escalation_threshold_len + 1 +
475 query_expander_len + 1 + query_flags_len + 1 +
477 long long int threshold, original_threshold = 0;
481 char *cp = cache_key;
482 memcpy(cp, table, table_len);
483 cp += table_len; *cp++ =
'\0';
484 memcpy(cp, match_columns, match_columns_len);
485 cp += match_columns_len; *cp++ =
'\0';
486 memcpy(cp, query, query_len);
487 cp += query_len; *cp++ =
'\0';
488 memcpy(cp, filter, filter_len);
489 cp += filter_len; *cp++ =
'\0';
490 memcpy(cp, scorer, scorer_len);
491 cp += scorer_len; *cp++ =
'\0';
492 memcpy(cp, sortby, sortby_len);
493 cp += sortby_len; *cp++ =
'\0';
494 memcpy(cp, output_columns, output_columns_len);
495 cp += output_columns_len; *cp++ =
'\0';
496 memcpy(cp, drilldown, drilldown_len);
497 cp += drilldown_len; *cp++ =
'\0';
498 memcpy(cp, drilldown_sortby, drilldown_sortby_len);
499 cp += drilldown_sortby_len; *cp++ =
'\0';
500 memcpy(cp, drilldown_output_columns, drilldown_output_columns_len);
501 cp += drilldown_output_columns_len; *cp++ =
'\0';
502 memcpy(cp, match_escalation_threshold, match_escalation_threshold_len);
503 cp += match_escalation_threshold_len; *cp++ =
'\0';
504 memcpy(cp, query_expander, query_expander_len);
505 cp += query_expander_len; *cp++ =
'\0';
506 memcpy(cp, query_flags, query_flags_len);
507 cp += query_flags_len; *cp++ =
'\0';
509 memcpy(cp, &offset,
sizeof(
int)); cp +=
sizeof(int);
510 memcpy(cp, &limit,
sizeof(
int)); cp +=
sizeof(int);
511 memcpy(cp, &drilldown_offset,
sizeof(
int)); cp +=
sizeof(int);
512 memcpy(cp, &drilldown_limit,
sizeof(
int)); cp +=
sizeof(int);
513 cache_value =
grn_cache_fetch(ctx, cache_obj, cache_key, cache_key_size);
525 if (match_escalation_threshold_len) {
526 const char *end, *rest;
528 end = match_escalation_threshold + match_escalation_threshold_len;
529 threshold =
grn_atoll(match_escalation_threshold, end, &rest);
534 if ((table_ =
grn_ctx_get(ctx, table, table_len))) {
536 if (query_len || filter_len) {
540 if (match_columns_len) {
542 if (match_columns_) {
543 grn_expr_parse(ctx, match_columns_, match_columns, match_columns_len,
555 if (query_flags_len) {
556 flags |= grn_parse_query_flags(ctx, query_flags, query_flags_len);
563 if (query_expander_len) {
564 if (expand_query(ctx, query, query_len, flags,
565 query_expander, query_expander_len,
577 if (!ctx->
rc && filter_len) {
588 cacheable *= ((
grn_expr *)cond)->cacheable;
589 taintable += ((
grn_expr *)cond)->taintable;
608 ":",
"select(%d)", nhits);
614 if (!ctx->
rc && drilldown_len) {
616 drilldown, drilldown_len,
619 result_size += ngkeys;
624 if (scorer && scorer_len) {
631 cacheable *= ((
grn_expr *)scorer_)->cacheable;
632 taintable += ((
grn_expr *)scorer_)->taintable;
644 ":",
"score(%d)", nhits);
655 ":",
"sort(%d)", limit);
660 if (is_output_columns_format_v1(ctx, output_columns, output_columns_len)) {
668 output_columns, output_columns_len, NULL,
689 if (is_output_columns_format_v1(ctx, output_columns, output_columns_len)) {
697 output_columns, output_columns_len, NULL,
712 ":",
"output(%d)", limit);
713 if (!ctx->
rc && drilldown_len) {
717 for (i = 0; i < ngkeys; i++) {
719 gkeys[i].key, res, 0))) {
720 int n_drilldown_offset = drilldown_offset,
721 n_drilldown_limit = drilldown_limit;
727 &n_drilldown_offset, &n_drilldown_limit);
729 if (drilldown_sortby_len) {
731 drilldown_sortby, drilldown_sortby_len,
736 sorted, keys, nkeys);
738 n_drilldown_limit, n_drilldown_offset);
743 drilldown_output_columns, drilldown_output_columns_len,
753 n_drilldown_limit, n_drilldown_offset);
758 drilldown_output_columns_len, &format.
columns);
765 ":",
"drilldown(%d)", nhits);
776 && (!cache || cache_len != 2 || *cache !=
'n' || *(cache + 1) !=
'o')) {
785 if (match_escalation_threshold_len) {
788 if (match_columns_) {
820 query_expander = query_expansion;
822 if (!output_columns_len) {
826 if (!drilldown_output_columns_len) {
836 output_columns, output_columns_len,
840 drilldown_output_columns, drilldown_output_columns_len,
841 drilldown_offset, drilldown_limit,
856 for (i = 1; i < nvars; i++) {
913 double cache_hit_rate;
914 cache_hit_rate = (double)statistics.
nhits / (
double)statistics.
nfetches;
928 grn_parse_table_create_flags(
grn_ctx *ctx,
const char *nptr,
const char *end)
932 if (*nptr ==
'|' || *nptr ==
' ') {
936 if (!memcmp(nptr,
"TABLE_HASH_KEY", 14)) {
939 }
else if (!memcmp(nptr,
"TABLE_PAT_KEY", 13)) {
942 }
else if (!memcmp(nptr,
"TABLE_DAT_KEY", 13)) {
945 }
else if (!memcmp(nptr,
"TABLE_NO_KEY", 12)) {
948 }
else if (!memcmp(nptr,
"KEY_NORMALIZE", 13)) {
951 }
else if (!memcmp(nptr,
"KEY_WITH_SIS", 12)) {
956 (
int)(end - nptr), nptr);
964 grn_parse_column_create_flags(
grn_ctx *ctx,
const char *nptr,
const char *end)
968 if (*nptr ==
'|' || *nptr ==
' ') {
972 if (!memcmp(nptr,
"COLUMN_SCALAR", 13)) {
975 }
else if (!memcmp(nptr,
"COLUMN_VECTOR", 13)) {
978 }
else if (!memcmp(nptr,
"COLUMN_INDEX", 12)) {
981 }
else if (!memcmp(nptr,
"WITH_SECTION", 12)) {
984 }
else if (!memcmp(nptr,
"WITH_WEIGHT", 11)) {
987 }
else if (!memcmp(nptr,
"WITH_POSITION", 13)) {
990 }
else if (!memcmp(nptr,
"RING_BUFFER", 11)) {
995 (
int)(end - nptr), nptr);
1080 if (ctx->
rc) {
goto exit; }
1083 grn_obj *key_type = NULL, *value_type = NULL;
1089 "[table][create] key type doesn't exist: <%.*s> (%.*s)",
1100 "[table][create] value type doesn't exist: <%.*s> (%.*s)",
1119 normalizer_name =
VAR(5);
1131 "[table][create] should not create anonymous table");
1160 ERR(rc,
"[table][rename] table name isn't specified");
1167 "[table][rename] table isn't found: <%.*s>",
1174 "[table][rename] new table name isn't specified: <%.*s>",
1182 "[table][rename] failed to rename: <%.*s> -> <%.*s>",
1202 if (ctx->
rc) {
goto exit; }
1207 "[column][create] table doesn't exist: <%.*s>",
1215 "[column][create] type doesn't exist: <%.*s>",
1231 grn_obj sources, source_ids, **p, **pe;
1240 for (; p < pe; p++) {
1271 unsigned int colname_len,fullname_len;
1281 memcpy((fullname + fullname_len + 1), colname, colname_len);
1282 fullname_len += colname_len + 1;
1305 ERR(rc,
"[column][rename] table name isn't specified");
1312 "[column][rename] table isn't found: <%.*s>",
1319 "[column][rename] column name isn't specified: <%.*s>",
1328 "[column][rename] column isn't found: <%.*s.%.*s>",
1336 "[column][rename] new column name isn't specified: <%.*s.%.*s>",
1345 "[column][rename] failed to rename: <%.*s.%.*s> -> <%.*s.%.*s>",
1358 #define GRN_STRLEN(s) ((s) ? strlen(s) : 0)
1403 output_object_name(ctx, obj);
1433 output_column_name(ctx, column);
1436 grn_column_create_flags_to_text(ctx, &o, column->
header.
flags);
1445 for (i = 0; i < n; i++, s++) {
1446 output_object_id_name(ctx, *s);
1465 int column_list_size = -1;
1466 #ifdef GRN_WITH_MESSAGE_PACK
1467 column_list_size = 1;
1528 grn_column_create_flags_to_text(ctx, &buf, 0);
1543 output_column_info(ctx, col);
1588 output_object_id_name(ctx,
id);
1590 grn_table_create_flags_to_text(ctx, &o, table->
header.
flags);
1596 output_object_name(ctx, default_tokenizer);
1598 output_object_name(ctx, normalizer);
1610 int n_top_level_elements;
1611 int n_elements_for_header = 1;
1622 if (is_table(
object)) {
1637 n_top_level_elements = n_elements_for_header + n_tables;
1675 for (i = 0; i < n_tables; i++) {
1677 output_table_info(ctx, table);
1692 static int grn_document_root_len = -1;
1694 if (grn_document_root_len < 0) {
1699 grn_document_root_len = (int)l;
1705 path[grn_document_root_len] =
'/';
1709 path + grn_document_root_len + 1,
1710 PATH_MAX - grn_document_root_len - 1);
1711 grn_bulk_put_from_file(ctx, outbuf, path);
1713 uint32_t abbrlen = 32;
1715 "too long path name: <%s/%.*s...> %u(%u)",
1718 plen + grn_document_root_len,
PATH_MAX);
1743 int target_name_len;
1747 target_name =
VAR(0);
1750 if (target_name_len) {
1770 int olen, threshold;
1792 static char slev[] =
" EACewnid-";
1841 "[table][record][delete] table doesn't exist: <%.*s>",
1851 "[table][record][delete] either key, id or filter must be specified: "
1860 "[table][record][delete] "
1861 "record selector must be one of key, id and filter: "
1862 "table: <%.*s>, key: <%.*s>, id: <%.*s>, filter: <%.*s>",
1873 "[table][record][delete] "
1874 "can't use both key and id: table: <%.*s>, key: <%.*s>, id: <%.*s>",
1884 "[table][record][delete] "
1885 "can't use both key and filter: "
1886 "table: <%.*s>, key: <%.*s>, filter: <%.*s>",
1896 "[table][record][delete] "
1897 "can't use both id and filter: "
1898 "table: <%.*s>, id: <%.*s>, filter: <%.*s>",
1920 ERR(rc,
"[table][record][delete] table name isn't specified");
1927 rc = proc_delete_validate_selector(ctx, table, table_name, key,
id, filter);
1941 if (key == &casted_key) {
1953 "[table][record][delete] id should be number: "
1954 "table: <%.*s>, id: <%.*s>, detail: <%.*s|%c|%.*s>",
1972 strcpy(original_error_message, ctx->
errbuf);
1975 "[table][record][delete] failed to parse filter: "
1976 "table: <%.*s>, filter: <%.*s>, detail: <%s>",
1979 original_error_message);
1987 result_id, &key, NULL, NULL, {
2009 dump_name(
grn_ctx *ctx,
grn_obj *outbuf,
const char *name,
int name_len)
2031 dump_name(ctx, outbuf, name, name_len);
2040 dump_name(ctx, outbuf, name, name_len);
2058 for (i = 0; i < n; i++) {
2060 if ((source =
grn_ctx_at(ctx, *source_ids))) {
2069 dump_column_name(ctx, outbuf, source);
2092 dump_obj_name(ctx, outbuf, table);
2094 dump_column_name(ctx, outbuf, column);
2100 grn_column_create_flags_to_text(ctx, &buf, column->
header.
flags & ~default_flags);
2104 dump_obj_name(ctx, outbuf, type);
2106 dump_index_column_sources(ctx, outbuf, column);
2152 if (reference_column_p(ctx, column)) {
2155 dump_column(ctx, outbuf, table, column);
2170 int i, ncolumns, n_use_columns;
2171 grn_obj columnbuf, delete_commands, use_columns, column_name;
2190 dump_obj_name(ctx, outbuf, table);
2200 for (i = 0; i < ncolumns; i++) {
2221 for (i = 0; i < n_use_columns; i++) {
2235 int is_value_column;
2241 for (current_id = old_id + 1; current_id < id; current_id++) {
2244 dump_obj_name(ctx, &delete_commands, table);
2251 for (j = 0; j < n_use_columns; j++) {
2259 is_value_column = 1;
2261 is_value_column = 0;
2269 switch (column->
header.
flags & GRN_OBJ_COLUMN_TYPE_MASK) {
2300 "unsupported column type: %#x",
2312 if (is_value_column) {
2321 "unsupported header type %#x",
2336 for (i = 0; i < ncolumns; i++) {
2346 grn_obj *domain = NULL, *range = NULL;
2363 dump_obj_name(ctx, outbuf, table);
2366 grn_table_create_flags_to_text(ctx, &buf, table->
header.
flags & ~default_flags);
2371 dump_obj_name(ctx, outbuf, domain);
2384 dump_obj_name(ctx, outbuf, range);
2389 if (default_tokenizer) {
2391 dump_obj_name(ctx, outbuf, default_tokenizer);
2396 dump_obj_name(ctx, outbuf, normalizer);
2405 dump_columns(ctx, outbuf, table, pending_columns);
2409 #define GRN_PTR_POP(obj,value) do {\
2410 if (GRN_BULK_VSIZE(obj) >= sizeof(grn_obj *)) {\
2411 GRN_BULK_INCR_LEN((obj), -(sizeof(grn_obj *)));\
2412 value = *(grn_obj **)(GRN_BULK_CURR(obj));\
2438 dump_table(ctx, outbuf,
object, &pending_columns);
2461 dump_column(ctx, outbuf, table, column);
2479 const char *token, *token_e;
2487 if (!((
'a' <= *p && *p <=
'z') ||
2488 (
'A' <= *p && *p <=
'Z') ||
2494 (
int)(p - token), token);
2498 ((
'a' <= *p && *p <=
'z') ||
2499 (
'A' <= *p && *p <=
'Z') ||
2500 (
'0' <= *p && *p <=
'9') ||
2509 if (p < e && *p ==
',') {
2513 if ((table =
grn_ctx_get(ctx, token, token_e - token))) {
2514 dump_records(ctx, outbuf, table);
2518 "nonexistent table name is ignored: <%.*s>\n",
2519 (
int)(token_e - token), token);
2537 dump_records(ctx, outbuf, table);
2557 dump_schema(ctx, outbuf);
2562 dump_selected_tables_records(ctx, outbuf,
VAR(0));
2564 dump_all_records(ctx, outbuf);
2580 unsigned int current_max_n_entries;
2592 "max value is invalid unsigned integer format: <%.*s>",
2653 uint32_t
i, j, g =0, a = 0,
b = 0;
2658 if (j > max) { max = j; }
2663 if (j > max) { max = j; }
2670 if (j > max) { max = j; }
2696 for (max = 0, i = 0; i < (GRN_II_MAX_CHUNK >> 3); i++) {
2697 if ((j = h->
chunks[i])) {
2699 for (k = 0; k < 8; k++) {
2700 if ((j & (1 << k))) { max = (i << 3) + j; }
2729 if (table_name_len == 0) {
2736 "no such table: <%.*s>", table_name_len, table_name);
2751 "not a table object: %.*s",
2767 const char *names, *names_end;
2772 names_end = names + length;
2773 while (names < names_end) {
2774 if (*names ==
'|' || *names ==
' ') {
2779 #define CHECK_FLAG(name)\
2780 if (((names_end - names) >= (sizeof(#name) - 1)) &&\
2781 (!memcmp(names, #name, sizeof(#name) - 1))) {\
2782 flags |= GRN_STRING_ ## name;\
2783 names += sizeof(#name);\
2792 #define GRN_STRING_NONE 0
2794 #undef GRN_STRING_NONE
2797 (
int)(names_end - names), names);
2808 const char *name =
"unknown";
2847 normalizer_name =
VAR(0);
2849 flag_names =
VAR(2);
2860 unsigned int normalized_n_characters;
2862 flags = parse_normalize_flags(ctx, flag_names);
2868 "unknown normalizer: <%.*s>",
2882 const char *normalized;
2883 unsigned int normalized_length_in_bytes;
2887 &normalized_length_in_bytes,
2888 &normalized_n_characters);
2893 const unsigned char *types;
2900 for (i = 0; i < normalized_n_characters; i++) {
2920 unsigned int flags = 0;
2921 const char *names, *names_end;
2926 names_end = names + length;
2927 while (names < names_end) {
2928 if (*names ==
'|' || *names ==
' ') {
2933 #define CHECK_FLAG(name)\
2934 if (((names_end - names) >= (sizeof(#name) - 1)) &&\
2935 (!memcmp(names, #name, sizeof(#name) - 1))) {\
2936 flags |= GRN_TOKEN_ ## name;\
2937 names += sizeof(#name);\
2943 #define GRN_TOKEN_NONE 0
2945 #undef GRN_TOKEN_NONE
2948 (
int)(names_end - names), names);
2964 int i, n_tokens = 0;
2971 for (i = 0; i < n_tokens; i++) {
2974 unsigned int value_size;
2994 create_lexicon_for_tokenize(
grn_ctx *ctx,
3007 "[tokenize] unknown tokenizer: <%.*s>",
3020 "[tokenize] unknown normalizer: <%.*s>",
3062 current_token->
id = token_id;
3076 tokenizer_name =
VAR(0);
3078 normalizer_name =
VAR(2);
3079 flag_names =
VAR(3);
3083 output_tokens(ctx, NULL, NULL);
3089 output_tokens(ctx, NULL, NULL);
3098 flags = parse_tokenize_flags(ctx, flag_names);
3100 output_tokens(ctx, NULL, NULL);
3104 lexicon = create_lexicon_for_tokenize(ctx, tokenizer_name, normalizer_name);
3106 output_tokens(ctx, NULL, NULL);
3111 tokenize(ctx, lexicon,
string, flags, &tokens);
3112 output_tokens(ctx, &tokens, lexicon);
3128 val = (int) (1.0 * max * rand() / (RAND_MAX + 1.0));
3149 is_comparable_number_type(
grn_id type)
3157 if (type1 == type2) {
3171 if (type2 > type1) {
3182 if (type1 == type2) {
3197 grn_id smaller_number_type;
3198 if (type2 > type1) {
3199 smaller_number_type = type2;
3201 smaller_number_type = type1;
3203 switch (smaller_number_type) {
3213 return smaller_number_type;
3220 is_negative_value(
grn_obj *number)
3251 if (is_negative_value(src)) {
3256 if (is_negative_value(src)) {
3261 if (is_negative_value(src)) {
3266 if (is_negative_value(src)) {
3278 #define COMPARE_AND_RETURN(type, value1, value2)\
3280 type computed_value1 = value1;\
3281 type computed_value2 = value2;\
3282 if (computed_value1 > computed_value2) {\
3284 } else if (computed_value1 < computed_value2) {\
3336 #undef COMPARE_AND_RETURN
3344 grn_obj casted_max, casted_number;
3354 for (i = 0; i < nargs; i++) {
3357 if (!is_comparable_number_type(domain)) {
3360 cast_type = larger_number_type(cast_type, domain);
3361 if (!number_safe_cast(ctx, number, &casted_number, cast_type)) {
3373 if (!number_safe_cast(ctx, max, &casted_max, cast_type)) {
3381 if (compare_number(ctx, &casted_number, max, cast_type) > 0) {
3399 grn_obj casted_min, casted_number;
3409 for (i = 0; i < nargs; i++) {
3412 if (!is_comparable_number_type(domain)) {
3415 cast_type = smaller_number_type(cast_type, domain);
3416 if (!number_safe_cast(ctx, number, &casted_number, cast_type)) {
3428 if (!number_safe_cast(ctx, min, &casted_min, cast_type)) {
3436 if (compare_number(ctx, &casted_number, min, cast_type) < 0) {
3541 #define DIST(ox,oy) (dists[((lx + 1) * (oy)) + (ox)])
3549 uint32_t cx, lx, cy, ly, *dists;
3552 for (px = sx, lx = 0; px < ex && (cx =
grn_charlen(ctx, px, ex)); px += cx, lx++);
3553 for (py = sy, ly = 0; py < ey && (cy =
grn_charlen(ctx, py, ey)); py += cy, ly++);
3554 if ((dists =
GRN_MALLOC((lx + 1) * (ly + 1) *
sizeof(uint32_t)))) {
3556 for (x = 0; x <= lx; x++) {
DIST(x, 0) = x; }
3557 for (y = 0; y <= ly; y++) {
DIST(0, y) = y; }
3558 for (x = 1, px = sx; x <= lx; x++, px += cx) {
3560 for (y = 1, py = sy; y <= ly; y++, py += cy) {
3562 if (cx == cy && !memcmp(px, py, cx)) {
3565 uint32_t a =
DIST(x - 1, y) + 1;
3566 uint32_t
b =
DIST(x, y - 1) + 1;
3567 uint32_t c =
DIST(x - 1, y - 1) + 1;
3568 DIST(x, y) = ((a <
b) ? ((a < c) ? a : c) : ((b < c) ? b : c));
3629 grn_obj *condition_ptr = NULL;
3633 unsigned int width = 200;
3634 unsigned int max_n_results = 3;
3635 unsigned int n_tags = 1;
3636 const char *open_tags[] = {
"<span class=\"keyword\">"};
3637 unsigned int open_tag_lengths[1];
3638 const char *close_tags[] = {
"</span>"};
3639 unsigned int close_tag_lengths[1];
3642 open_tag_lengths[0] = strlen(open_tags[0]);
3643 close_tag_lengths[0] = strlen(close_tags[0]);
3649 if (condition_ptr) {
3655 width, max_n_results, n_tags,
3656 open_tags, open_tag_lengths,
3657 close_tags, close_tag_lengths,
3663 unsigned int i, n_results, max_tagged_length;
3668 &n_results, &max_tagged_length);
3671 for (i = 0; i < n_results; i++) {
3672 unsigned int snippet_length;
3696 grn_obj *match_columns_string;
3698 grn_obj *query_expander_name = NULL;
3699 grn_obj *match_columns = NULL;
3704 if (!(2 <= nargs && nargs <= 3)) {
3706 "wrong number of arguments (%d for 2..3)", nargs);
3711 match_columns_string = args[0];
3714 query_expander_name = args[2];
3720 if (!match_columns) {
3737 const char *query_string;
3738 unsigned int query_string_len;
3753 if (query_expander_name &&
3756 rc = expand_query(ctx, query_string, query_string_len, flags,
3781 if (match_columns) {
3828 unsigned int key_size;
3831 key_size = ((
grn_hash *)res)->key_size;
3856 return run_query(ctx, table, nargs - 1, args + 1, res, op);
3869 grn_obj *dummy_variable = NULL;
3873 "sub_filter(): wrong number of arguments (%d for 2)", nargs);
3879 sub_filter_string = args[1];
3889 "sub_filter(): the 1nd argument must be column or accessor");
3900 "sub_filter(): the 2nd argument must be String");
3906 "sub_filter(): the 2nd argument must not be empty String");
3932 scope_domain, NULL);
3939 accessor.
obj = scope;
3941 accessor.
next = NULL;
3996 unsigned int key_size;
3999 key_size = ((
grn_hash *)res)->key_size;
4024 return run_sub_filter(ctx, table, nargs - 1, args + 1, res, op);
4032 int html_arg_domain;
4035 const char *html_raw;
4046 switch (html_arg_domain) {
4076 for (i = 0; i < length; i++) {
4077 switch (html_raw[i]) {
4101 #define DEF_VAR(v,name_str) do {\
4102 (v).name = (name_str);\
4103 (v).name_size = GRN_STRLEN(name_str);\
4104 GRN_TEXT_INIT(&(v).value, 0);\
4107 #define DEF_COMMAND(name, func, nvars, vars)\
4108 (grn_proc_create(ctx, (name), (sizeof(name) - 1),\
4109 GRN_PROC_COMMAND, (func), NULL, NULL, (nvars), (vars)))
4118 DEF_VAR(vars[2],
"match_columns");
4123 DEF_VAR(vars[7],
"output_columns");
4126 DEF_VAR(vars[10],
"drilldown");
4127 DEF_VAR(vars[11],
"drilldown_sortby");
4128 DEF_VAR(vars[12],
"drilldown_output_columns");
4129 DEF_VAR(vars[13],
"drilldown_offset");
4130 DEF_VAR(vars[14],
"drilldown_limit");
4132 DEF_VAR(vars[16],
"match_escalation_threshold");
4134 DEF_VAR(vars[17],
"query_expansion");
4135 DEF_VAR(vars[18],
"query_flags");
4136 DEF_VAR(vars[19],
"query_expander");
4137 DEF_COMMAND(
"define_selector", proc_define_selector, 20, vars);
4144 DEF_VAR(vars[4],
"input_type");
4150 DEF_COMMAND(
"table_list", proc_table_list, 0, vars);
4153 DEF_COMMAND(
"column_list", proc_column_list, 1, vars);
4158 DEF_VAR(vars[3],
"value_type");
4159 DEF_VAR(vars[4],
"default_tokenizer");
4160 DEF_VAR(vars[5],
"normalizer");
4161 DEF_COMMAND(
"table_create", proc_table_create, 6, vars);
4164 DEF_COMMAND(
"table_remove", proc_table_remove, 1, vars);
4168 DEF_COMMAND(
"table_rename", proc_table_rename, 2, vars);
4175 DEF_COMMAND(
"column_create", proc_column_create, 5, vars);
4179 DEF_COMMAND(
"column_remove", proc_column_remove, 2, vars);
4184 DEF_COMMAND(
"column_rename", proc_column_rename, 3, vars);
4193 DEF_VAR(vars[0],
"target_name");
4194 DEF_COMMAND(
"clearlock", proc_clearlock, 1, vars);
4196 DEF_VAR(vars[0],
"target_name");
4197 DEF_VAR(vars[1],
"threshold");
4201 DEF_COMMAND(
"log_level", proc_log_level, 1, vars);
4207 DEF_COMMAND(
"log_reopen", proc_log_reopen, 0, vars);
4216 DEF_COMMAND(
"cache_limit", proc_cache_limit, 1, vars);
4230 DEF_VAR(vars[0],
"normalizer");
4233 DEF_COMMAND(
"normalize", proc_normalize, 3, vars);
4235 DEF_VAR(vars[0],
"tokenizer");
4237 DEF_VAR(vars[2],
"normalizer");
4243 NULL, NULL, 0, vars);
4246 NULL, NULL, 0, vars);
4249 NULL, NULL, 0, vars);
4251 NULL, NULL, 0, vars);
4257 func_geo_in_circle, NULL, NULL, 0, NULL);
4262 func_geo_in_rectangle, NULL, NULL, 0, NULL);
4267 func_geo_distance, NULL, NULL, 0, NULL);
4271 func_geo_distance2, NULL, NULL, 0, NULL);
4275 func_geo_distance3, NULL, NULL, 0, NULL);
4278 func_edit_distance, NULL, NULL, 0, NULL);
4284 func_all_records, NULL, NULL, 0, NULL);
4290 func_snippet_html, NULL, NULL, 0, NULL);
4296 func_query, NULL, NULL, 0, NULL);
4304 func_sub_filter, NULL, NULL, 0, NULL);
4309 func_html_untag, NULL, NULL, 0, NULL);