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_expr_node.h" |
25 | #include "ts_str.h" |
26 | #include "ts_types.h" |
27 | |
28 | #ifdef __cplusplus |
29 | extern "C" { |
30 | #endif |
31 | |
32 | /*------------------------------------------------------------- |
33 | * Enumeration types. |
34 | */ |
35 | |
36 | typedef enum { |
37 | GRN_TS_EXPR_ID, /* IDs (_id). */ |
38 | GRN_TS_EXPR_SCORE, /* Scores (_score). */ |
39 | GRN_TS_EXPR_CONST, /* A const. */ |
40 | GRN_TS_EXPR_VARIABLE /* An expression that contains a variable. */ |
41 | } grn_ts_expr_type; |
42 | |
43 | /*------------------------------------------------------------- |
44 | * Expression components. |
45 | */ |
46 | |
47 | typedef struct { |
48 | grn_obj *table; /* Associated table. */ |
49 | grn_ts_expr_type type; /* Expression type. */ |
50 | grn_ts_data_kind data_kind; /* Abstract data type. */ |
51 | grn_ts_data_type data_type; /* Detailed data type. */ |
52 | grn_ts_expr_node *root; /* Root node. */ |
53 | } grn_ts_expr; |
54 | |
55 | /* grn_ts_expr_open() creates an expression. */ |
56 | grn_rc grn_ts_expr_open(grn_ctx *ctx, grn_obj *table, grn_ts_expr_node *root, |
57 | grn_ts_expr **expr); |
58 | |
59 | /* grn_ts_expr_parse() parses a string and creates an expression. */ |
60 | grn_rc grn_ts_expr_parse(grn_ctx *ctx, grn_obj *table, grn_ts_str str, |
61 | grn_ts_expr **expr); |
62 | |
63 | /* grn_ts_expr_close() destroys an expression. */ |
64 | grn_rc grn_ts_expr_close(grn_ctx *ctx, grn_ts_expr *expr); |
65 | |
66 | /* grn_ts_expr_evaluate() evaluates an expression. */ |
67 | grn_rc grn_ts_expr_evaluate(grn_ctx *ctx, grn_ts_expr *expr, |
68 | const grn_ts_record *in, size_t n_in, void *out); |
69 | |
70 | /* grn_ts_expr_evaluate_to_buf() evaluates an expression. */ |
71 | grn_rc grn_ts_expr_evaluate_to_buf(grn_ctx *ctx, grn_ts_expr *expr, |
72 | const grn_ts_record *in, size_t n_in, |
73 | grn_ts_buf *out); |
74 | |
75 | /* grn_ts_expr_filter() filters records. */ |
76 | grn_rc grn_ts_expr_filter(grn_ctx *ctx, grn_ts_expr *expr, |
77 | grn_ts_record *in, size_t n_in, |
78 | grn_ts_record *out, size_t *n_out); |
79 | |
80 | /* grn_ts_expr_adjust() updates scores. */ |
81 | grn_rc grn_ts_expr_adjust(grn_ctx *ctx, grn_ts_expr *expr, |
82 | grn_ts_record *io, size_t n_io); |
83 | |
84 | #ifdef __cplusplus |
85 | } |
86 | #endif |
87 | |
88 | |