| 1 | /* |
| 2 | Copyright(C) 2020-2022 Sutou Kouhei <[email protected]> |
| 3 | |
| 4 | This library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Lesser General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2.1 of the License, or (at your option) any later version. |
| 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 | #include "grn_ctx.h" |
| 20 | #include "grn_posting.h" |
| 21 | |
| 22 | grn_posting * |
| 23 | grn_posting_open(grn_ctx *ctx) |
| 24 | { |
| 25 | GRN_API_ENTER; |
| 26 | grn_posting *posting = GRN_CALLOC(sizeof(grn_posting_internal)); |
| 27 | if (!posting) { |
| 28 | ERR(GRN_NO_MEMORY_AVAILABLE, "[posting][open] failed to allocate"); |
| 29 | } |
| 30 | GRN_API_RETURN(posting); |
| 31 | } |
| 32 | |
| 33 | void |
| 34 | grn_posting_close(grn_ctx *ctx, grn_posting *posting) |
| 35 | { |
| 36 | GRN_API_ENTER; |
| 37 | GRN_FREE(posting); |
| 38 | GRN_API_RETURN(); |
| 39 | } |
| 40 | |
| 41 | grn_id |
| 42 | grn_posting_get_record_id(grn_ctx *ctx, grn_posting *posting) |
| 43 | { |
| 44 | return posting->rid; |
| 45 | } |
| 46 | |
| 47 | uint32_t |
| 48 | grn_posting_get_section_id(grn_ctx *ctx, grn_posting *posting) |
| 49 | { |
| 50 | return posting->sid; |
| 51 | } |
| 52 | |
| 53 | uint32_t |
| 54 | grn_posting_get_position(grn_ctx *ctx, grn_posting *posting) |
| 55 | { |
| 56 | return posting->pos; |
| 57 | } |
| 58 | |
| 59 | uint32_t |
| 60 | grn_posting_get_tf(grn_ctx *ctx, grn_posting *posting) |
| 61 | { |
| 62 | return posting->tf; |
| 63 | } |
| 64 | |
| 65 | uint32_t |
| 66 | grn_posting_get_weight(grn_ctx *ctx, grn_posting *posting) |
| 67 | { |
| 68 | return posting->weight; |
| 69 | } |
| 70 | |
| 71 | float |
| 72 | grn_posting_get_weight_float(grn_ctx *ctx, grn_posting *posting) |
| 73 | { |
| 74 | return ((grn_posting_internal *)posting)->weight_float; |
| 75 | } |
| 76 | |
| 77 | uint32_t |
| 78 | grn_posting_get_rest(grn_ctx *ctx, grn_posting *posting) |
| 79 | { |
| 80 | return posting->rest; |
| 81 | } |
| 82 | |
| 83 | void |
| 84 | grn_posting_set_weight(grn_ctx *ctx, grn_posting *posting, uint32_t weight) |
| 85 | { |
| 86 | posting->weight = weight; |
| 87 | ((grn_posting_internal *)posting)->weight_float = (float)weight; |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | grn_posting_set_weight_float(grn_ctx *ctx, grn_posting *posting, float weight) |
| 92 | { |
| 93 | posting->weight = (uint32_t)weight; |
| 94 | ((grn_posting_internal *)posting)->weight_float = weight; |
| 95 | } |