| 1 | /* -*- c-basic-offset: 2 -*- */ |
| 2 | /* |
| 3 | Copyright(C) 2015-2016 Brazil |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License version 2.1 as published by the Free Software Foundation. |
| 8 | |
| 9 | This library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with this library; if not, write to the Free Software |
| 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include "../grn.h" |
| 22 | |
| 23 | #include "ts_buf.h" |
| 24 | #include "ts_op.h" |
| 25 | #include "ts_types.h" |
| 26 | |
| 27 | #ifdef __cplusplus |
| 28 | extern "C" { |
| 29 | #endif |
| 30 | |
| 31 | typedef enum { |
| 32 | GRN_TS_EXPR_ID_NODE, /* ID (_id). */ |
| 33 | GRN_TS_EXPR_SCORE_NODE, /* Score (_score). */ |
| 34 | GRN_TS_EXPR_KEY_NODE, /* Key (_key). */ |
| 35 | GRN_TS_EXPR_VALUE_NODE, /* Embedded value (_value). */ |
| 36 | GRN_TS_EXPR_CONST_NODE, /* Const. */ |
| 37 | GRN_TS_EXPR_COLUMN_NODE, /* Column. */ |
| 38 | GRN_TS_EXPR_OP_NODE, /* Operator. */ |
| 39 | GRN_TS_EXPR_BRIDGE_NODE /* Bridge to a subexpression. */ |
| 40 | } grn_ts_expr_node_type; |
| 41 | |
| 42 | #define GRN_TS_EXPR_NODE_COMMON_MEMBERS\ |
| 43 | grn_ts_expr_node_type type; /* Node type. */\ |
| 44 | grn_ts_data_kind data_kind; /* Abstract data type. */\ |
| 45 | grn_ts_data_type data_type; /* Detailed data type. */ |
| 46 | |
| 47 | typedef struct { |
| 48 | GRN_TS_EXPR_NODE_COMMON_MEMBERS |
| 49 | } grn_ts_expr_node; |
| 50 | |
| 51 | /* grn_ts_expr_id_node_open() creates a node associated with IDs (_id). */ |
| 52 | grn_rc grn_ts_expr_id_node_open(grn_ctx *ctx, grn_ts_expr_node **node); |
| 53 | |
| 54 | /* |
| 55 | * grn_ts_expr_score_node_open() creates a node associated with scores |
| 56 | * (_score). |
| 57 | */ |
| 58 | grn_rc grn_ts_expr_score_node_open(grn_ctx *ctx, grn_ts_expr_node **node); |
| 59 | |
| 60 | /* grn_ts_expr_key_node_open() creates a node associated with keys (_key). */ |
| 61 | grn_rc grn_ts_expr_key_node_open(grn_ctx *ctx, grn_obj *table, |
| 62 | grn_ts_expr_node **node); |
| 63 | |
| 64 | /* |
| 65 | * grn_ts_expr_value_node_open() creates a node associated with values |
| 66 | * (_value). |
| 67 | */ |
| 68 | grn_rc grn_ts_expr_value_node_open(grn_ctx *ctx, grn_obj *table, |
| 69 | grn_ts_expr_node **node); |
| 70 | |
| 71 | /* grn_ts_expr_const_node_open() creates a node associated with a const. */ |
| 72 | grn_rc grn_ts_expr_const_node_open(grn_ctx *ctx, grn_ts_data_kind data_kind, |
| 73 | grn_ts_data_type data_type, |
| 74 | grn_ts_any value, grn_ts_expr_node **node); |
| 75 | |
| 76 | /* grn_ts_expr_column_node_open() creates a node associated with a column. */ |
| 77 | grn_rc grn_ts_expr_column_node_open(grn_ctx *ctx, grn_obj *column, |
| 78 | grn_ts_expr_node **node); |
| 79 | |
| 80 | /* |
| 81 | * grn_ts_expr_op_node_open() creates a node associated with an operator. |
| 82 | * Note that argument nodes are destroyed on failure. |
| 83 | */ |
| 84 | grn_rc grn_ts_expr_op_node_open(grn_ctx *ctx, grn_ts_op_type op_type, |
| 85 | grn_ts_expr_node **args, size_t n_args, |
| 86 | grn_ts_expr_node **node); |
| 87 | |
| 88 | /* grn_ts_expr_bridge_node_open() creates a node associated with a bridge. */ |
| 89 | grn_rc grn_ts_expr_bridge_node_open(grn_ctx *ctx, grn_ts_expr_node *src, |
| 90 | grn_ts_expr_node *dest, |
| 91 | grn_ts_expr_node **node); |
| 92 | |
| 93 | /* grn_ts_expr_node_close() destroys a node. */ |
| 94 | void grn_ts_expr_node_close(grn_ctx *ctx, grn_ts_expr_node *node); |
| 95 | |
| 96 | /* |
| 97 | * grn_ts_expr_node_deref() resolves references. |
| 98 | * |
| 99 | * If *node_ptr refers to a reference node, grn_ts_expr_node_deref() creates a |
| 100 | * key node associated with the destination table and creates a bridge node |
| 101 | * from *node_ptr to the key node. If the data kind of the bridge node is |
| 102 | * GRN_TS_REF, references are recursively resolved. |
| 103 | */ |
| 104 | grn_rc grn_ts_expr_node_deref(grn_ctx *ctx, grn_ts_expr_node **node_ptr); |
| 105 | |
| 106 | /* grn_ts_expr_node_evaluate() evaluates a subtree. */ |
| 107 | grn_rc grn_ts_expr_node_evaluate(grn_ctx *ctx, grn_ts_expr_node *node, |
| 108 | const grn_ts_record *in, size_t n_in, |
| 109 | void *out); |
| 110 | |
| 111 | /* grn_ts_expr_node_evaluate_to_buf() evaluates a subtree. */ |
| 112 | grn_rc grn_ts_expr_node_evaluate_to_buf(grn_ctx *ctx, grn_ts_expr_node *node, |
| 113 | const grn_ts_record *in, size_t n_in, |
| 114 | grn_ts_buf *out); |
| 115 | |
| 116 | /* grn_ts_expr_node_filter() filters records. */ |
| 117 | grn_rc grn_ts_expr_node_filter(grn_ctx *ctx, grn_ts_expr_node *node, |
| 118 | grn_ts_record *in, size_t n_in, |
| 119 | grn_ts_record *out, size_t *n_out); |
| 120 | |
| 121 | /* grn_ts_expr_node_adjust() updates scores. */ |
| 122 | grn_rc grn_ts_expr_node_adjust(grn_ctx *ctx, grn_ts_expr_node *node, |
| 123 | grn_ts_record *io, size_t n_io); |
| 124 | |
| 125 | #ifdef __cplusplus |
| 126 | } |
| 127 | #endif |
| 128 | |
| 129 | |