isomorfeus-ferret 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +612 -0
- data/README.md +44 -0
- data/ext/isomorfeus_ferret_ext/benchmark.c +223 -0
- data/ext/isomorfeus_ferret_ext/benchmark.h +45 -0
- data/ext/isomorfeus_ferret_ext/benchmarks_all.h +25 -0
- data/ext/isomorfeus_ferret_ext/bm_bitvector.c +123 -0
- data/ext/isomorfeus_ferret_ext/bm_hash.c +118 -0
- data/ext/isomorfeus_ferret_ext/bm_micro_string.c +40 -0
- data/ext/isomorfeus_ferret_ext/bm_store.c +93 -0
- data/ext/isomorfeus_ferret_ext/email.rl +21 -0
- data/ext/isomorfeus_ferret_ext/extconf.rb +5 -0
- data/ext/isomorfeus_ferret_ext/fio_tmpfile.h +53 -0
- data/ext/isomorfeus_ferret_ext/frb_analysis.c +2577 -0
- data/ext/isomorfeus_ferret_ext/frb_index.c +3457 -0
- data/ext/isomorfeus_ferret_ext/frb_lang.c +9 -0
- data/ext/isomorfeus_ferret_ext/frb_lang.h +17 -0
- data/ext/isomorfeus_ferret_ext/frb_qparser.c +629 -0
- data/ext/isomorfeus_ferret_ext/frb_search.c +4460 -0
- data/ext/isomorfeus_ferret_ext/frb_store.c +515 -0
- data/ext/isomorfeus_ferret_ext/frb_threading.h +30 -0
- data/ext/isomorfeus_ferret_ext/frb_utils.c +1127 -0
- data/ext/isomorfeus_ferret_ext/frt_analysis.c +1644 -0
- data/ext/isomorfeus_ferret_ext/frt_analysis.h +247 -0
- data/ext/isomorfeus_ferret_ext/frt_array.c +124 -0
- data/ext/isomorfeus_ferret_ext/frt_array.h +54 -0
- data/ext/isomorfeus_ferret_ext/frt_bitvector.c +95 -0
- data/ext/isomorfeus_ferret_ext/frt_bitvector.h +586 -0
- data/ext/isomorfeus_ferret_ext/frt_compound_io.c +374 -0
- data/ext/isomorfeus_ferret_ext/frt_config.h +44 -0
- data/ext/isomorfeus_ferret_ext/frt_document.c +134 -0
- data/ext/isomorfeus_ferret_ext/frt_document.h +52 -0
- data/ext/isomorfeus_ferret_ext/frt_except.c +95 -0
- data/ext/isomorfeus_ferret_ext/frt_except.h +188 -0
- data/ext/isomorfeus_ferret_ext/frt_field_index.c +233 -0
- data/ext/isomorfeus_ferret_ext/frt_field_index.h +42 -0
- data/ext/isomorfeus_ferret_ext/frt_filter.c +157 -0
- data/ext/isomorfeus_ferret_ext/frt_fs_store.c +502 -0
- data/ext/isomorfeus_ferret_ext/frt_global.c +427 -0
- data/ext/isomorfeus_ferret_ext/frt_global.h +290 -0
- data/ext/isomorfeus_ferret_ext/frt_hash.c +518 -0
- data/ext/isomorfeus_ferret_ext/frt_hash.h +466 -0
- data/ext/isomorfeus_ferret_ext/frt_hashset.c +191 -0
- data/ext/isomorfeus_ferret_ext/frt_hashset.h +206 -0
- data/ext/isomorfeus_ferret_ext/frt_helper.c +62 -0
- data/ext/isomorfeus_ferret_ext/frt_helper.h +13 -0
- data/ext/isomorfeus_ferret_ext/frt_ind.c +353 -0
- data/ext/isomorfeus_ferret_ext/frt_ind.h +54 -0
- data/ext/isomorfeus_ferret_ext/frt_index.c +6377 -0
- data/ext/isomorfeus_ferret_ext/frt_index.h +880 -0
- data/ext/isomorfeus_ferret_ext/frt_lang.c +104 -0
- data/ext/isomorfeus_ferret_ext/frt_lang.h +44 -0
- data/ext/isomorfeus_ferret_ext/frt_mempool.c +87 -0
- data/ext/isomorfeus_ferret_ext/frt_mempool.h +33 -0
- data/ext/isomorfeus_ferret_ext/frt_multimapper.c +349 -0
- data/ext/isomorfeus_ferret_ext/frt_multimapper.h +52 -0
- data/ext/isomorfeus_ferret_ext/frt_posh.c +1006 -0
- data/ext/isomorfeus_ferret_ext/frt_posh.h +973 -0
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +147 -0
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +147 -0
- data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +1612 -0
- data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +157 -0
- data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +209 -0
- data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +281 -0
- data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +147 -0
- data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +672 -0
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +3084 -0
- data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +1182 -0
- data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +98 -0
- data/ext/isomorfeus_ferret_ext/frt_q_range.c +665 -0
- data/ext/isomorfeus_ferret_ext/frt_q_span.c +2386 -0
- data/ext/isomorfeus_ferret_ext/frt_q_term.c +311 -0
- data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +166 -0
- data/ext/isomorfeus_ferret_ext/frt_ram_store.c +460 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner.c +899 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner.h +28 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +6705 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +4419 -0
- data/ext/isomorfeus_ferret_ext/frt_search.c +1824 -0
- data/ext/isomorfeus_ferret_ext/frt_search.h +924 -0
- data/ext/isomorfeus_ferret_ext/frt_similarity.c +150 -0
- data/ext/isomorfeus_ferret_ext/frt_similarity.h +79 -0
- data/ext/isomorfeus_ferret_ext/frt_sort.c +796 -0
- data/ext/isomorfeus_ferret_ext/frt_stopwords.c +395 -0
- data/ext/isomorfeus_ferret_ext/frt_store.c +680 -0
- data/ext/isomorfeus_ferret_ext/frt_store.h +789 -0
- data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +72 -0
- data/ext/isomorfeus_ferret_ext/frt_threading.h +23 -0
- data/ext/isomorfeus_ferret_ext/frt_win32.h +54 -0
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +409 -0
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +95 -0
- data/ext/isomorfeus_ferret_ext/libstemmer.c +93 -0
- data/ext/isomorfeus_ferret_ext/libstemmer.h +73 -0
- data/ext/isomorfeus_ferret_ext/q_parser.y +1366 -0
- data/ext/isomorfeus_ferret_ext/scanner.h +28 -0
- data/ext/isomorfeus_ferret_ext/scanner.in +43 -0
- data/ext/isomorfeus_ferret_ext/scanner.rl +84 -0
- data/ext/isomorfeus_ferret_ext/scanner_mb.rl +200 -0
- data/ext/isomorfeus_ferret_ext/scanner_utf8.rl +85 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +324 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +610 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +1104 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +749 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +1233 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +490 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +1217 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +1052 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +283 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +735 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +1003 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +1079 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +293 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +984 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +686 -0
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.c +325 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.c +620 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.c +1111 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.c +754 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.c +1242 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.c +495 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.c +1220 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.c +1059 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.c +285 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.c +741 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.c +1009 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.c +990 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.c +680 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.c +1083 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.c +294 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.c +2191 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_api.c +66 -0
- data/ext/isomorfeus_ferret_ext/stem_api.h +26 -0
- data/ext/isomorfeus_ferret_ext/stem_header.h +57 -0
- data/ext/isomorfeus_ferret_ext/stem_modules.h +190 -0
- data/ext/isomorfeus_ferret_ext/stem_modules.txt +50 -0
- data/ext/isomorfeus_ferret_ext/stem_utilities.c +478 -0
- data/ext/isomorfeus_ferret_ext/test.c +850 -0
- data/ext/isomorfeus_ferret_ext/test.h +416 -0
- data/ext/isomorfeus_ferret_ext/test_1710.c +63 -0
- data/ext/isomorfeus_ferret_ext/test_analysis.c +1221 -0
- data/ext/isomorfeus_ferret_ext/test_array.c +272 -0
- data/ext/isomorfeus_ferret_ext/test_bitvector.c +600 -0
- data/ext/isomorfeus_ferret_ext/test_compound_io.c +170 -0
- data/ext/isomorfeus_ferret_ext/test_document.c +156 -0
- data/ext/isomorfeus_ferret_ext/test_except.c +244 -0
- data/ext/isomorfeus_ferret_ext/test_fields.c +522 -0
- data/ext/isomorfeus_ferret_ext/test_file_deleter.c +185 -0
- data/ext/isomorfeus_ferret_ext/test_filter.c +331 -0
- data/ext/isomorfeus_ferret_ext/test_fs_store.c +25 -0
- data/ext/isomorfeus_ferret_ext/test_global.c +299 -0
- data/ext/isomorfeus_ferret_ext/test_hash.c +485 -0
- data/ext/isomorfeus_ferret_ext/test_hashset.c +288 -0
- data/ext/isomorfeus_ferret_ext/test_helper.c +47 -0
- data/ext/isomorfeus_ferret_ext/test_highlighter.c +548 -0
- data/ext/isomorfeus_ferret_ext/test_index.c +2323 -0
- data/ext/isomorfeus_ferret_ext/test_lang.c +74 -0
- data/ext/isomorfeus_ferret_ext/test_mempool.c +102 -0
- data/ext/isomorfeus_ferret_ext/test_multimapper.c +64 -0
- data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +213 -0
- data/ext/isomorfeus_ferret_ext/test_q_const_score.c +84 -0
- data/ext/isomorfeus_ferret_ext/test_q_filtered.c +61 -0
- data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +241 -0
- data/ext/isomorfeus_ferret_ext/test_q_parser.c +464 -0
- data/ext/isomorfeus_ferret_ext/test_q_span.c +575 -0
- data/ext/isomorfeus_ferret_ext/test_ram_store.c +77 -0
- data/ext/isomorfeus_ferret_ext/test_search.c +1874 -0
- data/ext/isomorfeus_ferret_ext/test_segments.c +167 -0
- data/ext/isomorfeus_ferret_ext/test_similarity.c +25 -0
- data/ext/isomorfeus_ferret_ext/test_sort.c +333 -0
- data/ext/isomorfeus_ferret_ext/test_store.c +591 -0
- data/ext/isomorfeus_ferret_ext/test_store.h +3 -0
- data/ext/isomorfeus_ferret_ext/test_term.c +351 -0
- data/ext/isomorfeus_ferret_ext/test_term_vectors.c +373 -0
- data/ext/isomorfeus_ferret_ext/test_test.c +83 -0
- data/ext/isomorfeus_ferret_ext/test_threading.c +188 -0
- data/ext/isomorfeus_ferret_ext/testhelper.c +561 -0
- data/ext/isomorfeus_ferret_ext/testhelper.h +25 -0
- data/ext/isomorfeus_ferret_ext/tests_all.h +87 -0
- data/ext/isomorfeus_ferret_ext/uchar-ucs4.rl +1854 -0
- data/ext/isomorfeus_ferret_ext/uchar-utf8.rl +1999 -0
- data/ext/isomorfeus_ferret_ext/url.rl +27 -0
- data/ext/isomorfeus_ferret_ext/word_list.h +15156 -0
- data/lib/isomorfeus/ferret/document.rb +132 -0
- data/lib/isomorfeus/ferret/field_symbol.rb +85 -0
- data/lib/isomorfeus/ferret/index/field_infos.rb +48 -0
- data/lib/isomorfeus/ferret/index/index.rb +970 -0
- data/lib/isomorfeus/ferret/monitor.rb +323 -0
- data/lib/isomorfeus/ferret/stdlib_patches.rb +151 -0
- data/lib/isomorfeus/ferret/version.rb +5 -0
- data/lib/isomorfeus-ferret.rb +8 -0
- metadata +307 -0
@@ -0,0 +1,924 @@
|
|
1
|
+
#ifndef FRT_SEARCH_H
|
2
|
+
#define FRT_SEARCH_H
|
3
|
+
|
4
|
+
#include "frt_priorityqueue.h"
|
5
|
+
#include "frt_field_index.h"
|
6
|
+
#include "frt_bitvector.h"
|
7
|
+
#include "frt_similarity.h"
|
8
|
+
|
9
|
+
typedef struct FrtQuery FrtQuery;
|
10
|
+
typedef struct FrtWeight FrtWeight;
|
11
|
+
typedef struct FrtScorer FrtScorer;
|
12
|
+
|
13
|
+
/***************************************************************************
|
14
|
+
*
|
15
|
+
* FrtExplanation
|
16
|
+
*
|
17
|
+
***************************************************************************/
|
18
|
+
|
19
|
+
#define FRT_EXPLANATION_DETAILS_START_SIZE 4
|
20
|
+
typedef struct FrtExplanation
|
21
|
+
{
|
22
|
+
float value;
|
23
|
+
char *description;
|
24
|
+
struct FrtExplanation **details;
|
25
|
+
} FrtExplanation;
|
26
|
+
|
27
|
+
extern FrtExplanation *frt_expl_new(float value, const char *description, ...);
|
28
|
+
extern void frt_expl_destroy(FrtExplanation *expl);
|
29
|
+
extern FrtExplanation *frt_expl_add_detail(FrtExplanation *expl, FrtExplanation *detail);
|
30
|
+
extern char *frt_expl_to_s_depth(FrtExplanation *expl, int depth);
|
31
|
+
extern char *frt_expl_to_html(FrtExplanation *expl);
|
32
|
+
|
33
|
+
#define frt_expl_to_s(expl) frt_expl_to_s_depth(expl, 0)
|
34
|
+
|
35
|
+
/***************************************************************************
|
36
|
+
*
|
37
|
+
* Highlighter
|
38
|
+
*
|
39
|
+
***************************************************************************/
|
40
|
+
typedef struct FrtSearcher FrtSearcher;
|
41
|
+
|
42
|
+
typedef struct FrtMatchRange
|
43
|
+
{
|
44
|
+
int start;
|
45
|
+
int end;
|
46
|
+
int start_offset;
|
47
|
+
int end_offset;
|
48
|
+
double score;
|
49
|
+
} FrtMatchRange;
|
50
|
+
|
51
|
+
#define FRT_MATCH_VECTOR_INIT_CAPA 8
|
52
|
+
typedef struct FrtMatchVector
|
53
|
+
{
|
54
|
+
int size;
|
55
|
+
int capa;
|
56
|
+
FrtMatchRange *matches;
|
57
|
+
} FrtMatchVector;
|
58
|
+
|
59
|
+
extern FrtMatchVector *frt_matchv_new();
|
60
|
+
extern FrtMatchVector *frt_matchv_add(FrtMatchVector *mp, int start, int end);
|
61
|
+
extern FrtMatchVector *frt_matchv_sort(FrtMatchVector *self);
|
62
|
+
extern void frt_matchv_destroy(FrtMatchVector *self);
|
63
|
+
extern FrtMatchVector *frt_matchv_compact(FrtMatchVector *self);
|
64
|
+
extern FrtMatchVector *frt_matchv_compact_with_breaks(FrtMatchVector *self);
|
65
|
+
|
66
|
+
/***************************************************************************
|
67
|
+
*
|
68
|
+
* FrtHit
|
69
|
+
*
|
70
|
+
***************************************************************************/
|
71
|
+
|
72
|
+
typedef struct FrtHit
|
73
|
+
{
|
74
|
+
int doc;
|
75
|
+
float score;
|
76
|
+
} FrtHit;
|
77
|
+
|
78
|
+
/***************************************************************************
|
79
|
+
*
|
80
|
+
* FrtTopDocs
|
81
|
+
*
|
82
|
+
***************************************************************************/
|
83
|
+
|
84
|
+
typedef struct FrtTopDocs
|
85
|
+
{
|
86
|
+
int total_hits;
|
87
|
+
int size;
|
88
|
+
FrtHit **hits;
|
89
|
+
float max_score;
|
90
|
+
} FrtTopDocs;
|
91
|
+
|
92
|
+
extern FrtTopDocs *frt_td_new(int total_hits, int size, FrtHit **hits,
|
93
|
+
float max_score);
|
94
|
+
extern void frt_td_destroy(FrtTopDocs *td);
|
95
|
+
extern char *frt_td_to_s(FrtTopDocs *td);
|
96
|
+
|
97
|
+
/***************************************************************************
|
98
|
+
*
|
99
|
+
* FrtFilter
|
100
|
+
*
|
101
|
+
***************************************************************************/
|
102
|
+
|
103
|
+
typedef struct FrtFilter
|
104
|
+
{
|
105
|
+
FrtSymbol name;
|
106
|
+
FrtHash *cache;
|
107
|
+
FrtBitVector *(*get_bv_i)(struct FrtFilter *self, FrtIndexReader *ir);
|
108
|
+
char *(*to_s)(struct FrtFilter *self);
|
109
|
+
unsigned long long (*hash)(struct FrtFilter *self);
|
110
|
+
int (*eq)(struct FrtFilter *self, struct FrtFilter *o);
|
111
|
+
void (*destroy_i)(struct FrtFilter *self);
|
112
|
+
int ref_cnt;
|
113
|
+
} FrtFilter;
|
114
|
+
|
115
|
+
#define filt_new(type) frt_filt_create(sizeof(type), rb_intern(#type))
|
116
|
+
extern FrtFilter *frt_filt_create(size_t size, FrtSymbol name);
|
117
|
+
extern FrtBitVector *frt_filt_get_bv(FrtFilter *filt, FrtIndexReader *ir);
|
118
|
+
extern void frt_filt_destroy_i(FrtFilter *filt);
|
119
|
+
extern void frt_filt_deref(FrtFilter *filt);
|
120
|
+
extern unsigned long long frt_filt_hash(FrtFilter *filt);
|
121
|
+
extern int frt_filt_eq(FrtFilter *filt, FrtFilter *o);
|
122
|
+
|
123
|
+
/***************************************************************************
|
124
|
+
*
|
125
|
+
* RangeFilter
|
126
|
+
*
|
127
|
+
***************************************************************************/
|
128
|
+
|
129
|
+
extern FrtFilter *frt_rfilt_new(FrtSymbol field,
|
130
|
+
const char *lower_term, const char *upper_term,
|
131
|
+
bool include_lower, bool include_upper);
|
132
|
+
|
133
|
+
/***************************************************************************
|
134
|
+
*
|
135
|
+
* TypedRangeFilter
|
136
|
+
*
|
137
|
+
***************************************************************************/
|
138
|
+
|
139
|
+
extern FrtFilter *frt_trfilt_new(FrtSymbol field,
|
140
|
+
const char *lower_term, const char *upper_term,
|
141
|
+
bool include_lower, bool include_upper);
|
142
|
+
|
143
|
+
/***************************************************************************
|
144
|
+
*
|
145
|
+
* QueryFilter
|
146
|
+
*
|
147
|
+
***************************************************************************/
|
148
|
+
|
149
|
+
extern FrtFilter *frt_qfilt_new(FrtQuery *query);
|
150
|
+
extern FrtFilter *frt_qfilt_new_nr(FrtQuery *query);
|
151
|
+
|
152
|
+
/***************************************************************************
|
153
|
+
*
|
154
|
+
* FrtWeight
|
155
|
+
*
|
156
|
+
***************************************************************************/
|
157
|
+
|
158
|
+
struct FrtWeight
|
159
|
+
{
|
160
|
+
float value;
|
161
|
+
float qweight;
|
162
|
+
float qnorm;
|
163
|
+
float idf;
|
164
|
+
FrtQuery *query;
|
165
|
+
FrtSimilarity *similarity;
|
166
|
+
FrtQuery *(*get_query)(FrtWeight *self);
|
167
|
+
float (*get_value)(FrtWeight *self);
|
168
|
+
void (*normalize)(FrtWeight *self, float normalization_factor);
|
169
|
+
FrtScorer *(*scorer)(FrtWeight *self, FrtIndexReader *ir);
|
170
|
+
FrtExplanation *(*explain)(FrtWeight *self, FrtIndexReader *ir, int doc_num);
|
171
|
+
float (*sum_of_squared_weights)(FrtWeight *self);
|
172
|
+
char *(*to_s)(FrtWeight *self);
|
173
|
+
void (*destroy)(FrtWeight *self);
|
174
|
+
};
|
175
|
+
|
176
|
+
#define w_new(type, query) frt_w_create(sizeof(type), query)
|
177
|
+
extern FrtWeight *frt_w_create(size_t size, FrtQuery *query);
|
178
|
+
extern void frt_w_destroy(FrtWeight *self);
|
179
|
+
extern FrtQuery *frt_w_get_query(FrtWeight *self);
|
180
|
+
extern float frt_w_get_value(FrtWeight *self);
|
181
|
+
extern float frt_w_sum_of_squared_weights(FrtWeight *self);
|
182
|
+
extern void frt_w_normalize(FrtWeight *self, float normalization_factor);
|
183
|
+
|
184
|
+
/***************************************************************************
|
185
|
+
*
|
186
|
+
* FrtQuery
|
187
|
+
*
|
188
|
+
***************************************************************************/
|
189
|
+
|
190
|
+
typedef enum
|
191
|
+
{
|
192
|
+
TERM_QUERY,
|
193
|
+
MULTI_TERM_QUERY,
|
194
|
+
BOOLEAN_QUERY,
|
195
|
+
PHRASE_QUERY,
|
196
|
+
CONSTANT_QUERY,
|
197
|
+
FILTERED_QUERY,
|
198
|
+
MATCH_ALL_QUERY,
|
199
|
+
RANGE_QUERY,
|
200
|
+
TYPED_RANGE_QUERY,
|
201
|
+
WILD_CARD_QUERY,
|
202
|
+
FUZZY_QUERY,
|
203
|
+
PREFIX_QUERY,
|
204
|
+
SPAN_TERM_QUERY,
|
205
|
+
SPAN_MULTI_TERM_QUERY,
|
206
|
+
SPAN_PREFIX_QUERY,
|
207
|
+
SPAN_FIRST_QUERY,
|
208
|
+
SPAN_OR_QUERY,
|
209
|
+
SPAN_NOT_QUERY,
|
210
|
+
SPAN_NEAR_QUERY
|
211
|
+
} FrtQueryType;
|
212
|
+
|
213
|
+
struct FrtQuery
|
214
|
+
{
|
215
|
+
int ref_cnt;
|
216
|
+
float boost;
|
217
|
+
FrtWeight *weight;
|
218
|
+
FrtQuery *(*rewrite)(FrtQuery *self, FrtIndexReader *ir);
|
219
|
+
void (*extract_terms)(FrtQuery *self, FrtHashSet *terms);
|
220
|
+
FrtSimilarity *(*get_similarity)(FrtQuery *self, FrtSearcher *searcher);
|
221
|
+
char *(*to_s)(FrtQuery *self, FrtSymbol field);
|
222
|
+
unsigned long long (*hash)(FrtQuery *self);
|
223
|
+
int (*eq)(FrtQuery *self, FrtQuery *o);
|
224
|
+
void (*destroy_i)(FrtQuery *self);
|
225
|
+
FrtWeight *(*create_weight_i)(FrtQuery *self, FrtSearcher *searcher);
|
226
|
+
FrtMatchVector *(*get_matchv_i)(FrtQuery *self, FrtMatchVector *mv, FrtTermVector *tv);
|
227
|
+
FrtQueryType type;
|
228
|
+
};
|
229
|
+
|
230
|
+
/* Internal FrtQuery Functions */
|
231
|
+
extern FrtSimilarity *frt_q_get_similarity_i(FrtQuery *self, FrtSearcher *searcher);
|
232
|
+
extern void frt_q_destroy_i(FrtQuery *self);
|
233
|
+
extern FrtWeight *frt_q_create_weight_unsup(FrtQuery *self, FrtSearcher *searcher);
|
234
|
+
|
235
|
+
extern void frt_q_deref(FrtQuery *self);
|
236
|
+
extern const char *frt_q_get_query_name(FrtQueryType type);
|
237
|
+
extern FrtWeight *frt_q_weight(FrtQuery *self, FrtSearcher *searcher);
|
238
|
+
extern FrtQuery *frt_q_combine(FrtQuery **queries, int q_cnt);
|
239
|
+
extern unsigned long long frt_q_hash(FrtQuery *self);
|
240
|
+
extern int frt_q_eq(FrtQuery *self, FrtQuery *o);
|
241
|
+
extern FrtQuery *frt_q_create(size_t size);
|
242
|
+
#define frt_q_new(type) frt_q_create(sizeof(type))
|
243
|
+
|
244
|
+
/***************************************************************************
|
245
|
+
* FrtTermQuery
|
246
|
+
***************************************************************************/
|
247
|
+
|
248
|
+
typedef struct FrtTermQuery
|
249
|
+
{
|
250
|
+
FrtQuery super;
|
251
|
+
FrtSymbol field;
|
252
|
+
char *term;
|
253
|
+
} FrtTermQuery;
|
254
|
+
|
255
|
+
FrtQuery *frt_tq_new(FrtSymbol field, const char *term);
|
256
|
+
|
257
|
+
/***************************************************************************
|
258
|
+
* FrtBooleanQuery
|
259
|
+
***************************************************************************/
|
260
|
+
|
261
|
+
/* *** FrtBooleanClause *** */
|
262
|
+
|
263
|
+
typedef enum
|
264
|
+
{
|
265
|
+
FRT_BC_SHOULD,
|
266
|
+
FRT_BC_MUST,
|
267
|
+
FRT_BC_MUST_NOT
|
268
|
+
} FrtBCType;
|
269
|
+
|
270
|
+
typedef struct FrtBooleanClause
|
271
|
+
{
|
272
|
+
int ref_cnt;
|
273
|
+
FrtQuery *query;
|
274
|
+
FrtBCType occur;
|
275
|
+
bool is_prohibited : 1;
|
276
|
+
bool is_required : 1;
|
277
|
+
} FrtBooleanClause;
|
278
|
+
|
279
|
+
extern FrtBooleanClause *frt_bc_new(FrtQuery *query, FrtBCType occur);
|
280
|
+
extern void frt_bc_deref(FrtBooleanClause *self);
|
281
|
+
extern void frt_bc_set_occur(FrtBooleanClause *self, FrtBCType occur);
|
282
|
+
|
283
|
+
/* *** FrtBooleanQuery *** */
|
284
|
+
|
285
|
+
#define FRT_DEFAULT_MAX_CLAUSE_COUNT 1024
|
286
|
+
#define FRT_BOOLEAN_CLAUSES_START_CAPA 4
|
287
|
+
#define FRT_QUERY_STRING_START_SIZE 64
|
288
|
+
|
289
|
+
typedef struct FrtBooleanQuery
|
290
|
+
{
|
291
|
+
FrtQuery super;
|
292
|
+
bool coord_disabled;
|
293
|
+
int max_clause_cnt;
|
294
|
+
int clause_cnt;
|
295
|
+
int clause_capa;
|
296
|
+
float original_boost;
|
297
|
+
FrtBooleanClause **clauses;
|
298
|
+
FrtSimilarity *similarity;
|
299
|
+
} FrtBooleanQuery;
|
300
|
+
|
301
|
+
extern FrtQuery *frt_bq_new(bool coord_disabled);
|
302
|
+
extern FrtQuery *frt_bq_new_max(bool coord_disabled, int max);
|
303
|
+
extern FrtBooleanClause *frt_bq_add_query(FrtQuery *self, FrtQuery *sub_query,
|
304
|
+
FrtBCType occur);
|
305
|
+
extern FrtBooleanClause *frt_bq_add_query_nr(FrtQuery *self, FrtQuery *sub_query,
|
306
|
+
FrtBCType occur);
|
307
|
+
extern FrtBooleanClause *frt_bq_add_clause(FrtQuery *self, FrtBooleanClause *bc);
|
308
|
+
extern FrtBooleanClause *frt_bq_add_clause_nr(FrtQuery *self, FrtBooleanClause *bc);
|
309
|
+
|
310
|
+
/***************************************************************************
|
311
|
+
* FrtPhraseQuery
|
312
|
+
***************************************************************************/
|
313
|
+
|
314
|
+
typedef struct FrtPhraseQuery
|
315
|
+
{
|
316
|
+
FrtQuery super;
|
317
|
+
int slop;
|
318
|
+
FrtSymbol field;
|
319
|
+
FrtPhrasePosition *positions;
|
320
|
+
int pos_cnt;
|
321
|
+
int pos_capa;
|
322
|
+
} FrtPhraseQuery;
|
323
|
+
|
324
|
+
extern FrtQuery *frt_phq_new(FrtSymbol field);
|
325
|
+
extern void frt_phq_add_term(FrtQuery *self, const char *term, int pos_inc);
|
326
|
+
extern void frt_phq_add_term_abs(FrtQuery *self, const char *term, int position);
|
327
|
+
extern void frt_phq_append_multi_term(FrtQuery *self, const char *term);
|
328
|
+
extern void frt_phq_set_slop(FrtQuery *self, int slop);
|
329
|
+
|
330
|
+
/***************************************************************************
|
331
|
+
* FrtMultiTermQuery
|
332
|
+
***************************************************************************/
|
333
|
+
|
334
|
+
#define MULTI_TERM_QUERY_MAX_TERMS 256
|
335
|
+
typedef struct FrtMultiTermQuery
|
336
|
+
{
|
337
|
+
FrtQuery super;
|
338
|
+
FrtSymbol field;
|
339
|
+
FrtPriorityQueue *boosted_terms;
|
340
|
+
float min_boost;
|
341
|
+
} FrtMultiTermQuery;
|
342
|
+
|
343
|
+
extern void frt_multi_tq_add_term(FrtQuery *self, const char *term);
|
344
|
+
extern void frt_multi_tq_add_term_boost(FrtQuery *self, const char *term, float boost);
|
345
|
+
extern FrtQuery *frt_multi_tq_new(FrtSymbol field);
|
346
|
+
extern FrtQuery *frt_multi_tq_new_conf(FrtSymbol field, int max_terms,
|
347
|
+
float min_boost);
|
348
|
+
|
349
|
+
#define FrtMTQMaxTerms(query) (((FrtMTQSubQuery *)(query))->max_terms)
|
350
|
+
typedef struct FrtMTQSubQuery
|
351
|
+
{
|
352
|
+
FrtQuery super;
|
353
|
+
int max_terms;
|
354
|
+
} FrtMTQSubQuery;
|
355
|
+
|
356
|
+
/***************************************************************************
|
357
|
+
* FrtPrefixQuery
|
358
|
+
***************************************************************************/
|
359
|
+
|
360
|
+
#define PREFIX_QUERY_MAX_TERMS 256
|
361
|
+
|
362
|
+
typedef struct FrtPrefixQuery
|
363
|
+
{
|
364
|
+
FrtMTQSubQuery super;
|
365
|
+
FrtSymbol field;
|
366
|
+
char *prefix;
|
367
|
+
} FrtPrefixQuery;
|
368
|
+
|
369
|
+
extern FrtQuery *frt_prefixq_new(FrtSymbol field, const char *prefix);
|
370
|
+
|
371
|
+
/***************************************************************************
|
372
|
+
* FrtWildCardQuery
|
373
|
+
***************************************************************************/
|
374
|
+
|
375
|
+
#define FRT_WILD_CHAR '?'
|
376
|
+
#define FRT_WILD_STRING '*'
|
377
|
+
#define FRT_WILD_CARD_QUERY_MAX_TERMS 256
|
378
|
+
|
379
|
+
typedef struct FrtWildCardQuery
|
380
|
+
{
|
381
|
+
FrtMTQSubQuery super;
|
382
|
+
FrtSymbol field;
|
383
|
+
char *pattern;
|
384
|
+
} FrtWildCardQuery;
|
385
|
+
|
386
|
+
|
387
|
+
extern FrtQuery *frt_wcq_new(FrtSymbol field, const char *pattern);
|
388
|
+
extern bool frt_wc_match(const char *pattern, const char *text);
|
389
|
+
|
390
|
+
/***************************************************************************
|
391
|
+
* FrtFuzzyQuery
|
392
|
+
***************************************************************************/
|
393
|
+
|
394
|
+
#define FRT_DEF_MIN_SIM 0.5f
|
395
|
+
#define FRT_DEF_PRE_LEN 0
|
396
|
+
#define FRT_DEF_MAX_TERMS 256
|
397
|
+
#define FRT_TYPICAL_LONGEST_WORD 20
|
398
|
+
|
399
|
+
typedef struct FrtFuzzyQuery
|
400
|
+
{
|
401
|
+
FrtMTQSubQuery super;
|
402
|
+
FrtSymbol field;
|
403
|
+
char *term;
|
404
|
+
const char *text; /* term text after prefix */
|
405
|
+
int text_len;
|
406
|
+
int pre_len;
|
407
|
+
float min_sim;
|
408
|
+
float scale_factor;
|
409
|
+
int max_distances[FRT_TYPICAL_LONGEST_WORD];
|
410
|
+
int *da;
|
411
|
+
} FrtFuzzyQuery;
|
412
|
+
|
413
|
+
extern FrtQuery *frt_fuzq_new(FrtSymbol field, const char *term);
|
414
|
+
extern FrtQuery *frt_fuzq_new_conf(FrtSymbol field, const char *term,
|
415
|
+
float min_sim, int pre_len, int max_terms);
|
416
|
+
extern float frt_fuzq_score(FrtFuzzyQuery *fuzq, const char *target);
|
417
|
+
|
418
|
+
/***************************************************************************
|
419
|
+
* FrtConstantScoreQuery
|
420
|
+
***************************************************************************/
|
421
|
+
|
422
|
+
typedef struct FrtConstantScoreQuery
|
423
|
+
{
|
424
|
+
FrtQuery super;
|
425
|
+
FrtFilter *filter;
|
426
|
+
FrtQuery *original;
|
427
|
+
} FrtConstantScoreQuery;
|
428
|
+
|
429
|
+
extern FrtQuery *frt_csq_new(FrtFilter *filter);
|
430
|
+
extern FrtQuery *frt_csq_new_nr(FrtFilter *filter);
|
431
|
+
|
432
|
+
/***************************************************************************
|
433
|
+
* FrtFilteredQuery
|
434
|
+
***************************************************************************/
|
435
|
+
|
436
|
+
typedef struct FrtFilteredQuery {
|
437
|
+
FrtQuery super;
|
438
|
+
FrtQuery *query;
|
439
|
+
FrtFilter *filter;
|
440
|
+
} FrtFilteredQuery;
|
441
|
+
|
442
|
+
extern FrtQuery *frt_fq_new(FrtQuery *query, FrtFilter *filter);
|
443
|
+
|
444
|
+
/***************************************************************************
|
445
|
+
* FrtMatchAllQuery
|
446
|
+
***************************************************************************/
|
447
|
+
|
448
|
+
extern FrtQuery *frt_maq_new();
|
449
|
+
|
450
|
+
/***************************************************************************
|
451
|
+
* FrtRangeQuery
|
452
|
+
***************************************************************************/
|
453
|
+
|
454
|
+
extern FrtQuery *frt_rq_new(FrtSymbol field, const char *lower_term,
|
455
|
+
const char *upper_term, bool include_lower,
|
456
|
+
bool include_upper);
|
457
|
+
extern FrtQuery *frt_rq_new_less(FrtSymbol field, const char *upper_term, bool include_upper);
|
458
|
+
extern FrtQuery *frt_rq_new_more(FrtSymbol field, const char *lower_term, bool include_lower);
|
459
|
+
|
460
|
+
/***************************************************************************
|
461
|
+
* FrtTypedRangeQuery
|
462
|
+
***************************************************************************/
|
463
|
+
|
464
|
+
extern FrtQuery *frt_trq_new(FrtSymbol field, const char *lower_term,
|
465
|
+
const char *upper_term, bool include_lower,
|
466
|
+
bool include_upper);
|
467
|
+
extern FrtQuery *frt_trq_new_less(FrtSymbol field, const char *upper_term, bool include_upper);
|
468
|
+
extern FrtQuery *frt_trq_new_more(FrtSymbol field, const char *lower_term, bool include_lower);
|
469
|
+
|
470
|
+
/***************************************************************************
|
471
|
+
* FrtSpanQuery
|
472
|
+
***************************************************************************/
|
473
|
+
|
474
|
+
/* ** FrtSpanEnum ** */
|
475
|
+
typedef struct FrtSpanEnum FrtSpanEnum;
|
476
|
+
struct FrtSpanEnum
|
477
|
+
{
|
478
|
+
FrtQuery *query;
|
479
|
+
bool (*next)(FrtSpanEnum *self);
|
480
|
+
bool (*skip_to)(FrtSpanEnum *self, int target_doc);
|
481
|
+
int (*doc)(FrtSpanEnum *self);
|
482
|
+
int (*start)(FrtSpanEnum *self);
|
483
|
+
int (*end)(FrtSpanEnum *self);
|
484
|
+
char *(*to_s)(FrtSpanEnum *self);
|
485
|
+
void (*destroy)(FrtSpanEnum *self);
|
486
|
+
};
|
487
|
+
|
488
|
+
/* ** FrtSpanQuery ** */
|
489
|
+
typedef struct FrtSpanQuery
|
490
|
+
{
|
491
|
+
FrtQuery super;
|
492
|
+
FrtSymbol field;
|
493
|
+
FrtSpanEnum *(*get_spans)(FrtQuery *self, FrtIndexReader *ir);
|
494
|
+
FrtHashSet *(*get_terms)(FrtQuery *self);
|
495
|
+
} FrtSpanQuery;
|
496
|
+
|
497
|
+
/***************************************************************************
|
498
|
+
* FrtSpanTermQuery
|
499
|
+
***************************************************************************/
|
500
|
+
|
501
|
+
typedef struct FrtSpanTermQuery
|
502
|
+
{
|
503
|
+
FrtSpanQuery super;
|
504
|
+
char *term;
|
505
|
+
} FrtSpanTermQuery;
|
506
|
+
extern FrtQuery *frt_spantq_new(FrtSymbol field, const char *term);
|
507
|
+
|
508
|
+
/***************************************************************************
|
509
|
+
* FrtSpanMultiTermQuery
|
510
|
+
***************************************************************************/
|
511
|
+
|
512
|
+
#define SPAN_MULTI_TERM_QUERY_CAPA 1024
|
513
|
+
typedef struct FrtSpanMultiTermQuery
|
514
|
+
{
|
515
|
+
FrtSpanQuery super;
|
516
|
+
char **terms;
|
517
|
+
int term_cnt;
|
518
|
+
int term_capa;
|
519
|
+
} FrtSpanMultiTermQuery;
|
520
|
+
|
521
|
+
extern FrtQuery *frt_spanmtq_new(FrtSymbol field);
|
522
|
+
extern FrtQuery *frt_spanmtq_new_conf(FrtSymbol field, int max_size);
|
523
|
+
extern void frt_spanmtq_add_term(FrtQuery *self, const char *term);
|
524
|
+
|
525
|
+
/***************************************************************************
|
526
|
+
* FrtSpanFirstQuery
|
527
|
+
***************************************************************************/
|
528
|
+
|
529
|
+
typedef struct FrtSpanFirstQuery
|
530
|
+
{
|
531
|
+
FrtSpanQuery super;
|
532
|
+
int end;
|
533
|
+
FrtQuery *match;
|
534
|
+
} FrtSpanFirstQuery;
|
535
|
+
|
536
|
+
extern FrtQuery *frt_spanfq_new(FrtQuery *match, int end);
|
537
|
+
extern FrtQuery *frt_spanfq_new_nr(FrtQuery *match, int end);
|
538
|
+
|
539
|
+
/***************************************************************************
|
540
|
+
* FrtSpanOrQuery
|
541
|
+
***************************************************************************/
|
542
|
+
|
543
|
+
typedef struct FrtSpanOrQuery
|
544
|
+
{
|
545
|
+
FrtSpanQuery super;
|
546
|
+
FrtQuery **clauses;
|
547
|
+
int c_cnt;
|
548
|
+
int c_capa;
|
549
|
+
} FrtSpanOrQuery;
|
550
|
+
|
551
|
+
extern FrtQuery *frt_spanoq_new();
|
552
|
+
extern FrtQuery *frt_spanoq_add_clause(FrtQuery *self, FrtQuery *clause);
|
553
|
+
extern FrtQuery *frt_spanoq_add_clause_nr(FrtQuery *self, FrtQuery *clause);
|
554
|
+
|
555
|
+
/***************************************************************************
|
556
|
+
* FrtSpanNearQuery
|
557
|
+
***************************************************************************/
|
558
|
+
|
559
|
+
typedef struct FrtSpanNearQuery
|
560
|
+
{
|
561
|
+
FrtSpanQuery super;
|
562
|
+
FrtQuery **clauses;
|
563
|
+
int c_cnt;
|
564
|
+
int c_capa;
|
565
|
+
int slop;
|
566
|
+
bool in_order : 1;
|
567
|
+
} FrtSpanNearQuery;
|
568
|
+
|
569
|
+
extern FrtQuery *frt_spannq_new(int slop, bool in_order);
|
570
|
+
extern FrtQuery *frt_spannq_add_clause(FrtQuery *self, FrtQuery *clause);
|
571
|
+
extern FrtQuery *frt_spannq_add_clause_nr(FrtQuery *self, FrtQuery *clause);
|
572
|
+
|
573
|
+
/***************************************************************************
|
574
|
+
* FrtSpanNotQuery
|
575
|
+
***************************************************************************/
|
576
|
+
|
577
|
+
typedef struct FrtSpanNotQuery
|
578
|
+
{
|
579
|
+
FrtSpanQuery super;
|
580
|
+
FrtQuery *inc;
|
581
|
+
FrtQuery *exc;
|
582
|
+
} FrtSpanNotQuery;
|
583
|
+
|
584
|
+
extern FrtQuery *frt_spanxq_new(FrtQuery *inc, FrtQuery *exc);
|
585
|
+
extern FrtQuery *frt_spanxq_new_nr(FrtQuery *inc, FrtQuery *exc);
|
586
|
+
|
587
|
+
|
588
|
+
/***************************************************************************
|
589
|
+
* FrtSpanPrefixQuery
|
590
|
+
***************************************************************************/
|
591
|
+
|
592
|
+
#define FRT_SPAN_PREFIX_QUERY_MAX_TERMS 256
|
593
|
+
|
594
|
+
typedef struct FrtSpanPrefixQuery
|
595
|
+
{
|
596
|
+
FrtSpanQuery super;
|
597
|
+
char *prefix;
|
598
|
+
int max_terms;
|
599
|
+
} FrtSpanPrefixQuery;
|
600
|
+
|
601
|
+
extern FrtQuery *frt_spanprq_new(FrtSymbol field, const char *prefix);
|
602
|
+
|
603
|
+
|
604
|
+
/***************************************************************************
|
605
|
+
*
|
606
|
+
* FrtScorer
|
607
|
+
*
|
608
|
+
***************************************************************************/
|
609
|
+
|
610
|
+
#define FRT_SCORER_NULLIFY(mscorer) do {\
|
611
|
+
(mscorer)->destroy(mscorer);\
|
612
|
+
(mscorer) = NULL;\
|
613
|
+
} while (0)
|
614
|
+
|
615
|
+
struct FrtScorer
|
616
|
+
{
|
617
|
+
FrtSimilarity *similarity;
|
618
|
+
int doc;
|
619
|
+
float (*score)(FrtScorer *self);
|
620
|
+
bool (*next)(FrtScorer *self);
|
621
|
+
bool (*skip_to)(FrtScorer *self, int doc_num);
|
622
|
+
FrtExplanation *(*explain)(FrtScorer *self, int doc_num);
|
623
|
+
void (*destroy)(FrtScorer *self);
|
624
|
+
};
|
625
|
+
|
626
|
+
#define frt_scorer_new(type, similarity) frt_scorer_create(sizeof(type), similarity)
|
627
|
+
/* Internal FrtScorer Function */
|
628
|
+
extern void frt_scorer_destroy_i(FrtScorer *self);
|
629
|
+
extern FrtScorer *frt_scorer_create(size_t size, FrtSimilarity *similarity);
|
630
|
+
extern bool frt_scorer_doc_less_than(const FrtScorer *s1, const FrtScorer *s2);
|
631
|
+
extern int frt_scorer_doc_cmp(const void *p1, const void *p2);
|
632
|
+
|
633
|
+
/***************************************************************************
|
634
|
+
* FrtComparable
|
635
|
+
***************************************************************************/
|
636
|
+
|
637
|
+
typedef struct FrtComparable
|
638
|
+
{
|
639
|
+
int type;
|
640
|
+
union {
|
641
|
+
long l;
|
642
|
+
float f;
|
643
|
+
char *s;
|
644
|
+
void *p;
|
645
|
+
} val;
|
646
|
+
bool reverse : 1;
|
647
|
+
} FrtComparable;
|
648
|
+
|
649
|
+
/***************************************************************************
|
650
|
+
*
|
651
|
+
* FrtSort
|
652
|
+
*
|
653
|
+
***************************************************************************/
|
654
|
+
|
655
|
+
typedef enum
|
656
|
+
{
|
657
|
+
FRT_SORT_TYPE_SCORE,
|
658
|
+
FRT_SORT_TYPE_DOC,
|
659
|
+
FRT_SORT_TYPE_BYTE,
|
660
|
+
FRT_SORT_TYPE_INTEGER,
|
661
|
+
FRT_SORT_TYPE_FLOAT,
|
662
|
+
FRT_SORT_TYPE_STRING,
|
663
|
+
FRT_SORT_TYPE_AUTO
|
664
|
+
} SortType;
|
665
|
+
|
666
|
+
/***************************************************************************
|
667
|
+
* FrtSortField
|
668
|
+
***************************************************************************/
|
669
|
+
|
670
|
+
typedef struct FrtSortField
|
671
|
+
{
|
672
|
+
const FrtFieldIndexClass *field_index_class;
|
673
|
+
FrtSymbol field;
|
674
|
+
SortType type;
|
675
|
+
bool reverse : 1;
|
676
|
+
int (*compare)(void *index_ptr, FrtHit *hit1, FrtHit *hit2);
|
677
|
+
void (*get_val)(void *index_ptr, FrtHit *hit1, FrtComparable *comparable);
|
678
|
+
} FrtSortField;
|
679
|
+
|
680
|
+
extern FrtSortField *frt_sort_field_new(FrtSymbol field,
|
681
|
+
SortType type,
|
682
|
+
bool reverse);
|
683
|
+
extern FrtSortField *frt_sort_field_score_new(bool reverse);
|
684
|
+
extern FrtSortField *frt_sort_field_doc_new(bool reverse);
|
685
|
+
extern FrtSortField *frt_sort_field_int_new(FrtSymbol field, bool reverse);
|
686
|
+
extern FrtSortField *frt_sort_field_byte_new(FrtSymbol field, bool reverse);
|
687
|
+
extern FrtSortField *frt_sort_field_float_new(FrtSymbol field, bool reverse);
|
688
|
+
extern FrtSortField *frt_sort_field_string_new(FrtSymbol field, bool reverse);
|
689
|
+
extern FrtSortField *frt_sort_field_auto_new(FrtSymbol field, bool reverse);
|
690
|
+
extern void frt_sort_field_destroy(void *p);
|
691
|
+
extern char *frt_sort_field_to_s(FrtSortField *self);
|
692
|
+
|
693
|
+
extern const FrtSortField FRT_SORT_FIELD_SCORE;
|
694
|
+
extern const FrtSortField FRT_SORT_FIELD_SCORE_REV;
|
695
|
+
extern const FrtSortField FRT_SORT_FIELD_DOC;
|
696
|
+
extern const FrtSortField FRT_SORT_FIELD_DOC_REV;
|
697
|
+
|
698
|
+
/***************************************************************************
|
699
|
+
* FrtSort
|
700
|
+
***************************************************************************/
|
701
|
+
|
702
|
+
typedef struct FrtSort
|
703
|
+
{
|
704
|
+
FrtSortField **sort_fields;
|
705
|
+
int size;
|
706
|
+
int capa;
|
707
|
+
int start;
|
708
|
+
bool destroy_all : 1;
|
709
|
+
} FrtSort;
|
710
|
+
|
711
|
+
extern FrtSort *frt_sort_new();
|
712
|
+
extern void frt_sort_destroy(void *p);
|
713
|
+
extern void frt_sort_add_sort_field(FrtSort *self, FrtSortField *sf);
|
714
|
+
extern void frt_sort_clear(FrtSort *self);
|
715
|
+
extern char *frt_sort_to_s(FrtSort *self);
|
716
|
+
|
717
|
+
/***************************************************************************
|
718
|
+
* FieldSortedHitQueue
|
719
|
+
***************************************************************************/
|
720
|
+
|
721
|
+
extern FrtHit *frt_fshq_pq_pop(FrtPriorityQueue *pq);
|
722
|
+
extern void frt_fshq_pq_insert(FrtPriorityQueue *pq, FrtHit *hit);
|
723
|
+
extern void frt_fshq_pq_destroy(FrtPriorityQueue *pq);
|
724
|
+
extern FrtPriorityQueue *frt_fshq_pq_new(int size, FrtSort *sort, FrtIndexReader *ir);
|
725
|
+
extern FrtHit *frt_fshq_pq_pop_fd(FrtPriorityQueue *pq);
|
726
|
+
|
727
|
+
/***************************************************************************
|
728
|
+
* FrtFieldDoc
|
729
|
+
***************************************************************************/
|
730
|
+
|
731
|
+
typedef struct FrtFieldDoc
|
732
|
+
{
|
733
|
+
FrtHit hit;
|
734
|
+
int size;
|
735
|
+
FrtComparable comparables[1];
|
736
|
+
} FrtFieldDoc;
|
737
|
+
|
738
|
+
/***************************************************************************
|
739
|
+
* FieldDocSortedHitQueue
|
740
|
+
***************************************************************************/
|
741
|
+
|
742
|
+
extern bool frt_fdshq_lt(FrtFieldDoc *fd1, FrtFieldDoc *fd2);
|
743
|
+
|
744
|
+
/***************************************************************************
|
745
|
+
*
|
746
|
+
* FrtSearcher
|
747
|
+
*
|
748
|
+
***************************************************************************/
|
749
|
+
|
750
|
+
typedef struct FrtPostFilter
|
751
|
+
{
|
752
|
+
float (*filter_func)(int doc_num, float score, FrtSearcher *self, void *arg);
|
753
|
+
void *arg;
|
754
|
+
} FrtPostFilter;
|
755
|
+
|
756
|
+
struct FrtSearcher
|
757
|
+
{
|
758
|
+
FrtSimilarity *similarity;
|
759
|
+
int (*doc_freq)(FrtSearcher *self, FrtSymbol field,
|
760
|
+
const char *term);
|
761
|
+
FrtDocument *(*get_doc)(FrtSearcher *self, int doc_num);
|
762
|
+
FrtLazyDoc *(*get_lazy_doc)(FrtSearcher *self, int doc_num);
|
763
|
+
int (*max_doc)(FrtSearcher *self);
|
764
|
+
FrtWeight *(*create_weight)(FrtSearcher *self, FrtQuery *query);
|
765
|
+
FrtTopDocs *(*search)(FrtSearcher *self, FrtQuery *query, int first_doc,
|
766
|
+
int num_docs, FrtFilter *filter, FrtSort *sort,
|
767
|
+
FrtPostFilter *post_filter,
|
768
|
+
bool load_fields);
|
769
|
+
FrtTopDocs *(*search_w)(FrtSearcher *self, FrtWeight *weight, int first_doc,
|
770
|
+
int num_docs, FrtFilter *filter, FrtSort *sort,
|
771
|
+
FrtPostFilter *post_filter,
|
772
|
+
bool load_fields);
|
773
|
+
void (*search_each)(FrtSearcher *self, FrtQuery *query, FrtFilter *filter,
|
774
|
+
FrtPostFilter *post_filter,
|
775
|
+
void (*fn)(FrtSearcher *, int, float, void *),
|
776
|
+
void *arg);
|
777
|
+
void (*search_each_w)(FrtSearcher *self, FrtWeight *weight,
|
778
|
+
FrtFilter *filter,
|
779
|
+
FrtPostFilter *post_filter,
|
780
|
+
void (*fn)(FrtSearcher *, int, float, void *),
|
781
|
+
void *arg);
|
782
|
+
/*
|
783
|
+
* Scan the index for all documents that match a query and write the
|
784
|
+
* results to a buffer. It will stop scanning once the limit is reached
|
785
|
+
* and it starts scanning from offset_docnum.
|
786
|
+
*
|
787
|
+
* Note: Unlike the offset_docnum in other search methods, this
|
788
|
+
* offset_docnum refers to document number and not hit.
|
789
|
+
*/
|
790
|
+
int (*search_unscored)(FrtSearcher *searcher,
|
791
|
+
FrtQuery *query,
|
792
|
+
int *buf,
|
793
|
+
int limit,
|
794
|
+
int offset_docnum);
|
795
|
+
int (*search_unscored_w)(FrtSearcher *searcher,
|
796
|
+
FrtWeight *weight,
|
797
|
+
int *buf,
|
798
|
+
int limit,
|
799
|
+
int offset_docnum);
|
800
|
+
FrtQuery *(*rewrite)(FrtSearcher *self, FrtQuery *original);
|
801
|
+
FrtExplanation *(*explain)(FrtSearcher *self, FrtQuery *query, int doc_num);
|
802
|
+
FrtExplanation *(*explain_w)(FrtSearcher *self, FrtWeight *weight, int doc_num);
|
803
|
+
FrtTermVector *(*get_term_vector)(FrtSearcher *self, const int doc_num,
|
804
|
+
FrtSymbol field);
|
805
|
+
FrtSimilarity *(*get_similarity)(FrtSearcher *self);
|
806
|
+
void (*close)(FrtSearcher *self);
|
807
|
+
};
|
808
|
+
|
809
|
+
#define frt_searcher_get_doc(s, dn) s->get_doc(s, dn)
|
810
|
+
#define frt_searcher_get_lazy_doc(s, dn) s->get_lazy_doc(s, dn)
|
811
|
+
#define frt_searcher_max_doc(s) s->max_doc(s)
|
812
|
+
#define frt_searcher_rewrite(s, q) s->rewrite(s, q)
|
813
|
+
#define frt_searcher_explain(s, q, dn) s->explain(s, q, dn)
|
814
|
+
#define frt_searcher_close(s) s->close(s)
|
815
|
+
#define frt_searcher_search(s, q, fd, nd, filt, sort, ff) s->search(s, q, fd, nd, filt, sort, ff, false)
|
816
|
+
#define frt_searcher_search_each(s, q, filt, ff, fn, arg) s->search_each(s, q, filt, ff, fn, arg)
|
817
|
+
#define frt_searcher_search_unscored(s, q, buf, limit, offset_docnum) s->search_unscored(s, q, buf, limit, offset_docnum)
|
818
|
+
|
819
|
+
extern FrtMatchVector *frt_searcher_get_match_vector(FrtSearcher *self,
|
820
|
+
FrtQuery *query,
|
821
|
+
const int doc_num,
|
822
|
+
FrtSymbol field);
|
823
|
+
extern char **frt_searcher_highlight(FrtSearcher *self,
|
824
|
+
FrtQuery *query,
|
825
|
+
const int doc_num,
|
826
|
+
FrtSymbol field,
|
827
|
+
const int excerpt_len,
|
828
|
+
const int num_excerpts,
|
829
|
+
const char *pre_tag,
|
830
|
+
const char *post_tag,
|
831
|
+
const char *ellipsis);
|
832
|
+
|
833
|
+
/***************************************************************************
|
834
|
+
*
|
835
|
+
* FrtIndexSearcher
|
836
|
+
*
|
837
|
+
***************************************************************************/
|
838
|
+
|
839
|
+
typedef struct FrtIndexSearcher {
|
840
|
+
FrtSearcher super;
|
841
|
+
FrtIndexReader *ir;
|
842
|
+
bool close_ir : 1;
|
843
|
+
} FrtIndexSearcher;
|
844
|
+
|
845
|
+
extern FrtSearcher *frt_isea_new(FrtIndexReader *ir);
|
846
|
+
extern int frt_isea_doc_freq(FrtSearcher *self, FrtSymbol field, const char *term);
|
847
|
+
|
848
|
+
|
849
|
+
|
850
|
+
/***************************************************************************
|
851
|
+
*
|
852
|
+
* FrtMultiSearcher
|
853
|
+
*
|
854
|
+
***************************************************************************/
|
855
|
+
|
856
|
+
typedef struct FrtMultiSearcher
|
857
|
+
{
|
858
|
+
FrtSearcher super;
|
859
|
+
int s_cnt;
|
860
|
+
FrtSearcher **searchers;
|
861
|
+
int *starts;
|
862
|
+
int max_doc;
|
863
|
+
bool close_subs : 1;
|
864
|
+
} FrtMultiSearcher;
|
865
|
+
|
866
|
+
extern FrtSearcher *frt_msea_new(FrtSearcher **searchers, int s_cnt, bool close_subs);
|
867
|
+
|
868
|
+
/***************************************************************************
|
869
|
+
*
|
870
|
+
* FrtQParser
|
871
|
+
*
|
872
|
+
***************************************************************************/
|
873
|
+
|
874
|
+
#define FRT_QP_CONC_WORDS 2
|
875
|
+
#define FRT_QP_MAX_CLAUSES 512
|
876
|
+
typedef struct FrtFieldStack {
|
877
|
+
FrtHashSet *fields;
|
878
|
+
struct FrtFieldStack *next;
|
879
|
+
bool destroy : 1;
|
880
|
+
} FrtFieldStack;
|
881
|
+
|
882
|
+
typedef struct FrtQueryParser
|
883
|
+
{
|
884
|
+
frt_mutex_t mutex;
|
885
|
+
int def_slop;
|
886
|
+
int max_clauses;
|
887
|
+
int phq_pos_inc;
|
888
|
+
char *qstr;
|
889
|
+
char *qstrp;
|
890
|
+
char buf[FRT_QP_CONC_WORDS][FRT_MAX_WORD_SIZE];
|
891
|
+
char *dynbuf;
|
892
|
+
int buf_index;
|
893
|
+
FrtHashSet *def_fields;
|
894
|
+
FrtHashSet *all_fields;
|
895
|
+
FrtHashSet *tokenized_fields;
|
896
|
+
FrtHashSet *fields;
|
897
|
+
FrtFieldStack *fields_top;
|
898
|
+
FrtAnalyzer *analyzer;
|
899
|
+
FrtHash *ts_cache;
|
900
|
+
FrtQuery *result;
|
901
|
+
FrtTokenStream *non_tokenizer;
|
902
|
+
bool or_default : 1;
|
903
|
+
bool wild_lower : 1;
|
904
|
+
bool clean_str : 1;
|
905
|
+
bool handle_parse_errors : 1;
|
906
|
+
bool allow_any_fields : 1;
|
907
|
+
bool destruct : 1;
|
908
|
+
bool recovering : 1;
|
909
|
+
bool use_keywords : 1;
|
910
|
+
bool use_typed_range_query : 1;
|
911
|
+
} FrtQueryParser;
|
912
|
+
typedef FrtQueryParser FrtQParser; /* QParser is an alias for QueryParser */
|
913
|
+
|
914
|
+
extern FrtQParser *frt_qp_new(FrtAnalyzer *analyzer);
|
915
|
+
extern void frt_qp_add_field(FrtQParser *self, FrtSymbol field,
|
916
|
+
bool is_default, bool is_tokenized);
|
917
|
+
extern void frt_qp_destroy(FrtQParser *self);
|
918
|
+
extern FrtQuery *qp_parse(FrtQParser *self, char *qstr);
|
919
|
+
extern char *frt_qp_clean_str(char *str);
|
920
|
+
|
921
|
+
extern float frt_qp_default_fuzzy_min_sim;
|
922
|
+
extern int frt_qp_default_fuzzy_pre_len;
|
923
|
+
|
924
|
+
#endif
|