jk-ferret 0.11.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +24 -0
- data/MIT-LICENSE +20 -0
- data/README +90 -0
- data/RELEASE_CHANGES +137 -0
- data/RELEASE_NOTES +60 -0
- data/Rakefile +443 -0
- data/TODO +109 -0
- data/TUTORIAL +231 -0
- data/bin/ferret-browser +79 -0
- data/ext/BZLIB_blocksort.c +1094 -0
- data/ext/BZLIB_bzlib.c +1578 -0
- data/ext/BZLIB_compress.c +672 -0
- data/ext/BZLIB_crctable.c +104 -0
- data/ext/BZLIB_decompress.c +626 -0
- data/ext/BZLIB_huffman.c +205 -0
- data/ext/BZLIB_randtable.c +84 -0
- data/ext/STEMMER_api.c +66 -0
- data/ext/STEMMER_libstemmer.c +93 -0
- data/ext/STEMMER_stem_ISO_8859_1_danish.c +337 -0
- data/ext/STEMMER_stem_ISO_8859_1_dutch.c +624 -0
- data/ext/STEMMER_stem_ISO_8859_1_english.c +1117 -0
- data/ext/STEMMER_stem_ISO_8859_1_finnish.c +762 -0
- data/ext/STEMMER_stem_ISO_8859_1_french.c +1246 -0
- data/ext/STEMMER_stem_ISO_8859_1_german.c +503 -0
- data/ext/STEMMER_stem_ISO_8859_1_hungarian.c +1230 -0
- data/ext/STEMMER_stem_ISO_8859_1_italian.c +1065 -0
- data/ext/STEMMER_stem_ISO_8859_1_norwegian.c +297 -0
- data/ext/STEMMER_stem_ISO_8859_1_porter.c +749 -0
- data/ext/STEMMER_stem_ISO_8859_1_portuguese.c +1017 -0
- data/ext/STEMMER_stem_ISO_8859_1_spanish.c +1093 -0
- data/ext/STEMMER_stem_ISO_8859_1_swedish.c +307 -0
- data/ext/STEMMER_stem_ISO_8859_2_romanian.c +998 -0
- data/ext/STEMMER_stem_KOI8_R_russian.c +700 -0
- data/ext/STEMMER_stem_UTF_8_danish.c +339 -0
- data/ext/STEMMER_stem_UTF_8_dutch.c +634 -0
- data/ext/STEMMER_stem_UTF_8_english.c +1125 -0
- data/ext/STEMMER_stem_UTF_8_finnish.c +768 -0
- data/ext/STEMMER_stem_UTF_8_french.c +1256 -0
- data/ext/STEMMER_stem_UTF_8_german.c +509 -0
- data/ext/STEMMER_stem_UTF_8_hungarian.c +1234 -0
- data/ext/STEMMER_stem_UTF_8_italian.c +1073 -0
- data/ext/STEMMER_stem_UTF_8_norwegian.c +299 -0
- data/ext/STEMMER_stem_UTF_8_porter.c +755 -0
- data/ext/STEMMER_stem_UTF_8_portuguese.c +1023 -0
- data/ext/STEMMER_stem_UTF_8_romanian.c +1004 -0
- data/ext/STEMMER_stem_UTF_8_russian.c +694 -0
- data/ext/STEMMER_stem_UTF_8_spanish.c +1097 -0
- data/ext/STEMMER_stem_UTF_8_swedish.c +309 -0
- data/ext/STEMMER_stem_UTF_8_turkish.c +2205 -0
- data/ext/STEMMER_utilities.c +478 -0
- data/ext/analysis.c +1710 -0
- data/ext/analysis.h +266 -0
- data/ext/api.h +26 -0
- data/ext/array.c +125 -0
- data/ext/array.h +62 -0
- data/ext/bitvector.c +96 -0
- data/ext/bitvector.h +594 -0
- data/ext/bzlib.h +282 -0
- data/ext/bzlib_private.h +503 -0
- data/ext/compound_io.c +384 -0
- data/ext/config.h +52 -0
- data/ext/document.c +159 -0
- data/ext/document.h +63 -0
- data/ext/except.c +102 -0
- data/ext/except.h +176 -0
- data/ext/extconf.rb +15 -0
- data/ext/ferret.c +416 -0
- data/ext/ferret.h +94 -0
- data/ext/field_index.c +262 -0
- data/ext/field_index.h +52 -0
- data/ext/filter.c +157 -0
- data/ext/fs_store.c +493 -0
- data/ext/global.c +458 -0
- data/ext/global.h +302 -0
- data/ext/hash.c +524 -0
- data/ext/hash.h +515 -0
- data/ext/hashset.c +192 -0
- data/ext/hashset.h +215 -0
- data/ext/header.h +58 -0
- data/ext/helper.c +63 -0
- data/ext/helper.h +21 -0
- data/ext/index.c +6804 -0
- data/ext/index.h +935 -0
- data/ext/internal.h +1019 -0
- data/ext/lang.c +10 -0
- data/ext/lang.h +68 -0
- data/ext/libstemmer.h +79 -0
- data/ext/mempool.c +88 -0
- data/ext/mempool.h +43 -0
- data/ext/modules.h +190 -0
- data/ext/multimapper.c +351 -0
- data/ext/multimapper.h +60 -0
- data/ext/posh.c +1006 -0
- data/ext/posh.h +973 -0
- data/ext/priorityqueue.c +149 -0
- data/ext/priorityqueue.h +155 -0
- data/ext/q_boolean.c +1621 -0
- data/ext/q_const_score.c +162 -0
- data/ext/q_filtered_query.c +212 -0
- data/ext/q_fuzzy.c +280 -0
- data/ext/q_match_all.c +149 -0
- data/ext/q_multi_term.c +673 -0
- data/ext/q_parser.c +3103 -0
- data/ext/q_phrase.c +1206 -0
- data/ext/q_prefix.c +98 -0
- data/ext/q_range.c +682 -0
- data/ext/q_span.c +2390 -0
- data/ext/q_term.c +337 -0
- data/ext/q_wildcard.c +167 -0
- data/ext/r_analysis.c +2626 -0
- data/ext/r_index.c +3468 -0
- data/ext/r_qparser.c +635 -0
- data/ext/r_search.c +4490 -0
- data/ext/r_store.c +513 -0
- data/ext/r_utils.c +1131 -0
- data/ext/ram_store.c +476 -0
- data/ext/scanner.c +895 -0
- data/ext/scanner.h +36 -0
- data/ext/scanner_mb.c +6701 -0
- data/ext/scanner_utf8.c +4415 -0
- data/ext/search.c +1864 -0
- data/ext/search.h +953 -0
- data/ext/similarity.c +151 -0
- data/ext/similarity.h +89 -0
- data/ext/sort.c +786 -0
- data/ext/stem_ISO_8859_1_danish.h +16 -0
- data/ext/stem_ISO_8859_1_dutch.h +16 -0
- data/ext/stem_ISO_8859_1_english.h +16 -0
- data/ext/stem_ISO_8859_1_finnish.h +16 -0
- data/ext/stem_ISO_8859_1_french.h +16 -0
- data/ext/stem_ISO_8859_1_german.h +16 -0
- data/ext/stem_ISO_8859_1_hungarian.h +16 -0
- data/ext/stem_ISO_8859_1_italian.h +16 -0
- data/ext/stem_ISO_8859_1_norwegian.h +16 -0
- data/ext/stem_ISO_8859_1_porter.h +16 -0
- data/ext/stem_ISO_8859_1_portuguese.h +16 -0
- data/ext/stem_ISO_8859_1_spanish.h +16 -0
- data/ext/stem_ISO_8859_1_swedish.h +16 -0
- data/ext/stem_ISO_8859_2_romanian.h +16 -0
- data/ext/stem_KOI8_R_russian.h +16 -0
- data/ext/stem_UTF_8_danish.h +16 -0
- data/ext/stem_UTF_8_dutch.h +16 -0
- data/ext/stem_UTF_8_english.h +16 -0
- data/ext/stem_UTF_8_finnish.h +16 -0
- data/ext/stem_UTF_8_french.h +16 -0
- data/ext/stem_UTF_8_german.h +16 -0
- data/ext/stem_UTF_8_hungarian.h +16 -0
- data/ext/stem_UTF_8_italian.h +16 -0
- data/ext/stem_UTF_8_norwegian.h +16 -0
- data/ext/stem_UTF_8_porter.h +16 -0
- data/ext/stem_UTF_8_portuguese.h +16 -0
- data/ext/stem_UTF_8_romanian.h +16 -0
- data/ext/stem_UTF_8_russian.h +16 -0
- data/ext/stem_UTF_8_spanish.h +16 -0
- data/ext/stem_UTF_8_swedish.h +16 -0
- data/ext/stem_UTF_8_turkish.h +16 -0
- data/ext/stopwords.c +410 -0
- data/ext/store.c +698 -0
- data/ext/store.h +799 -0
- data/ext/symbol.c +10 -0
- data/ext/symbol.h +23 -0
- data/ext/term_vectors.c +73 -0
- data/ext/threading.h +31 -0
- data/ext/win32.h +62 -0
- data/lib/ferret.rb +30 -0
- data/lib/ferret/browser.rb +246 -0
- data/lib/ferret/browser/s/global.js +192 -0
- data/lib/ferret/browser/s/style.css +148 -0
- data/lib/ferret/browser/views/document/list.rhtml +49 -0
- data/lib/ferret/browser/views/document/show.rhtml +27 -0
- data/lib/ferret/browser/views/error/index.rhtml +7 -0
- data/lib/ferret/browser/views/help/index.rhtml +8 -0
- data/lib/ferret/browser/views/home/index.rhtml +29 -0
- data/lib/ferret/browser/views/layout.rhtml +22 -0
- data/lib/ferret/browser/views/term-vector/index.rhtml +4 -0
- data/lib/ferret/browser/views/term/index.rhtml +199 -0
- data/lib/ferret/browser/views/term/termdocs.rhtml +1 -0
- data/lib/ferret/browser/webrick.rb +14 -0
- data/lib/ferret/document.rb +130 -0
- data/lib/ferret/field_infos.rb +44 -0
- data/lib/ferret/field_symbol.rb +87 -0
- data/lib/ferret/index.rb +973 -0
- data/lib/ferret/number_tools.rb +157 -0
- data/lib/ferret/version.rb +3 -0
- data/setup.rb +1555 -0
- data/test/long_running/largefile/tc_largefile.rb +46 -0
- data/test/test_all.rb +5 -0
- data/test/test_helper.rb +29 -0
- data/test/test_installed.rb +1 -0
- data/test/threading/number_to_spoken.rb +132 -0
- data/test/threading/thread_safety_index_test.rb +88 -0
- data/test/threading/thread_safety_read_write_test.rb +73 -0
- data/test/threading/thread_safety_test.rb +133 -0
- data/test/unit/analysis/tc_analyzer.rb +550 -0
- data/test/unit/analysis/tc_token_stream.rb +653 -0
- data/test/unit/index/tc_index.rb +867 -0
- data/test/unit/index/tc_index_reader.rb +699 -0
- data/test/unit/index/tc_index_writer.rb +447 -0
- data/test/unit/index/th_doc.rb +332 -0
- data/test/unit/query_parser/tc_query_parser.rb +238 -0
- data/test/unit/search/tc_filter.rb +156 -0
- data/test/unit/search/tc_fuzzy_query.rb +147 -0
- data/test/unit/search/tc_index_searcher.rb +67 -0
- data/test/unit/search/tc_multi_searcher.rb +128 -0
- data/test/unit/search/tc_multiple_search_requests.rb +58 -0
- data/test/unit/search/tc_search_and_sort.rb +179 -0
- data/test/unit/search/tc_sort.rb +49 -0
- data/test/unit/search/tc_sort_field.rb +27 -0
- data/test/unit/search/tc_spans.rb +190 -0
- data/test/unit/search/tm_searcher.rb +436 -0
- data/test/unit/store/tc_fs_store.rb +115 -0
- data/test/unit/store/tc_ram_store.rb +35 -0
- data/test/unit/store/tm_store.rb +34 -0
- data/test/unit/store/tm_store_lock.rb +68 -0
- data/test/unit/tc_document.rb +81 -0
- data/test/unit/tc_field_symbol.rb +26 -0
- data/test/unit/ts_analysis.rb +2 -0
- data/test/unit/ts_index.rb +2 -0
- data/test/unit/ts_largefile.rb +4 -0
- data/test/unit/ts_query_parser.rb +2 -0
- data/test/unit/ts_search.rb +2 -0
- data/test/unit/ts_store.rb +2 -0
- data/test/unit/ts_utils.rb +2 -0
- data/test/unit/utils/tc_bit_vector.rb +295 -0
- data/test/unit/utils/tc_number_tools.rb +117 -0
- data/test/unit/utils/tc_priority_queue.rb +106 -0
- data/test/utils/content_generator.rb +226 -0
- metadata +319 -0
data/ext/search.h
ADDED
@@ -0,0 +1,953 @@
|
|
1
|
+
#ifndef FRT_SEARCH_H
|
2
|
+
#define FRT_SEARCH_H
|
3
|
+
|
4
|
+
#ifdef __cplusplus
|
5
|
+
extern "C" {
|
6
|
+
#endif
|
7
|
+
|
8
|
+
typedef struct FrtQuery FrtQuery;
|
9
|
+
typedef struct FrtWeight FrtWeight;
|
10
|
+
typedef struct FrtScorer FrtScorer;
|
11
|
+
|
12
|
+
#include "index.h"
|
13
|
+
#include "bitvector.h"
|
14
|
+
#include "similarity.h"
|
15
|
+
#include "field_index.h"
|
16
|
+
|
17
|
+
/***************************************************************************
|
18
|
+
*
|
19
|
+
* FrtExplanation
|
20
|
+
*
|
21
|
+
***************************************************************************/
|
22
|
+
|
23
|
+
#define FRT_EXPLANATION_DETAILS_START_SIZE 4
|
24
|
+
typedef struct FrtExplanation
|
25
|
+
{
|
26
|
+
float value;
|
27
|
+
char *description;
|
28
|
+
struct FrtExplanation **details;
|
29
|
+
} FrtExplanation;
|
30
|
+
|
31
|
+
extern FrtExplanation *frt_expl_new(float value, const char *description, ...);
|
32
|
+
extern void frt_expl_destroy(FrtExplanation *expl);
|
33
|
+
extern FrtExplanation *frt_expl_add_detail(FrtExplanation *expl, FrtExplanation *detail);
|
34
|
+
extern char *frt_expl_to_s_depth(FrtExplanation *expl, int depth);
|
35
|
+
extern char *frt_expl_to_html(FrtExplanation *expl);
|
36
|
+
|
37
|
+
#define frt_expl_to_s(expl) frt_expl_to_s_depth(expl, 0)
|
38
|
+
|
39
|
+
/***************************************************************************
|
40
|
+
*
|
41
|
+
* Highlighter
|
42
|
+
*
|
43
|
+
***************************************************************************/
|
44
|
+
|
45
|
+
typedef struct FrtMatchRange
|
46
|
+
{
|
47
|
+
int start;
|
48
|
+
int end;
|
49
|
+
int start_offset;
|
50
|
+
int end_offset;
|
51
|
+
double score;
|
52
|
+
} FrtMatchRange;
|
53
|
+
|
54
|
+
#define FRT_MATCH_VECTOR_INIT_CAPA 8
|
55
|
+
typedef struct FrtMatchVector
|
56
|
+
{
|
57
|
+
int size;
|
58
|
+
int capa;
|
59
|
+
FrtMatchRange *matches;
|
60
|
+
} FrtMatchVector;
|
61
|
+
|
62
|
+
extern FrtMatchVector *frt_matchv_new();
|
63
|
+
extern FrtMatchVector *frt_matchv_add(FrtMatchVector *mp, int start, int end);
|
64
|
+
extern FrtMatchVector *frt_matchv_sort(FrtMatchVector *self);
|
65
|
+
extern void frt_matchv_destroy(FrtMatchVector *self);
|
66
|
+
extern FrtMatchVector *frt_matchv_compact(FrtMatchVector *self);
|
67
|
+
extern FrtMatchVector *frt_matchv_compact_with_breaks(FrtMatchVector *self);
|
68
|
+
|
69
|
+
/***************************************************************************
|
70
|
+
*
|
71
|
+
* FrtHit
|
72
|
+
*
|
73
|
+
***************************************************************************/
|
74
|
+
|
75
|
+
typedef struct FrtHit
|
76
|
+
{
|
77
|
+
int doc;
|
78
|
+
float score;
|
79
|
+
} FrtHit;
|
80
|
+
|
81
|
+
/***************************************************************************
|
82
|
+
*
|
83
|
+
* FrtTopDocs
|
84
|
+
*
|
85
|
+
***************************************************************************/
|
86
|
+
|
87
|
+
typedef struct FrtTopDocs
|
88
|
+
{
|
89
|
+
int total_hits;
|
90
|
+
int size;
|
91
|
+
FrtHit **hits;
|
92
|
+
float max_score;
|
93
|
+
} FrtTopDocs;
|
94
|
+
|
95
|
+
extern FrtTopDocs *frt_td_new(int total_hits, int size, FrtHit **hits,
|
96
|
+
float max_score);
|
97
|
+
extern void frt_td_destroy(FrtTopDocs *td);
|
98
|
+
extern char *frt_td_to_s(FrtTopDocs *td);
|
99
|
+
|
100
|
+
/***************************************************************************
|
101
|
+
*
|
102
|
+
* FrtFilter
|
103
|
+
*
|
104
|
+
***************************************************************************/
|
105
|
+
|
106
|
+
typedef struct FrtFilter
|
107
|
+
{
|
108
|
+
FrtSymbol name;
|
109
|
+
FrtHash *cache;
|
110
|
+
FrtBitVector *(*get_bv_i)(struct FrtFilter *self, FrtIndexReader *ir);
|
111
|
+
char *(*to_s)(struct FrtFilter *self);
|
112
|
+
unsigned long (*hash)(struct FrtFilter *self);
|
113
|
+
int (*eq)(struct FrtFilter *self, struct FrtFilter *o);
|
114
|
+
void (*destroy_i)(struct FrtFilter *self);
|
115
|
+
int ref_cnt;
|
116
|
+
} FrtFilter;
|
117
|
+
|
118
|
+
#define filt_new(type) frt_filt_create(sizeof(type), frt_intern(#type))
|
119
|
+
extern FrtFilter *frt_filt_create(size_t size, FrtSymbol name);
|
120
|
+
extern FrtBitVector *frt_filt_get_bv(FrtFilter *filt, FrtIndexReader *ir);
|
121
|
+
extern void frt_filt_destroy_i(FrtFilter *filt);
|
122
|
+
extern void frt_filt_deref(FrtFilter *filt);
|
123
|
+
extern unsigned long frt_filt_hash(FrtFilter *filt);
|
124
|
+
extern int frt_filt_eq(FrtFilter *filt, FrtFilter *o);
|
125
|
+
|
126
|
+
/***************************************************************************
|
127
|
+
*
|
128
|
+
* RangeFilter
|
129
|
+
*
|
130
|
+
***************************************************************************/
|
131
|
+
|
132
|
+
extern FrtFilter *frt_rfilt_new(FrtSymbol field,
|
133
|
+
const char *lower_term, const char *upper_term,
|
134
|
+
bool include_lower, bool include_upper);
|
135
|
+
|
136
|
+
/***************************************************************************
|
137
|
+
*
|
138
|
+
* TypedRangeFilter
|
139
|
+
*
|
140
|
+
***************************************************************************/
|
141
|
+
|
142
|
+
extern FrtFilter *frt_trfilt_new(FrtSymbol field,
|
143
|
+
const char *lower_term, const char *upper_term,
|
144
|
+
bool include_lower, bool include_upper);
|
145
|
+
|
146
|
+
/***************************************************************************
|
147
|
+
*
|
148
|
+
* QueryFilter
|
149
|
+
*
|
150
|
+
***************************************************************************/
|
151
|
+
|
152
|
+
extern FrtFilter *frt_qfilt_new(FrtQuery *query);
|
153
|
+
extern FrtFilter *frt_qfilt_new_nr(FrtQuery *query);
|
154
|
+
|
155
|
+
/***************************************************************************
|
156
|
+
*
|
157
|
+
* FrtWeight
|
158
|
+
*
|
159
|
+
***************************************************************************/
|
160
|
+
|
161
|
+
struct FrtWeight
|
162
|
+
{
|
163
|
+
float value;
|
164
|
+
float qweight;
|
165
|
+
float qnorm;
|
166
|
+
float idf;
|
167
|
+
FrtQuery *query;
|
168
|
+
FrtSimilarity *similarity;
|
169
|
+
FrtQuery *(*get_query)(FrtWeight *self);
|
170
|
+
float (*get_value)(FrtWeight *self);
|
171
|
+
void (*normalize)(FrtWeight *self, float normalization_factor);
|
172
|
+
FrtScorer *(*scorer)(FrtWeight *self, FrtIndexReader *ir);
|
173
|
+
FrtExplanation *(*explain)(FrtWeight *self, FrtIndexReader *ir, int doc_num);
|
174
|
+
float (*sum_of_squared_weights)(FrtWeight *self);
|
175
|
+
char *(*to_s)(FrtWeight *self);
|
176
|
+
void (*destroy)(FrtWeight *self);
|
177
|
+
};
|
178
|
+
|
179
|
+
#define w_new(type, query) frt_w_create(sizeof(type), query)
|
180
|
+
extern FrtWeight *frt_w_create(size_t size, FrtQuery *query);
|
181
|
+
extern void frt_w_destroy(FrtWeight *self);
|
182
|
+
extern FrtQuery *frt_w_get_query(FrtWeight *self);
|
183
|
+
extern float frt_w_get_value(FrtWeight *self);
|
184
|
+
extern float frt_w_sum_of_squared_weights(FrtWeight *self);
|
185
|
+
extern void frt_w_normalize(FrtWeight *self, float normalization_factor);
|
186
|
+
|
187
|
+
/***************************************************************************
|
188
|
+
*
|
189
|
+
* FrtQuery
|
190
|
+
*
|
191
|
+
***************************************************************************/
|
192
|
+
|
193
|
+
typedef enum
|
194
|
+
{
|
195
|
+
FRT_TERM_QUERY,
|
196
|
+
FRT_MULTI_TERM_QUERY,
|
197
|
+
FRT_BOOLEAN_QUERY,
|
198
|
+
FRT_PHRASE_QUERY,
|
199
|
+
FRT_CONSTANT_QUERY,
|
200
|
+
FRT_FILTERED_QUERY,
|
201
|
+
FRT_MATCH_ALL_QUERY,
|
202
|
+
FRT_RANGE_QUERY,
|
203
|
+
FRT_TYPED_RANGE_QUERY,
|
204
|
+
FRT_WILD_CARD_QUERY,
|
205
|
+
FRT_FUZZY_QUERY,
|
206
|
+
FRT_PREFIX_QUERY,
|
207
|
+
FRT_SPAN_TERM_QUERY,
|
208
|
+
FRT_SPAN_MULTI_TERM_QUERY,
|
209
|
+
FRT_SPAN_PREFIX_QUERY,
|
210
|
+
FRT_SPAN_FIRST_QUERY,
|
211
|
+
FRT_SPAN_OR_QUERY,
|
212
|
+
FRT_SPAN_NOT_QUERY,
|
213
|
+
FRT_SPAN_NEAR_QUERY
|
214
|
+
} FrtQueryType;
|
215
|
+
|
216
|
+
struct FrtQuery
|
217
|
+
{
|
218
|
+
int ref_cnt;
|
219
|
+
float boost;
|
220
|
+
FrtWeight *weight;
|
221
|
+
FrtQuery *(*rewrite)(FrtQuery *self, FrtIndexReader *ir);
|
222
|
+
void (*extract_terms)(FrtQuery *self, FrtHashSet *terms);
|
223
|
+
FrtSimilarity *(*get_similarity)(FrtQuery *self, FrtSearcher *searcher);
|
224
|
+
char *(*to_s)(FrtQuery *self, FrtSymbol field);
|
225
|
+
unsigned long (*hash)(FrtQuery *self);
|
226
|
+
int (*eq)(FrtQuery *self, FrtQuery *o);
|
227
|
+
void (*destroy_i)(FrtQuery *self);
|
228
|
+
FrtWeight *(*create_weight_i)(FrtQuery *self, FrtSearcher *searcher);
|
229
|
+
FrtMatchVector *(*get_matchv_i)(FrtQuery *self, FrtMatchVector *mv, FrtTermVector *tv);
|
230
|
+
FrtQueryType type;
|
231
|
+
};
|
232
|
+
|
233
|
+
/* Internal FrtQuery Functions */
|
234
|
+
extern FrtSimilarity *frt_q_get_similarity_i(FrtQuery *self, FrtSearcher *searcher);
|
235
|
+
extern void frt_q_destroy_i(FrtQuery *self);
|
236
|
+
extern FrtWeight *frt_q_create_weight_unsup(FrtQuery *self, FrtSearcher *searcher);
|
237
|
+
|
238
|
+
extern void frt_q_deref(FrtQuery *self);
|
239
|
+
extern const char *frt_q_get_query_name(FrtQueryType type);
|
240
|
+
extern FrtWeight *frt_q_weight(FrtQuery *self, FrtSearcher *searcher);
|
241
|
+
extern FrtQuery *frt_q_combine(FrtQuery **queries, int q_cnt);
|
242
|
+
extern unsigned long frt_q_hash(FrtQuery *self);
|
243
|
+
extern int frt_q_eq(FrtQuery *self, FrtQuery *o);
|
244
|
+
extern FrtQuery *frt_q_create(size_t size);
|
245
|
+
#define frt_q_new(type) frt_q_create(sizeof(type))
|
246
|
+
|
247
|
+
/***************************************************************************
|
248
|
+
* FrtTermQuery
|
249
|
+
***************************************************************************/
|
250
|
+
|
251
|
+
typedef struct FrtTermQuery
|
252
|
+
{
|
253
|
+
FrtQuery super;
|
254
|
+
FrtSymbol field;
|
255
|
+
char *term;
|
256
|
+
} FrtTermQuery;
|
257
|
+
|
258
|
+
FrtQuery *frt_tq_new(FrtSymbol field, const char *term);
|
259
|
+
|
260
|
+
/***************************************************************************
|
261
|
+
* FrtBooleanQuery
|
262
|
+
***************************************************************************/
|
263
|
+
|
264
|
+
/* *** FrtBooleanClause *** */
|
265
|
+
|
266
|
+
typedef enum
|
267
|
+
{
|
268
|
+
FRT_BC_SHOULD,
|
269
|
+
FRT_BC_MUST,
|
270
|
+
FRT_BC_MUST_NOT
|
271
|
+
} FrtBCType;
|
272
|
+
|
273
|
+
typedef struct FrtBooleanClause
|
274
|
+
{
|
275
|
+
int ref_cnt;
|
276
|
+
FrtQuery *query;
|
277
|
+
FrtBCType occur;
|
278
|
+
bool is_prohibited : 1;
|
279
|
+
bool is_required : 1;
|
280
|
+
} FrtBooleanClause;
|
281
|
+
|
282
|
+
extern FrtBooleanClause *frt_bc_new(FrtQuery *query, FrtBCType occur);
|
283
|
+
extern void frt_bc_deref(FrtBooleanClause *self);
|
284
|
+
extern void frt_bc_set_occur(FrtBooleanClause *self, FrtBCType occur);
|
285
|
+
|
286
|
+
/* *** FrtBooleanQuery *** */
|
287
|
+
|
288
|
+
#define FRT_DEFAULT_MAX_CLAUSE_COUNT 1024
|
289
|
+
#define FRT_BOOLEAN_CLAUSES_START_CAPA 4
|
290
|
+
#define FRT_QUERY_STRING_START_SIZE 64
|
291
|
+
|
292
|
+
typedef struct FrtBooleanQuery
|
293
|
+
{
|
294
|
+
FrtQuery super;
|
295
|
+
bool coord_disabled;
|
296
|
+
int max_clause_cnt;
|
297
|
+
int clause_cnt;
|
298
|
+
int clause_capa;
|
299
|
+
float original_boost;
|
300
|
+
FrtBooleanClause **clauses;
|
301
|
+
FrtSimilarity *similarity;
|
302
|
+
} FrtBooleanQuery;
|
303
|
+
|
304
|
+
extern FrtQuery *frt_bq_new(bool coord_disabled);
|
305
|
+
extern FrtQuery *frt_bq_new_max(bool coord_disabled, int max);
|
306
|
+
extern FrtBooleanClause *frt_bq_add_query(FrtQuery *self, FrtQuery *sub_query,
|
307
|
+
FrtBCType occur);
|
308
|
+
extern FrtBooleanClause *frt_bq_add_query_nr(FrtQuery *self, FrtQuery *sub_query,
|
309
|
+
FrtBCType occur);
|
310
|
+
extern FrtBooleanClause *frt_bq_add_clause(FrtQuery *self, FrtBooleanClause *bc);
|
311
|
+
extern FrtBooleanClause *frt_bq_add_clause_nr(FrtQuery *self, FrtBooleanClause *bc);
|
312
|
+
|
313
|
+
/***************************************************************************
|
314
|
+
* FrtPhraseQuery
|
315
|
+
***************************************************************************/
|
316
|
+
|
317
|
+
#define FRT_PHQ_INIT_CAPA 4
|
318
|
+
typedef struct FrtPhraseQuery
|
319
|
+
{
|
320
|
+
FrtQuery super;
|
321
|
+
int slop;
|
322
|
+
FrtSymbol field;
|
323
|
+
FrtPhrasePosition *positions;
|
324
|
+
int pos_cnt;
|
325
|
+
int pos_capa;
|
326
|
+
} FrtPhraseQuery;
|
327
|
+
|
328
|
+
extern FrtQuery *frt_phq_new(FrtSymbol field);
|
329
|
+
extern void frt_phq_add_term(FrtQuery *self, const char *term, int pos_inc);
|
330
|
+
extern void frt_phq_add_term_abs(FrtQuery *self, const char *term, int position);
|
331
|
+
extern void frt_phq_append_multi_term(FrtQuery *self, const char *term);
|
332
|
+
extern void frt_phq_set_slop(FrtQuery *self, int slop);
|
333
|
+
|
334
|
+
/***************************************************************************
|
335
|
+
* FrtMultiTermQuery
|
336
|
+
***************************************************************************/
|
337
|
+
|
338
|
+
#define FRT_MULTI_TERM_QUERY_MAX_TERMS 256
|
339
|
+
typedef struct FrtMultiTermQuery
|
340
|
+
{
|
341
|
+
FrtQuery super;
|
342
|
+
FrtSymbol field;
|
343
|
+
FrtPriorityQueue *boosted_terms;
|
344
|
+
float min_boost;
|
345
|
+
} FrtMultiTermQuery;
|
346
|
+
|
347
|
+
extern void frt_multi_tq_add_term(FrtQuery *self, const char *term);
|
348
|
+
extern void frt_multi_tq_add_term_boost(FrtQuery *self, const char *term, float boost);
|
349
|
+
extern FrtQuery *frt_multi_tq_new(FrtSymbol field);
|
350
|
+
extern FrtQuery *frt_multi_tq_new_conf(FrtSymbol field, int max_terms,
|
351
|
+
float min_boost);
|
352
|
+
|
353
|
+
#define FrtMTQMaxTerms(query) (((FrtMTQSubQuery *)(query))->max_terms)
|
354
|
+
typedef struct FrtMTQSubQuery
|
355
|
+
{
|
356
|
+
FrtQuery super;
|
357
|
+
int max_terms;
|
358
|
+
} FrtMTQSubQuery;
|
359
|
+
|
360
|
+
/***************************************************************************
|
361
|
+
* FrtPrefixQuery
|
362
|
+
***************************************************************************/
|
363
|
+
|
364
|
+
#define FRT_PREFIX_QUERY_MAX_TERMS 256
|
365
|
+
|
366
|
+
typedef struct FrtPrefixQuery
|
367
|
+
{
|
368
|
+
FrtMTQSubQuery super;
|
369
|
+
FrtSymbol field;
|
370
|
+
char *prefix;
|
371
|
+
} FrtPrefixQuery;
|
372
|
+
|
373
|
+
extern FrtQuery *frt_prefixq_new(FrtSymbol field, const char *prefix);
|
374
|
+
|
375
|
+
/***************************************************************************
|
376
|
+
* FrtWildCardQuery
|
377
|
+
***************************************************************************/
|
378
|
+
|
379
|
+
#define FRT_WILD_CHAR '?'
|
380
|
+
#define FRT_WILD_STRING '*'
|
381
|
+
#define FRT_WILD_CARD_QUERY_MAX_TERMS 256
|
382
|
+
|
383
|
+
typedef struct FrtWildCardQuery
|
384
|
+
{
|
385
|
+
FrtMTQSubQuery super;
|
386
|
+
FrtSymbol field;
|
387
|
+
char *pattern;
|
388
|
+
} FrtWildCardQuery;
|
389
|
+
|
390
|
+
|
391
|
+
extern FrtQuery *frt_wcq_new(FrtSymbol field, const char *pattern);
|
392
|
+
extern bool frt_wc_match(const char *pattern, const char *text);
|
393
|
+
|
394
|
+
/***************************************************************************
|
395
|
+
* FrtFuzzyQuery
|
396
|
+
***************************************************************************/
|
397
|
+
|
398
|
+
#define FRT_DEF_MIN_SIM 0.5f
|
399
|
+
#define FRT_DEF_PRE_LEN 0
|
400
|
+
#define FRT_DEF_MAX_TERMS 256
|
401
|
+
#define FRT_TYPICAL_LONGEST_WORD 20
|
402
|
+
|
403
|
+
typedef struct FrtFuzzyQuery
|
404
|
+
{
|
405
|
+
FrtMTQSubQuery super;
|
406
|
+
FrtSymbol field;
|
407
|
+
char *term;
|
408
|
+
const char *text; /* term text after prefix */
|
409
|
+
int text_len;
|
410
|
+
int pre_len;
|
411
|
+
float min_sim;
|
412
|
+
float scale_factor;
|
413
|
+
int max_distances[FRT_TYPICAL_LONGEST_WORD];
|
414
|
+
int *da;
|
415
|
+
} FrtFuzzyQuery;
|
416
|
+
|
417
|
+
extern FrtQuery *frt_fuzq_new(FrtSymbol field, const char *term);
|
418
|
+
extern FrtQuery *frt_fuzq_new_conf(FrtSymbol field, const char *term,
|
419
|
+
float min_sim, int pre_len, int max_terms);
|
420
|
+
extern float frt_fuzq_score(FrtFuzzyQuery *fuzq, const char *target);
|
421
|
+
|
422
|
+
/***************************************************************************
|
423
|
+
* FrtConstantScoreQuery
|
424
|
+
***************************************************************************/
|
425
|
+
|
426
|
+
typedef struct FrtConstantScoreQuery
|
427
|
+
{
|
428
|
+
FrtQuery super;
|
429
|
+
FrtFilter *filter;
|
430
|
+
FrtQuery *original;
|
431
|
+
} FrtConstantScoreQuery;
|
432
|
+
|
433
|
+
extern FrtQuery *frt_csq_new(FrtFilter *filter);
|
434
|
+
extern FrtQuery *frt_csq_new_nr(FrtFilter *filter);
|
435
|
+
|
436
|
+
/***************************************************************************
|
437
|
+
* FrtFilteredQuery
|
438
|
+
***************************************************************************/
|
439
|
+
|
440
|
+
typedef struct FrtFilteredQuery
|
441
|
+
{
|
442
|
+
FrtQuery super;
|
443
|
+
FrtQuery *query;
|
444
|
+
FrtFilter *filter;
|
445
|
+
} FrtFilteredQuery;
|
446
|
+
|
447
|
+
extern FrtQuery *frt_fq_new(FrtQuery *query, FrtFilter *filter);
|
448
|
+
|
449
|
+
/***************************************************************************
|
450
|
+
* FrtMatchAllQuery
|
451
|
+
***************************************************************************/
|
452
|
+
|
453
|
+
extern FrtQuery *frt_maq_new();
|
454
|
+
|
455
|
+
/***************************************************************************
|
456
|
+
* FrtRangeQuery
|
457
|
+
***************************************************************************/
|
458
|
+
|
459
|
+
extern FrtQuery *frt_rq_new(FrtSymbol field, const char *lower_term,
|
460
|
+
const char *upper_term, bool include_lower,
|
461
|
+
bool include_upper);
|
462
|
+
extern FrtQuery *frt_rq_new_less(FrtSymbol field, const char *upper_term,
|
463
|
+
bool include_upper);
|
464
|
+
extern FrtQuery *frt_rq_new_more(FrtSymbol field, const char *lower_term,
|
465
|
+
bool include_lower);
|
466
|
+
|
467
|
+
/***************************************************************************
|
468
|
+
* FrtTypedRangeQuery
|
469
|
+
***************************************************************************/
|
470
|
+
|
471
|
+
extern FrtQuery *frt_trq_new(FrtSymbol field, const char *lower_term,
|
472
|
+
const char *upper_term, bool include_lower,
|
473
|
+
bool include_upper);
|
474
|
+
extern FrtQuery *frt_trq_new_less(FrtSymbol field, const char *upper_term,
|
475
|
+
bool include_upper);
|
476
|
+
extern FrtQuery *frt_trq_new_more(FrtSymbol field, const char *lower_term,
|
477
|
+
bool include_lower);
|
478
|
+
|
479
|
+
/***************************************************************************
|
480
|
+
* FrtSpanQuery
|
481
|
+
***************************************************************************/
|
482
|
+
|
483
|
+
/* ** FrtSpanEnum ** */
|
484
|
+
typedef struct FrtSpanEnum FrtSpanEnum;
|
485
|
+
struct FrtSpanEnum
|
486
|
+
{
|
487
|
+
FrtQuery *query;
|
488
|
+
bool (*next)(FrtSpanEnum *self);
|
489
|
+
bool (*skip_to)(FrtSpanEnum *self, int target_doc);
|
490
|
+
int (*doc)(FrtSpanEnum *self);
|
491
|
+
int (*start)(FrtSpanEnum *self);
|
492
|
+
int (*end)(FrtSpanEnum *self);
|
493
|
+
char *(*to_s)(FrtSpanEnum *self);
|
494
|
+
void (*destroy)(FrtSpanEnum *self);
|
495
|
+
};
|
496
|
+
|
497
|
+
/* ** FrtSpanQuery ** */
|
498
|
+
typedef struct FrtSpanQuery
|
499
|
+
{
|
500
|
+
FrtQuery super;
|
501
|
+
FrtSymbol field;
|
502
|
+
FrtSpanEnum *(*get_spans)(FrtQuery *self, FrtIndexReader *ir);
|
503
|
+
FrtHashSet *(*get_terms)(FrtQuery *self);
|
504
|
+
} FrtSpanQuery;
|
505
|
+
|
506
|
+
/***************************************************************************
|
507
|
+
* FrtSpanTermQuery
|
508
|
+
***************************************************************************/
|
509
|
+
|
510
|
+
typedef struct FrtSpanTermQuery
|
511
|
+
{
|
512
|
+
FrtSpanQuery super;
|
513
|
+
char *term;
|
514
|
+
} FrtSpanTermQuery;
|
515
|
+
extern FrtQuery *frt_spantq_new(FrtSymbol field, const char *term);
|
516
|
+
|
517
|
+
/***************************************************************************
|
518
|
+
* FrtSpanMultiTermQuery
|
519
|
+
***************************************************************************/
|
520
|
+
|
521
|
+
#define FRT_SPAN_MULTI_TERM_QUERY_CAPA 1024
|
522
|
+
typedef struct FrtSpanMultiTermQuery
|
523
|
+
{
|
524
|
+
FrtSpanQuery super;
|
525
|
+
char **terms;
|
526
|
+
int term_cnt;
|
527
|
+
int term_capa;
|
528
|
+
} FrtSpanMultiTermQuery;
|
529
|
+
|
530
|
+
extern FrtQuery *frt_spanmtq_new(FrtSymbol field);
|
531
|
+
extern FrtQuery *frt_spanmtq_new_conf(FrtSymbol field, int max_size);
|
532
|
+
extern void frt_spanmtq_add_term(FrtQuery *self, const char *term);
|
533
|
+
|
534
|
+
/***************************************************************************
|
535
|
+
* FrtSpanFirstQuery
|
536
|
+
***************************************************************************/
|
537
|
+
|
538
|
+
typedef struct FrtSpanFirstQuery
|
539
|
+
{
|
540
|
+
FrtSpanQuery super;
|
541
|
+
int end;
|
542
|
+
FrtQuery *match;
|
543
|
+
} FrtSpanFirstQuery;
|
544
|
+
|
545
|
+
extern FrtQuery *frt_spanfq_new(FrtQuery *match, int end);
|
546
|
+
extern FrtQuery *frt_spanfq_new_nr(FrtQuery *match, int end);
|
547
|
+
|
548
|
+
/***************************************************************************
|
549
|
+
* FrtSpanOrQuery
|
550
|
+
***************************************************************************/
|
551
|
+
|
552
|
+
typedef struct FrtSpanOrQuery
|
553
|
+
{
|
554
|
+
FrtSpanQuery super;
|
555
|
+
FrtQuery **clauses;
|
556
|
+
int c_cnt;
|
557
|
+
int c_capa;
|
558
|
+
} FrtSpanOrQuery;
|
559
|
+
|
560
|
+
extern FrtQuery *frt_spanoq_new();
|
561
|
+
extern FrtQuery *frt_spanoq_add_clause(FrtQuery *self, FrtQuery *clause);
|
562
|
+
extern FrtQuery *frt_spanoq_add_clause_nr(FrtQuery *self, FrtQuery *clause);
|
563
|
+
|
564
|
+
/***************************************************************************
|
565
|
+
* FrtSpanNearQuery
|
566
|
+
***************************************************************************/
|
567
|
+
|
568
|
+
typedef struct FrtSpanNearQuery
|
569
|
+
{
|
570
|
+
FrtSpanQuery super;
|
571
|
+
FrtQuery **clauses;
|
572
|
+
int c_cnt;
|
573
|
+
int c_capa;
|
574
|
+
int slop;
|
575
|
+
bool in_order : 1;
|
576
|
+
} FrtSpanNearQuery;
|
577
|
+
|
578
|
+
extern FrtQuery *frt_spannq_new(int slop, bool in_order);
|
579
|
+
extern FrtQuery *frt_spannq_add_clause(FrtQuery *self, FrtQuery *clause);
|
580
|
+
extern FrtQuery *frt_spannq_add_clause_nr(FrtQuery *self, FrtQuery *clause);
|
581
|
+
|
582
|
+
/***************************************************************************
|
583
|
+
* FrtSpanNotQuery
|
584
|
+
***************************************************************************/
|
585
|
+
|
586
|
+
typedef struct FrtSpanNotQuery
|
587
|
+
{
|
588
|
+
FrtSpanQuery super;
|
589
|
+
FrtQuery *inc;
|
590
|
+
FrtQuery *exc;
|
591
|
+
} FrtSpanNotQuery;
|
592
|
+
|
593
|
+
extern FrtQuery *frt_spanxq_new(FrtQuery *inc, FrtQuery *exc);
|
594
|
+
extern FrtQuery *frt_spanxq_new_nr(FrtQuery *inc, FrtQuery *exc);
|
595
|
+
|
596
|
+
|
597
|
+
/***************************************************************************
|
598
|
+
* FrtSpanPrefixQuery
|
599
|
+
***************************************************************************/
|
600
|
+
|
601
|
+
#define FRT_SPAN_PREFIX_QUERY_MAX_TERMS 256
|
602
|
+
|
603
|
+
typedef struct FrtSpanPrefixQuery
|
604
|
+
{
|
605
|
+
FrtSpanQuery super;
|
606
|
+
char *prefix;
|
607
|
+
int max_terms;
|
608
|
+
} FrtSpanPrefixQuery;
|
609
|
+
|
610
|
+
extern FrtQuery *frt_spanprq_new(FrtSymbol field, const char *prefix);
|
611
|
+
|
612
|
+
|
613
|
+
/***************************************************************************
|
614
|
+
*
|
615
|
+
* FrtScorer
|
616
|
+
*
|
617
|
+
***************************************************************************/
|
618
|
+
|
619
|
+
#define FRT_SCORER_NULLIFY(mscorer) do {\
|
620
|
+
(mscorer)->destroy(mscorer);\
|
621
|
+
(mscorer) = NULL;\
|
622
|
+
} while (0)
|
623
|
+
|
624
|
+
struct FrtScorer
|
625
|
+
{
|
626
|
+
FrtSimilarity *similarity;
|
627
|
+
int doc;
|
628
|
+
float (*score)(FrtScorer *self);
|
629
|
+
bool (*next)(FrtScorer *self);
|
630
|
+
bool (*skip_to)(FrtScorer *self, int doc_num);
|
631
|
+
FrtExplanation *(*explain)(FrtScorer *self, int doc_num);
|
632
|
+
void (*destroy)(FrtScorer *self);
|
633
|
+
};
|
634
|
+
|
635
|
+
#define frt_scorer_new(type, similarity) frt_scorer_create(sizeof(type), similarity)
|
636
|
+
/* Internal FrtScorer Function */
|
637
|
+
extern void frt_scorer_destroy_i(FrtScorer *self);
|
638
|
+
extern FrtScorer *frt_scorer_create(size_t size, FrtSimilarity *similarity);
|
639
|
+
extern bool frt_scorer_less_than(void *p1, void *p2);
|
640
|
+
extern bool frt_scorer_doc_less_than(const FrtScorer *s1, const FrtScorer *s2);
|
641
|
+
extern int frt_scorer_doc_cmp(const void *p1, const void *p2);
|
642
|
+
|
643
|
+
/***************************************************************************
|
644
|
+
* FrtComparable
|
645
|
+
***************************************************************************/
|
646
|
+
|
647
|
+
typedef struct FrtComparable
|
648
|
+
{
|
649
|
+
int type;
|
650
|
+
union {
|
651
|
+
long l;
|
652
|
+
float f;
|
653
|
+
char *s;
|
654
|
+
void *p;
|
655
|
+
} val;
|
656
|
+
bool reverse : 1;
|
657
|
+
} FrtComparable;
|
658
|
+
|
659
|
+
/***************************************************************************
|
660
|
+
*
|
661
|
+
* FrtSort
|
662
|
+
*
|
663
|
+
***************************************************************************/
|
664
|
+
|
665
|
+
typedef enum
|
666
|
+
{
|
667
|
+
FRT_SORT_TYPE_SCORE,
|
668
|
+
FRT_SORT_TYPE_DOC,
|
669
|
+
FRT_SORT_TYPE_BYTE,
|
670
|
+
FRT_SORT_TYPE_INTEGER,
|
671
|
+
FRT_SORT_TYPE_FLOAT,
|
672
|
+
FRT_SORT_TYPE_STRING,
|
673
|
+
FRT_SORT_TYPE_AUTO
|
674
|
+
} SortType;
|
675
|
+
|
676
|
+
/***************************************************************************
|
677
|
+
* FrtSortField
|
678
|
+
***************************************************************************/
|
679
|
+
|
680
|
+
typedef struct FrtSortField
|
681
|
+
{
|
682
|
+
const FrtFieldIndexClass *field_index_class;
|
683
|
+
FrtSymbol field;
|
684
|
+
SortType type;
|
685
|
+
bool reverse : 1;
|
686
|
+
int (*compare)(void *index_ptr, FrtHit *hit1, FrtHit *hit2);
|
687
|
+
void (*get_val)(void *index_ptr, FrtHit *hit1, FrtComparable *comparable);
|
688
|
+
} FrtSortField;
|
689
|
+
|
690
|
+
extern FrtSortField *frt_sort_field_new(FrtSymbol field,
|
691
|
+
SortType type,
|
692
|
+
bool reverse);
|
693
|
+
extern FrtSortField *frt_sort_field_score_new(bool reverse);
|
694
|
+
extern FrtSortField *frt_sort_field_doc_new(bool reverse);
|
695
|
+
extern FrtSortField *frt_sort_field_int_new(FrtSymbol field, bool reverse);
|
696
|
+
extern FrtSortField *frt_sort_field_byte_new(FrtSymbol field, bool reverse);
|
697
|
+
extern FrtSortField *frt_sort_field_float_new(FrtSymbol field, bool reverse);
|
698
|
+
extern FrtSortField *frt_sort_field_string_new(FrtSymbol field, bool reverse);
|
699
|
+
extern FrtSortField *frt_sort_field_auto_new(FrtSymbol field, bool reverse);
|
700
|
+
extern void frt_sort_field_destroy(void *p);
|
701
|
+
extern char *frt_sort_field_to_s(FrtSortField *self);
|
702
|
+
|
703
|
+
extern const FrtSortField FRT_SORT_FIELD_SCORE;
|
704
|
+
extern const FrtSortField FRT_SORT_FIELD_SCORE_REV;
|
705
|
+
extern const FrtSortField FRT_SORT_FIELD_DOC;
|
706
|
+
extern const FrtSortField FRT_SORT_FIELD_DOC_REV;
|
707
|
+
|
708
|
+
/***************************************************************************
|
709
|
+
* FrtSort
|
710
|
+
***************************************************************************/
|
711
|
+
|
712
|
+
typedef struct FrtSort
|
713
|
+
{
|
714
|
+
FrtSortField **sort_fields;
|
715
|
+
int size;
|
716
|
+
int capa;
|
717
|
+
int start;
|
718
|
+
bool destroy_all : 1;
|
719
|
+
} FrtSort;
|
720
|
+
|
721
|
+
extern FrtSort *frt_sort_new();
|
722
|
+
extern void frt_sort_destroy(void *p);
|
723
|
+
extern void frt_sort_add_sort_field(FrtSort *self, FrtSortField *sf);
|
724
|
+
extern void frt_sort_clear(FrtSort *self);
|
725
|
+
extern char *frt_sort_to_s(FrtSort *self);
|
726
|
+
|
727
|
+
/***************************************************************************
|
728
|
+
* FieldSortedHitQueue
|
729
|
+
***************************************************************************/
|
730
|
+
|
731
|
+
extern FrtHit *frt_fshq_pq_pop(FrtPriorityQueue *pq);
|
732
|
+
extern void frt_fshq_pq_down(FrtPriorityQueue *pq);
|
733
|
+
extern void frt_fshq_pq_insert(FrtPriorityQueue *pq, FrtHit *hit);
|
734
|
+
extern void frt_fshq_pq_destroy(FrtPriorityQueue *pq);
|
735
|
+
extern FrtPriorityQueue *frt_fshq_pq_new(int size, FrtSort *sort, FrtIndexReader *ir);
|
736
|
+
extern FrtHit *frt_fshq_pq_pop_fd(FrtPriorityQueue *pq);
|
737
|
+
|
738
|
+
/***************************************************************************
|
739
|
+
* FrtFieldDoc
|
740
|
+
***************************************************************************/
|
741
|
+
|
742
|
+
typedef struct FrtFieldDoc
|
743
|
+
{
|
744
|
+
FrtHit hit;
|
745
|
+
int size;
|
746
|
+
FrtComparable comparables[1];
|
747
|
+
} FrtFieldDoc;
|
748
|
+
|
749
|
+
extern void frt_fd_destroy(FrtFieldDoc *fd);
|
750
|
+
|
751
|
+
/***************************************************************************
|
752
|
+
* FieldDocSortedHitQueue
|
753
|
+
***************************************************************************/
|
754
|
+
|
755
|
+
extern bool frt_fdshq_lt(FrtFieldDoc *fd1, FrtFieldDoc *fd2);
|
756
|
+
|
757
|
+
/***************************************************************************
|
758
|
+
*
|
759
|
+
* FrtSearcher
|
760
|
+
*
|
761
|
+
***************************************************************************/
|
762
|
+
|
763
|
+
typedef float (*frt_filter_ft)(int doc_num, float score, FrtSearcher *self, void *arg);
|
764
|
+
|
765
|
+
typedef struct FrtPostFilter
|
766
|
+
{
|
767
|
+
float (*filter_func)(int doc_num, float score, FrtSearcher *self, void *arg);
|
768
|
+
void *arg;
|
769
|
+
} FrtPostFilter;
|
770
|
+
|
771
|
+
struct FrtSearcher
|
772
|
+
{
|
773
|
+
FrtSimilarity *similarity;
|
774
|
+
int (*doc_freq)(FrtSearcher *self, FrtSymbol field,
|
775
|
+
const char *term);
|
776
|
+
FrtDocument *(*get_doc)(FrtSearcher *self, int doc_num);
|
777
|
+
FrtLazyDoc *(*get_lazy_doc)(FrtSearcher *self, int doc_num);
|
778
|
+
int (*max_doc)(FrtSearcher *self);
|
779
|
+
FrtWeight *(*create_weight)(FrtSearcher *self, FrtQuery *query);
|
780
|
+
FrtTopDocs *(*search)(FrtSearcher *self, FrtQuery *query, int first_doc,
|
781
|
+
int num_docs, FrtFilter *filter, FrtSort *sort,
|
782
|
+
FrtPostFilter *post_filter,
|
783
|
+
bool load_fields);
|
784
|
+
FrtTopDocs *(*search_w)(FrtSearcher *self, FrtWeight *weight, int first_doc,
|
785
|
+
int num_docs, FrtFilter *filter, FrtSort *sort,
|
786
|
+
FrtPostFilter *post_filter,
|
787
|
+
bool load_fields);
|
788
|
+
void (*search_each)(FrtSearcher *self, FrtQuery *query, FrtFilter *filter,
|
789
|
+
FrtPostFilter *post_filter,
|
790
|
+
void (*fn)(FrtSearcher *, int, float, void *),
|
791
|
+
void *arg);
|
792
|
+
void (*search_each_w)(FrtSearcher *self, FrtWeight *weight,
|
793
|
+
FrtFilter *filter,
|
794
|
+
FrtPostFilter *post_filter,
|
795
|
+
void (*fn)(FrtSearcher *, int, float, void *),
|
796
|
+
void *arg);
|
797
|
+
/*
|
798
|
+
* Scan the index for all documents that match a query and write the
|
799
|
+
* results to a buffer. It will stop scanning once the limit is reached
|
800
|
+
* and it starts scanning from offset_docnum.
|
801
|
+
*
|
802
|
+
* Note: Unlike the offset_docnum in other search methods, this
|
803
|
+
* offset_docnum refers to document number and not hit.
|
804
|
+
*/
|
805
|
+
int (*search_unscored)(FrtSearcher *searcher,
|
806
|
+
FrtQuery *query,
|
807
|
+
int *buf,
|
808
|
+
int limit,
|
809
|
+
int offset_docnum);
|
810
|
+
int (*search_unscored_w)(FrtSearcher *searcher,
|
811
|
+
FrtWeight *weight,
|
812
|
+
int *buf,
|
813
|
+
int limit,
|
814
|
+
int offset_docnum);
|
815
|
+
FrtQuery *(*rewrite)(FrtSearcher *self, FrtQuery *original);
|
816
|
+
FrtExplanation *(*explain)(FrtSearcher *self, FrtQuery *query, int doc_num);
|
817
|
+
FrtExplanation *(*explain_w)(FrtSearcher *self, FrtWeight *weight, int doc_num);
|
818
|
+
FrtTermVector *(*get_term_vector)(FrtSearcher *self, const int doc_num,
|
819
|
+
FrtSymbol field);
|
820
|
+
FrtSimilarity *(*get_similarity)(FrtSearcher *self);
|
821
|
+
void (*close)(FrtSearcher *self);
|
822
|
+
};
|
823
|
+
|
824
|
+
#define frt_searcher_doc_freq(s, t) s->doc_freq(s, t)
|
825
|
+
#define frt_searcher_get_doc(s, dn) s->get_doc(s, dn)
|
826
|
+
#define frt_searcher_get_lazy_doc(s, dn) s->get_lazy_doc(s, dn)
|
827
|
+
#define frt_searcher_max_doc(s) s->max_doc(s)
|
828
|
+
#define frt_searcher_rewrite(s, q) s->rewrite(s, q)
|
829
|
+
#define frt_searcher_explain(s, q, dn) s->explain(s, q, dn)
|
830
|
+
#define frt_searcher_explain_w(s, q, dn) s->explain_w(s, q, dn)
|
831
|
+
#define frt_searcher_get_similarity(s) s->get_similarity(s)
|
832
|
+
#define frt_searcher_close(s) s->close(s)
|
833
|
+
#define frt_searcher_search(s, q, fd, nd, filt, sort, ff)\
|
834
|
+
s->search(s, q, fd, nd, filt, sort, ff, false)
|
835
|
+
#define frt_searcher_search_fd(s, q, fd, nd, filt, sort, ff)\
|
836
|
+
s->search(s, q, fd, nd, filt, sort, ff, true)
|
837
|
+
#define frt_searcher_search_each(s, q, filt, ff, fn, arg)\
|
838
|
+
s->search_each(s, q, filt, ff, fn, arg)
|
839
|
+
#define frt_searcher_search_unscored(s, q, buf, limit, offset_docnum)\
|
840
|
+
s->search_unscored(s, q, buf, limit, offset_docnum)
|
841
|
+
|
842
|
+
|
843
|
+
extern FrtMatchVector *frt_searcher_get_match_vector(FrtSearcher *self,
|
844
|
+
FrtQuery *query,
|
845
|
+
const int doc_num,
|
846
|
+
FrtSymbol field);
|
847
|
+
extern char **frt_searcher_highlight(FrtSearcher *self,
|
848
|
+
FrtQuery *query,
|
849
|
+
const int doc_num,
|
850
|
+
FrtSymbol field,
|
851
|
+
const int excerpt_len,
|
852
|
+
const int num_excerpts,
|
853
|
+
const char *pre_tag,
|
854
|
+
const char *post_tag,
|
855
|
+
const char *ellipsis);
|
856
|
+
|
857
|
+
/***************************************************************************
|
858
|
+
*
|
859
|
+
* FrtIndexSearcher
|
860
|
+
*
|
861
|
+
***************************************************************************/
|
862
|
+
|
863
|
+
typedef struct FrtIndexSearcher {
|
864
|
+
FrtSearcher super;
|
865
|
+
FrtIndexReader *ir;
|
866
|
+
bool close_ir : 1;
|
867
|
+
} FrtIndexSearcher;
|
868
|
+
|
869
|
+
extern FrtSearcher *frt_isea_new(FrtIndexReader *ir);
|
870
|
+
extern int frt_isea_doc_freq(FrtSearcher *self, FrtSymbol field, const char *term);
|
871
|
+
|
872
|
+
|
873
|
+
|
874
|
+
/***************************************************************************
|
875
|
+
*
|
876
|
+
* FrtMultiSearcher
|
877
|
+
*
|
878
|
+
***************************************************************************/
|
879
|
+
|
880
|
+
typedef struct FrtMultiSearcher
|
881
|
+
{
|
882
|
+
FrtSearcher super;
|
883
|
+
int s_cnt;
|
884
|
+
FrtSearcher **searchers;
|
885
|
+
int *starts;
|
886
|
+
int max_doc;
|
887
|
+
bool close_subs : 1;
|
888
|
+
} FrtMultiSearcher;
|
889
|
+
|
890
|
+
extern FrtSearcher *frt_msea_new(FrtSearcher **searchers, int s_cnt, bool close_subs);
|
891
|
+
|
892
|
+
/***************************************************************************
|
893
|
+
*
|
894
|
+
* FrtQParser
|
895
|
+
*
|
896
|
+
***************************************************************************/
|
897
|
+
|
898
|
+
#define FRT_QP_CONC_WORDS 2
|
899
|
+
#define FRT_QP_MAX_CLAUSES 512
|
900
|
+
typedef struct FrtFieldStack {
|
901
|
+
FrtHashSet *fields;
|
902
|
+
struct FrtFieldStack *next;
|
903
|
+
bool destroy : 1;
|
904
|
+
} FrtFieldStack;
|
905
|
+
|
906
|
+
typedef struct FrtQueryParser
|
907
|
+
{
|
908
|
+
frt_mutex_t mutex;
|
909
|
+
int def_slop;
|
910
|
+
int max_clauses;
|
911
|
+
int phq_pos_inc;
|
912
|
+
char *qstr;
|
913
|
+
char *qstrp;
|
914
|
+
char buf[FRT_QP_CONC_WORDS][FRT_MAX_WORD_SIZE];
|
915
|
+
char *dynbuf;
|
916
|
+
int buf_index;
|
917
|
+
FrtHash *field_cache;
|
918
|
+
FrtHashSet *def_fields;
|
919
|
+
FrtHashSet *all_fields;
|
920
|
+
FrtHashSet *tokenized_fields;
|
921
|
+
FrtHashSet *fields;
|
922
|
+
FrtFieldStack *fields_top;
|
923
|
+
FrtAnalyzer *analyzer;
|
924
|
+
FrtHash *ts_cache;
|
925
|
+
FrtQuery *result;
|
926
|
+
FrtTokenStream *non_tokenizer;
|
927
|
+
bool or_default : 1;
|
928
|
+
bool wild_lower : 1;
|
929
|
+
bool clean_str : 1;
|
930
|
+
bool handle_parse_errors : 1;
|
931
|
+
bool allow_any_fields : 1;
|
932
|
+
bool destruct : 1;
|
933
|
+
bool recovering : 1;
|
934
|
+
bool use_keywords : 1;
|
935
|
+
bool use_typed_range_query : 1;
|
936
|
+
} FrtQueryParser;
|
937
|
+
typedef FrtQueryParser FrtQParser; /* QParser is an alias for QueryParser */
|
938
|
+
|
939
|
+
extern FrtQParser *frt_qp_new(FrtAnalyzer *analyzer);
|
940
|
+
extern void frt_qp_add_field(FrtQParser *self, FrtSymbol field,
|
941
|
+
bool is_default, bool is_tokenized);
|
942
|
+
extern void frt_qp_destroy(FrtQParser *self);
|
943
|
+
extern FrtQuery *frt_qp_parse(FrtQParser *self, char *qstr);
|
944
|
+
extern char *frt_qp_clean_str(char *str);
|
945
|
+
|
946
|
+
extern float frt_qp_default_fuzzy_min_sim;
|
947
|
+
extern int frt_qp_default_fuzzy_pre_len;
|
948
|
+
|
949
|
+
#ifdef __cplusplus
|
950
|
+
} // extern "C"
|
951
|
+
#endif
|
952
|
+
|
953
|
+
#endif
|