1 /* Copyright(C) 2004 Brazil 2 3 This library is free software; you can redistribute it and/or 4 modify it under the terms of the GNU Lesser General Public 5 License as published by the Free Software Foundation; either 6 version 2.1 of the License, or (at your option) any later version. 7 8 This library is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 Lesser General Public License for more details. 12 13 You should have received a copy of the GNU Lesser General Public 14 License along with this library; if not, write to the Free Software 15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 */ 17 #ifndef SEN_INV_H 18 #define SEN_INV_H 19 20 #ifndef SENNA_H 21 #include "senna_in.h" 22 #endif /* SENNA_H */ 23 24 #ifndef SEN_SET_H 25 #include "set.h" 26 #endif /* SEN_SET_H */ 27 28 #ifndef SEN_IO_H 29 #include "io.h" 30 #endif /* SEN_IO_H */ 31 32 #ifndef SEN_STORE_H 33 #include "store.h" 34 #endif /* SEN_STORE_H */ 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #define SEN_INV_MAX_SEGMENT 0x4000 41 42 struct sen_inv_header; 43 44 struct _sen_inv_pos { 45 struct _sen_inv_pos *next; 46 uint32_t pos; 47 }; 48 49 struct _sen_inv_updspec { 50 uint32_t rid; 51 uint32_t sid; 52 int32_t score; 53 int32_t tf; /* number of postings successfully stored to index */ 54 int32_t atf; /* actual number of postings */ 55 struct _sen_inv_pos *pos; 56 struct _sen_inv_pos *tail; 57 sen_vgram_vnode *vnodes; 58 }; 59 60 typedef struct _sen_inv_updspec sen_inv_updspec; 61 62 sen_inv *sen_inv_create(const char *path, sen_sym *lexicon, 63 uint32_t initial_n_segments); 64 sen_inv *sen_inv_open(const char *path, sen_sym *lexicon); 65 sen_rc sen_inv_close(sen_inv *inv); 66 sen_rc sen_inv_remove(const char *path); 67 sen_rc sen_inv_info(sen_inv *inv, uint64_t *seg_size, uint64_t *chunk_size); 68 sen_rc sen_inv_update_one(sen_inv *inv, uint32_t key, sen_inv_updspec *u, sen_set *h, 69 int hint); 70 sen_rc sen_inv_delete_one(sen_inv *inv, uint32_t key, sen_inv_updspec *u, sen_set *h); 71 uint32_t sen_inv_initial_n_segments(sen_inv *inv); 72 73 sen_inv_updspec *sen_inv_updspec_open(uint32_t rid, uint32_t sid); 74 sen_rc sen_inv_updspec_close(sen_inv_updspec *u); 75 sen_rc sen_inv_updspec_add(sen_inv_updspec *u, int pos, int32_t weight); 76 int sen_inv_updspec_cmp(sen_inv_updspec *a, sen_inv_updspec *b); 77 78 uint32_t sen_inv_estimate_size(sen_inv *inv, uint32_t key); 79 80 void sen_inv_seg_expire(sen_inv *inv, int32_t threshold); 81 void sen_inv_expire(void); 82 83 #ifdef USE_QUERY_ABORT 84 void sen_inv_set_abort_callback(sen_inv *inv, int (*cb)(void*), void *arg); 85 #endif /* USE_QUERY_ABORT */ 86 87 typedef struct { 88 sen_id rid; 89 uint32_t sid; 90 uint32_t pos; 91 uint32_t tf; 92 uint32_t score; 93 uint32_t rest; 94 } sen_inv_posting; 95 96 typedef struct { 97 sen_inv *inv; 98 sen_inv_posting pc; 99 sen_inv_posting pb; 100 sen_inv_posting *post; 101 uint8_t *cp; 102 uint8_t *cpp; 103 uint8_t *cpe; 104 uint8_t *bp; 105 sen_io_win iw; 106 struct sen_inv_buffer *buf; 107 uint16_t stat; 108 uint16_t nextb; 109 uint16_t buffer_pseg; 110 uint16_t with_pos; 111 int flags; 112 uint16_t *ppseg; 113 } sen_inv_cursor; 114 115 #define SEN_INV_CURSOR_CMP(c1,c2) \ 116 (((c1)->post->rid > (c2)->post->rid) || \ 117 (((c1)->post->rid == (c2)->post->rid) && \ 118 (((c1)->post->sid > (c2)->post->sid) || \ 119 (((c1)->post->sid == (c2)->post->sid) && \ 120 ((c1)->post->pos > (c2)->post->pos))))) 121 122 sen_inv_cursor *sen_inv_cursor_open(sen_inv *inv, uint32_t key, int with_pos); 123 sen_inv_cursor *sen_inv_cursor_openv1(sen_inv *inv, uint32_t key); 124 sen_rc sen_inv_cursor_openv2(sen_inv_cursor **cursors, int ncursors); 125 sen_rc sen_inv_cursor_next(sen_inv_cursor *c); 126 sen_rc sen_inv_cursor_next_pos(sen_inv_cursor *c); 127 sen_rc sen_inv_cursor_close(sen_inv_cursor *c); 128 uint32_t sen_inv_max_section(sen_inv *inv); 129 130 int sen_inv_check(sen_inv *inv); 131 const char *sen_inv_path(sen_inv *inv); 132 sen_sym *sen_inv_lexicon(sen_inv *inv); 133 134 sen_rc sen_inv_upd(sen_inv *inv, sen_id rid, sen_vgram *vgram, 135 const char *oldvalue, unsigned int oldvalue_len, 136 const char *newvalue, unsigned int newvalue_len); 137 sen_rc sen_inv_update(sen_inv *inv, sen_id rid, sen_vgram *vgram, 138 unsigned int section, 139 sen_values *oldvalues, sen_values *newvalues); 140 sen_rc sen_inv_term_extract(sen_inv *inv, const char *string, 141 unsigned int string_len, sen_set *s, 142 sen_sel_operator op, sen_select_optarg *optarg); 143 sen_rc sen_inv_similar_search(sen_inv *inv, const char *string, unsigned int string_len, 144 sen_set *s, sen_sel_operator op, sen_select_optarg *optarg); 145 sen_rc sen_inv_select(sen_inv *inv, const char *string, unsigned int string_len, 146 sen_set *s, sen_sel_operator op, sen_select_optarg *optarg); 147 sen_set *sen_inv_sel(sen_inv *inv, const char *string, unsigned int string_len); 148 149 sen_rc sen_query_select(sen_inv *i, sen_query *q, sen_records *r, sen_sel_operator op); 150 151 #ifdef __cplusplus 152 } 153 #endif 154 155 #endif /* SEN_INV_H */ 156