isomorfeus-ferret 0.17.2 → 0.17.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/isomorfeus_ferret_ext/benchmark.c +9 -20
- data/ext/isomorfeus_ferret_ext/benchmarks_all.h +1 -2
- data/ext/isomorfeus_ferret_ext/bm_hash.c +1 -2
- data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +4 -2
- data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +3 -2
- data/ext/isomorfeus_ferret_ext/frb_analysis.c +4 -5
- data/ext/isomorfeus_ferret_ext/frb_field_info.c +3 -4
- data/ext/isomorfeus_ferret_ext/frb_index.c +161 -187
- data/ext/isomorfeus_ferret_ext/frb_lazy_doc.c +14 -16
- data/ext/isomorfeus_ferret_ext/frb_search.c +77 -69
- data/ext/isomorfeus_ferret_ext/frb_store.c +27 -13
- data/ext/isomorfeus_ferret_ext/frb_utils.c +3 -6
- data/ext/isomorfeus_ferret_ext/frt_analysis.c +39 -46
- data/ext/isomorfeus_ferret_ext/frt_analysis.h +9 -9
- data/ext/isomorfeus_ferret_ext/frt_array.c +11 -22
- data/ext/isomorfeus_ferret_ext/frt_bitvector.h +3 -6
- data/ext/isomorfeus_ferret_ext/frt_doc_field.c +87 -0
- data/ext/isomorfeus_ferret_ext/frt_doc_field.h +26 -0
- data/ext/isomorfeus_ferret_ext/frt_document.c +4 -97
- data/ext/isomorfeus_ferret_ext/frt_document.h +5 -33
- data/ext/isomorfeus_ferret_ext/frt_except.c +8 -6
- data/ext/isomorfeus_ferret_ext/frt_except.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_field_index.c +14 -33
- data/ext/isomorfeus_ferret_ext/frt_field_index.h +0 -6
- data/ext/isomorfeus_ferret_ext/frt_field_info.c +69 -0
- data/ext/isomorfeus_ferret_ext/frt_field_info.h +49 -0
- data/ext/isomorfeus_ferret_ext/frt_field_infos.c +196 -0
- data/ext/isomorfeus_ferret_ext/frt_field_infos.h +35 -0
- data/ext/isomorfeus_ferret_ext/frt_filter.c +2 -2
- data/ext/isomorfeus_ferret_ext/frt_global.c +10 -4
- data/ext/isomorfeus_ferret_ext/frt_global.h +11 -15
- data/ext/isomorfeus_ferret_ext/frt_hash.c +8 -8
- data/ext/isomorfeus_ferret_ext/frt_hash.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_hashset.c +20 -40
- data/ext/isomorfeus_ferret_ext/frt_hashset.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_helper.c +7 -15
- data/ext/isomorfeus_ferret_ext/frt_in_stream.c +35 -45
- data/ext/isomorfeus_ferret_ext/frt_in_stream.h +3 -2
- data/ext/isomorfeus_ferret_ext/frt_ind.c +21 -39
- data/ext/isomorfeus_ferret_ext/frt_ind.h +1 -1
- data/ext/isomorfeus_ferret_ext/frt_index.c +334 -848
- data/ext/isomorfeus_ferret_ext/frt_index.h +4 -105
- data/ext/isomorfeus_ferret_ext/frt_lang.c +5 -10
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc.c +3 -3
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc.h +1 -1
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.c +18 -25
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.h +5 -5
- data/ext/isomorfeus_ferret_ext/frt_mdbx_store.c +102 -70
- data/ext/isomorfeus_ferret_ext/frt_mempool.c +8 -16
- data/ext/isomorfeus_ferret_ext/frt_multimapper.c +23 -46
- data/ext/isomorfeus_ferret_ext/frt_multimapper.h +4 -8
- data/ext/isomorfeus_ferret_ext/frt_out_stream.c +31 -43
- data/ext/isomorfeus_ferret_ext/frt_out_stream.h +2 -2
- data/ext/isomorfeus_ferret_ext/frt_posh.c +6 -819
- data/ext/isomorfeus_ferret_ext/frt_posh.h +0 -57
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +11 -22
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +131 -217
- data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +2 -2
- data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +4 -4
- data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +18 -26
- data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +27 -28
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +49 -98
- data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +64 -116
- data/ext/isomorfeus_ferret_ext/frt_q_range.c +8 -14
- data/ext/isomorfeus_ferret_ext/frt_q_span.c +251 -365
- data/ext/isomorfeus_ferret_ext/frt_q_term.c +9 -9
- data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +1 -2
- data/ext/isomorfeus_ferret_ext/frt_ram_store.c +134 -85
- data/ext/isomorfeus_ferret_ext/frt_search.c +109 -191
- data/ext/isomorfeus_ferret_ext/frt_search.h +6 -6
- data/ext/isomorfeus_ferret_ext/frt_similarity.c +12 -23
- data/ext/isomorfeus_ferret_ext/frt_similarity.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_sort.c +20 -20
- data/ext/isomorfeus_ferret_ext/frt_store.c +13 -25
- data/ext/isomorfeus_ferret_ext/frt_store.h +86 -52
- data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +8 -16
- data/ext/isomorfeus_ferret_ext/frt_win32.h +5 -10
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +12 -11
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +11 -13
- data/ext/isomorfeus_ferret_ext/lz4.c +422 -195
- data/ext/isomorfeus_ferret_ext/lz4.h +114 -46
- data/ext/isomorfeus_ferret_ext/lz4frame.c +421 -242
- data/ext/isomorfeus_ferret_ext/lz4frame.h +122 -53
- data/ext/isomorfeus_ferret_ext/lz4hc.c +127 -111
- data/ext/isomorfeus_ferret_ext/lz4hc.h +14 -14
- data/ext/isomorfeus_ferret_ext/lz4xxhash.h +1 -1
- data/ext/isomorfeus_ferret_ext/mdbx.c +3762 -2526
- data/ext/isomorfeus_ferret_ext/mdbx.h +115 -70
- data/ext/isomorfeus_ferret_ext/test.c +41 -88
- data/ext/isomorfeus_ferret_ext/test.h +3 -6
- data/ext/isomorfeus_ferret_ext/test_1710.c +11 -13
- data/ext/isomorfeus_ferret_ext/test_analysis.c +32 -64
- data/ext/isomorfeus_ferret_ext/test_array.c +6 -12
- data/ext/isomorfeus_ferret_ext/test_bitvector.c +12 -24
- data/ext/isomorfeus_ferret_ext/test_document.c +23 -33
- data/ext/isomorfeus_ferret_ext/test_except.c +10 -21
- data/ext/isomorfeus_ferret_ext/test_fields.c +62 -68
- data/ext/isomorfeus_ferret_ext/test_file_deleter.c +16 -25
- data/ext/isomorfeus_ferret_ext/test_filter.c +22 -33
- data/ext/isomorfeus_ferret_ext/test_global.c +14 -29
- data/ext/isomorfeus_ferret_ext/test_hash.c +19 -38
- data/ext/isomorfeus_ferret_ext/test_hashset.c +8 -16
- data/ext/isomorfeus_ferret_ext/test_helper.c +4 -8
- data/ext/isomorfeus_ferret_ext/test_highlighter.c +16 -28
- data/ext/isomorfeus_ferret_ext/test_index.c +307 -519
- data/ext/isomorfeus_ferret_ext/test_lang.c +7 -14
- data/ext/isomorfeus_ferret_ext/test_mdbx_store.c +2 -5
- data/ext/isomorfeus_ferret_ext/test_mempool.c +5 -10
- data/ext/isomorfeus_ferret_ext/test_multimapper.c +3 -6
- data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +9 -18
- data/ext/isomorfeus_ferret_ext/test_q_const_score.c +4 -6
- data/ext/isomorfeus_ferret_ext/test_q_filtered.c +3 -4
- data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +9 -15
- data/ext/isomorfeus_ferret_ext/test_q_parser.c +8 -16
- data/ext/isomorfeus_ferret_ext/test_q_span.c +19 -35
- data/ext/isomorfeus_ferret_ext/test_ram_store.c +14 -13
- data/ext/isomorfeus_ferret_ext/test_search.c +66 -115
- data/ext/isomorfeus_ferret_ext/test_segments.c +8 -13
- data/ext/isomorfeus_ferret_ext/test_similarity.c +2 -4
- data/ext/isomorfeus_ferret_ext/test_sort.c +17 -27
- data/ext/isomorfeus_ferret_ext/test_store.c +96 -115
- data/ext/isomorfeus_ferret_ext/test_term.c +9 -15
- data/ext/isomorfeus_ferret_ext/test_term_vectors.c +9 -14
- data/ext/isomorfeus_ferret_ext/test_test.c +4 -8
- data/ext/isomorfeus_ferret_ext/test_threading.c +15 -21
- data/ext/isomorfeus_ferret_ext/testhelper.c +11 -21
- data/ext/isomorfeus_ferret_ext/testhelper.h +1 -1
- data/ext/isomorfeus_ferret_ext/tests_all.h +1 -2
- data/lib/isomorfeus/ferret/index/index.rb +8 -8
- data/lib/isomorfeus/ferret/version.rb +1 -1
- metadata +32 -6
@@ -68,7 +68,7 @@ extern FrtMatchVector *frt_matchv_compact_with_breaks(FrtMatchVector *self);
|
|
68
68
|
***************************************************************************/
|
69
69
|
|
70
70
|
typedef struct FrtHit {
|
71
|
-
int
|
71
|
+
int doc_num;
|
72
72
|
float score;
|
73
73
|
} FrtHit;
|
74
74
|
|
@@ -504,7 +504,7 @@ struct FrtSpanEnum {
|
|
504
504
|
FrtQuery *query;
|
505
505
|
bool (*next)(FrtSpanEnum *self);
|
506
506
|
bool (*skip_to)(FrtSpanEnum *self, int target_doc);
|
507
|
-
int (*
|
507
|
+
int (*doc_num)(FrtSpanEnum *self);
|
508
508
|
int (*start)(FrtSpanEnum *self);
|
509
509
|
int (*end)(FrtSpanEnum *self);
|
510
510
|
char *(*to_s)(FrtSpanEnum *self);
|
@@ -645,7 +645,7 @@ extern FrtQuery *frt_spanprq_new(ID field, const char *prefix);
|
|
645
645
|
|
646
646
|
struct FrtScorer {
|
647
647
|
FrtSimilarity *similarity;
|
648
|
-
int
|
648
|
+
int doc_num;
|
649
649
|
float (*score)(FrtScorer *self);
|
650
650
|
bool (*next)(FrtScorer *self);
|
651
651
|
bool (*skip_to)(FrtScorer *self, int doc_num);
|
@@ -795,7 +795,7 @@ struct FrtSearcher {
|
|
795
795
|
int (*doc_freq)(FrtSearcher *self, ID field, const char *term);
|
796
796
|
FrtDocument *(*get_doc)(FrtSearcher *self, int doc_num);
|
797
797
|
FrtLazyDoc *(*get_lazy_doc)(FrtSearcher *self, int doc_num);
|
798
|
-
int (*
|
798
|
+
int (*max_doc_num)(FrtSearcher *self);
|
799
799
|
FrtWeight *(*create_weight)(FrtSearcher *self, FrtQuery *query);
|
800
800
|
FrtTopDocs *(*search)(FrtSearcher *self, FrtQuery *query, int first_doc, int num_docs, FrtFilter *filter, FrtSort *sort, FrtPostFilter *post_filter, bool load_fields);
|
801
801
|
FrtTopDocs *(*search_w)(FrtSearcher *self, FrtWeight *weight, int first_doc, int num_docs, FrtFilter *filter, FrtSort *sort, FrtPostFilter *post_filter, bool load_fields);
|
@@ -822,7 +822,7 @@ struct FrtSearcher {
|
|
822
822
|
|
823
823
|
#define frt_searcher_get_doc(s, dn) s->get_doc(s, dn)
|
824
824
|
#define frt_searcher_get_lazy_doc(s, dn) s->get_lazy_doc(s, dn)
|
825
|
-
#define frt_searcher_max_doc(s) s->
|
825
|
+
#define frt_searcher_max_doc(s) s->max_doc_num(s)
|
826
826
|
#define frt_searcher_rewrite(s, q) s->rewrite(s, q)
|
827
827
|
#define frt_searcher_explain(s, q, dn) s->explain(s, q, dn)
|
828
828
|
#define frt_searcher_close(s) s->close(s)
|
@@ -868,7 +868,7 @@ typedef struct FrtMultiSearcher {
|
|
868
868
|
int s_cnt;
|
869
869
|
FrtSearcher **searchers;
|
870
870
|
int *starts;
|
871
|
-
int
|
871
|
+
int max_doc_num;
|
872
872
|
} FrtMultiSearcher;
|
873
873
|
|
874
874
|
extern FrtSearcher *frt_msea_alloc(void);
|
@@ -20,20 +20,17 @@ FrtTerm *frt_term_new(ID field, const char *text) {
|
|
20
20
|
return t;
|
21
21
|
}
|
22
22
|
|
23
|
-
void frt_term_destroy(FrtTerm *self)
|
24
|
-
{
|
23
|
+
void frt_term_destroy(FrtTerm *self) {
|
25
24
|
free(self->text);
|
26
25
|
free(self);
|
27
26
|
}
|
28
27
|
|
29
|
-
int frt_term_eq(const void *t1, const void *t2)
|
30
|
-
{
|
28
|
+
int frt_term_eq(const void *t1, const void *t2) {
|
31
29
|
return ((strcmp(((FrtTerm *)t1)->text, ((FrtTerm *)t2)->text) == 0) &&
|
32
30
|
(((FrtTerm *)t1)->field == ((FrtTerm *)t2)->field));
|
33
31
|
}
|
34
32
|
|
35
|
-
unsigned long long frt_term_hash(const void *t)
|
36
|
-
{
|
33
|
+
unsigned long long frt_term_hash(const void *t) {
|
37
34
|
return frt_str_hash(((FrtTerm *)t)->text) * frt_str_hash(rb_id2name(((FrtTerm *)t)->field));
|
38
35
|
}
|
39
36
|
|
@@ -49,27 +46,24 @@ static float simdef_length_norm(FrtSimilarity *s, ID field, int num_terms) {
|
|
49
46
|
return (float)(1.0 / sqrt(num_terms));
|
50
47
|
}
|
51
48
|
|
52
|
-
static float simdef_query_norm(struct FrtSimilarity *s, float sum_of_squared_weights)
|
53
|
-
{
|
49
|
+
static float simdef_query_norm(struct FrtSimilarity *s, float sum_of_squared_weights) {
|
54
50
|
(void)s;
|
55
51
|
return (float)(1.0 / sqrt(sum_of_squared_weights));
|
56
52
|
}
|
57
53
|
|
58
|
-
static float simdef_tf(struct FrtSimilarity *s, float freq)
|
59
|
-
{
|
54
|
+
static float simdef_tf(struct FrtSimilarity *s, float freq) {
|
60
55
|
(void)s;
|
61
56
|
return (float)sqrt(freq);
|
62
57
|
}
|
63
58
|
|
64
|
-
static float simdef_sloppy_freq(struct FrtSimilarity *s, int distance)
|
65
|
-
{
|
59
|
+
static float simdef_sloppy_freq(struct FrtSimilarity *s, int distance) {
|
66
60
|
(void)s;
|
67
61
|
return (float)(1.0 / (double)(distance + 1));
|
68
62
|
}
|
69
63
|
|
70
64
|
static float simdef_idf_term(struct FrtSimilarity *s, ID field, char *term, FrtSearcher *searcher) {
|
71
65
|
return s->idf(s, searcher->doc_freq(searcher, field, term),
|
72
|
-
searcher->
|
66
|
+
searcher->max_doc_num(searcher));
|
73
67
|
}
|
74
68
|
|
75
69
|
static float simdef_idf_phrase(struct FrtSimilarity *s, ID field, FrtPhrasePosition *positions, int pp_cnt, FrtSearcher *searcher) {
|
@@ -84,31 +78,26 @@ static float simdef_idf_phrase(struct FrtSimilarity *s, ID field, FrtPhrasePosit
|
|
84
78
|
return idf;
|
85
79
|
}
|
86
80
|
|
87
|
-
static float simdef_idf(struct FrtSimilarity *s, int doc_freq, int num_docs)
|
88
|
-
{
|
81
|
+
static float simdef_idf(struct FrtSimilarity *s, int doc_freq, int num_docs) {
|
89
82
|
(void)s;
|
90
83
|
return (float)(log((float)num_docs/(float)(doc_freq+1)) + 1.0);
|
91
84
|
}
|
92
85
|
|
93
|
-
static float simdef_coord(struct FrtSimilarity *s, int overlap, int max_overlap)
|
94
|
-
{
|
86
|
+
static float simdef_coord(struct FrtSimilarity *s, int overlap, int max_overlap) {
|
95
87
|
(void)s;
|
96
88
|
return (float)((double)overlap / (double)max_overlap);
|
97
89
|
}
|
98
90
|
|
99
|
-
static float simdef_decode_norm(struct FrtSimilarity *s, frt_uchar b)
|
100
|
-
{
|
91
|
+
static float simdef_decode_norm(struct FrtSimilarity *s, frt_uchar b) {
|
101
92
|
return s->norm_table[b];
|
102
93
|
}
|
103
94
|
|
104
|
-
static frt_uchar simdef_encode_norm(struct FrtSimilarity *s, float f)
|
105
|
-
{
|
95
|
+
static frt_uchar simdef_encode_norm(struct FrtSimilarity *s, float f) {
|
106
96
|
(void)s;
|
107
97
|
return frt_float2byte(f);
|
108
98
|
}
|
109
99
|
|
110
|
-
static void simdef_destroy(FrtSimilarity *s)
|
111
|
-
{
|
100
|
+
static void simdef_destroy(FrtSimilarity *s) {
|
112
101
|
(void)s;
|
113
102
|
/* nothing to do here */
|
114
103
|
}
|
@@ -25,8 +25,7 @@ extern unsigned long long frt_term_hash(const void *t);
|
|
25
25
|
*
|
26
26
|
***************************************************************************/
|
27
27
|
|
28
|
-
typedef struct FrtPhrasePosition
|
29
|
-
{
|
28
|
+
typedef struct FrtPhrasePosition {
|
30
29
|
int pos;
|
31
30
|
char **terms;
|
32
31
|
} FrtPhrasePosition;
|
@@ -145,12 +145,12 @@ FrtSortField *FRT_SORT_FIELD_SCORE_REV;
|
|
145
145
|
|
146
146
|
void frt_sort_field_doc_get_val(void *index, FrtHit *hit, FrtComparable *comparable) {
|
147
147
|
(void)index;
|
148
|
-
comparable->val.l = hit->
|
148
|
+
comparable->val.l = hit->doc_num;
|
149
149
|
}
|
150
150
|
|
151
151
|
int frt_sort_field_doc_compare(void *index_ptr, FrtHit *hit1, FrtHit *hit2) {
|
152
|
-
int val1 = hit1->
|
153
|
-
int val2 = hit2->
|
152
|
+
int val1 = hit1->doc_num;
|
153
|
+
int val2 = hit2->doc_num;
|
154
154
|
(void)index_ptr;
|
155
155
|
|
156
156
|
if (val1 > val2) return 1;
|
@@ -174,12 +174,12 @@ FrtSortField *FRT_SORT_FIELD_DOC_REV;
|
|
174
174
|
***************************************************************************/
|
175
175
|
|
176
176
|
static void sf_byte_get_val(void *index, FrtHit *hit, FrtComparable *comparable) {
|
177
|
-
comparable->val.l = ((long *)index)[hit->
|
177
|
+
comparable->val.l = ((long *)index)[hit->doc_num];
|
178
178
|
}
|
179
179
|
|
180
180
|
static int sf_byte_compare(void *index, FrtHit *hit1, FrtHit *hit2) {
|
181
|
-
long val1 = ((long *)index)[hit1->
|
182
|
-
long val2 = ((long *)index)[hit2->
|
181
|
+
long val1 = ((long *)index)[hit1->doc_num];
|
182
|
+
long val2 = ((long *)index)[hit2->doc_num];
|
183
183
|
if (val1 > val2) return 1;
|
184
184
|
else if (val1 < val2) return -1;
|
185
185
|
else return 0;
|
@@ -198,12 +198,12 @@ FrtSortField *frt_sort_field_byte_new(ID field, bool reverse) {
|
|
198
198
|
***************************************************************************/
|
199
199
|
|
200
200
|
static void sf_int_get_val(void *index, FrtHit *hit, FrtComparable *comparable) {
|
201
|
-
comparable->val.l = ((long *)index)[hit->
|
201
|
+
comparable->val.l = ((long *)index)[hit->doc_num];
|
202
202
|
}
|
203
203
|
|
204
204
|
static int sf_int_compare(void *index, FrtHit *hit1, FrtHit *hit2) {
|
205
|
-
long val1 = ((long *)index)[hit1->
|
206
|
-
long val2 = ((long *)index)[hit2->
|
205
|
+
long val1 = ((long *)index)[hit1->doc_num];
|
206
|
+
long val2 = ((long *)index)[hit2->doc_num];
|
207
207
|
if (val1 > val2) return 1;
|
208
208
|
else if (val1 < val2) return -1;
|
209
209
|
else return 0;
|
@@ -222,12 +222,12 @@ FrtSortField *frt_sort_field_int_new(ID field, bool reverse) {
|
|
222
222
|
***************************************************************************/
|
223
223
|
|
224
224
|
static void sf_float_get_val(void *index, FrtHit *hit, FrtComparable *comparable) {
|
225
|
-
comparable->val.f = ((float *)index)[hit->
|
225
|
+
comparable->val.f = ((float *)index)[hit->doc_num];
|
226
226
|
}
|
227
227
|
|
228
228
|
static int sf_float_compare(void *index, FrtHit *hit1, FrtHit *hit2) {
|
229
|
-
float val1 = ((float *)index)[hit1->
|
230
|
-
float val2 = ((float *)index)[hit2->
|
229
|
+
float val1 = ((float *)index)[hit1->doc_num];
|
230
|
+
float val2 = ((float *)index)[hit2->doc_num];
|
231
231
|
if (val1 > val2) return 1;
|
232
232
|
else if (val1 < val2) return -1;
|
233
233
|
else return 0;
|
@@ -248,14 +248,14 @@ FrtSortField *frt_sort_field_float_new(ID field, bool reverse) {
|
|
248
248
|
static void sf_string_get_val(void *index, FrtHit *hit, FrtComparable *comparable) {
|
249
249
|
comparable->val.s
|
250
250
|
= ((FrtStringIndex *)index)->values[
|
251
|
-
((FrtStringIndex *)index)->index[hit->
|
251
|
+
((FrtStringIndex *)index)->index[hit->doc_num]];
|
252
252
|
}
|
253
253
|
|
254
254
|
static int sf_string_compare(void *index, FrtHit *hit1, FrtHit *hit2) {
|
255
255
|
char *s1 = ((FrtStringIndex *)index)->values[
|
256
|
-
((FrtStringIndex *)index)->index[hit1->
|
256
|
+
((FrtStringIndex *)index)->index[hit1->doc_num]];
|
257
257
|
char *s2 = ((FrtStringIndex *)index)->values[
|
258
|
-
((FrtStringIndex *)index)->index[hit2->
|
258
|
+
((FrtStringIndex *)index)->index[hit2->doc_num]];
|
259
259
|
|
260
260
|
if (s1 == NULL) return s2 ? 1 : 0;
|
261
261
|
if (s2 == NULL) return -1;
|
@@ -427,7 +427,7 @@ static bool fshq_lt(Sorter *sorter, FrtHit *hit1, FrtHit *hit2) {
|
|
427
427
|
if (diff != 0) {
|
428
428
|
return diff > 0;
|
429
429
|
} else {
|
430
|
-
return hit1->
|
430
|
+
return hit1->doc_num > hit2->doc_num;
|
431
431
|
}
|
432
432
|
}
|
433
433
|
|
@@ -584,7 +584,7 @@ bool frt_fdshq_lt(FrtFieldDoc *fd1, FrtFieldDoc *fd2) {
|
|
584
584
|
else { all_equal = false; }
|
585
585
|
break;
|
586
586
|
case FRT_SORT_TYPE_DOC:
|
587
|
-
if (fd1->hit.
|
587
|
+
if (fd1->hit.doc_num < fd2->hit.doc_num) { all_equal = false; c = true; }
|
588
588
|
break;
|
589
589
|
case FRT_SORT_TYPE_INTEGER:
|
590
590
|
if (cmps1[i].val.l < cmps2[i].val.l) { all_equal = false; c = true; }
|
@@ -631,7 +631,7 @@ bool frt_fdshq_lt(FrtFieldDoc *fd1, FrtFieldDoc *fd2) {
|
|
631
631
|
else { all_equal = false; }
|
632
632
|
break;
|
633
633
|
case FRT_SORT_TYPE_DOC:
|
634
|
-
if (fd1->hit.
|
634
|
+
if (fd1->hit.doc_num > fd2->hit.doc_num) { all_equal = false; c = true; }
|
635
635
|
break;
|
636
636
|
case FRT_SORT_TYPE_INTEGER:
|
637
637
|
if (cmps1[i].val.l > cmps2[i].val.l) { all_equal = false; c = true; }
|
@@ -670,9 +670,9 @@ bool frt_fdshq_lt(FrtFieldDoc *fd1, FrtFieldDoc *fd2) {
|
|
670
670
|
}
|
671
671
|
if (all_equal) {
|
672
672
|
if (cmps1[0].reverse) {
|
673
|
-
if (fd1->hit.
|
673
|
+
if (fd1->hit.doc_num > fd2->hit.doc_num) c = true;
|
674
674
|
} else {
|
675
|
-
if (fd1->hit.
|
675
|
+
if (fd1->hit.doc_num > fd2->hit.doc_num) c = true;
|
676
676
|
}
|
677
677
|
}
|
678
678
|
return c;
|
@@ -1,9 +1,6 @@
|
|
1
1
|
#include "frt_store.h"
|
2
2
|
#include <string.h>
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
4
|
/*
|
8
5
|
* TODO: add try finally
|
9
6
|
*/
|
@@ -18,8 +15,8 @@ void frt_with_lock(FrtLock *lock, void (*func)(void *arg), void *arg) {
|
|
18
15
|
/*
|
19
16
|
* TODO: add try finally
|
20
17
|
*/
|
21
|
-
void frt_with_lock_name(FrtStore *store, const char *lock_name, void (*func)(void *arg), void *arg) {
|
22
|
-
FrtLock *lock = store->open_lock_i(store, lock_name);
|
18
|
+
void frt_with_lock_name(FrtStore *store, const char *folder_name, const char *lock_name, void (*func)(void *arg), void *arg) {
|
19
|
+
FrtLock *lock = store->open_lock_i(store, folder_name, lock_name);
|
23
20
|
if (!lock->obtain(lock)) {
|
24
21
|
FRT_RAISE(FRT_LOCK_ERROR, "couldn't obtain lock \"%s\"", lock->name);
|
25
22
|
}
|
@@ -28,20 +25,17 @@ void frt_with_lock_name(FrtStore *store, const char *lock_name, void (*func)(voi
|
|
28
25
|
store->close_lock_i(lock);
|
29
26
|
}
|
30
27
|
|
31
|
-
FrtLock *frt_open_lock(FrtStore *store, const char *lockname)
|
32
|
-
|
33
|
-
FrtLock *lock = store->open_lock_i(store, lockname);
|
28
|
+
FrtLock *frt_open_lock(FrtStore *store, const char *folder_name, const char *lockname) {
|
29
|
+
FrtLock *lock = store->open_lock_i(store, folder_name, lockname);
|
34
30
|
frt_hs_add(store->locks, lock);
|
35
31
|
return lock;
|
36
32
|
}
|
37
33
|
|
38
|
-
void frt_close_lock(FrtLock *lock)
|
39
|
-
{
|
34
|
+
void frt_close_lock(FrtLock *lock) {
|
40
35
|
frt_hs_del(lock->store->locks, lock);
|
41
36
|
}
|
42
37
|
|
43
|
-
static void frt_close_lock_i(FrtLock *lock)
|
44
|
-
{
|
38
|
+
static void frt_close_lock_i(FrtLock *lock) {
|
45
39
|
lock->store->close_lock_i(lock);
|
46
40
|
}
|
47
41
|
|
@@ -94,14 +88,12 @@ void frt_store_close(FrtStore *store) {
|
|
94
88
|
* @param filename the name of the file to check
|
95
89
|
* @return 1 (true) if the file is a lock file, 0 (false) otherwise
|
96
90
|
*/
|
97
|
-
int frt_file_is_lock(const char *filename)
|
98
|
-
{
|
91
|
+
int frt_file_is_lock(const char *filename) {
|
99
92
|
int start = (int) strlen(filename) - 4;
|
100
93
|
return ((start > 0) && (strcmp(FRT_LOCK_EXT, &filename[start]) == 0));
|
101
94
|
}
|
102
95
|
|
103
|
-
void frt_is2os_copy_bytes(FrtInStream *is, FrtOutStream *os, int cnt)
|
104
|
-
{
|
96
|
+
void frt_is2os_copy_bytes(FrtInStream *is, FrtOutStream *os, int cnt) {
|
105
97
|
int len;
|
106
98
|
frt_uchar buf[FRT_BUFFER_SIZE];
|
107
99
|
|
@@ -112,8 +104,7 @@ void frt_is2os_copy_bytes(FrtInStream *is, FrtOutStream *os, int cnt)
|
|
112
104
|
}
|
113
105
|
}
|
114
106
|
|
115
|
-
void frt_is2os_copy_vints(FrtInStream *is, FrtOutStream *os, int cnt)
|
116
|
-
{
|
107
|
+
void frt_is2os_copy_vints(FrtInStream *is, FrtOutStream *os, int cnt) {
|
117
108
|
frt_uchar b;
|
118
109
|
for (; cnt > 0; cnt--) {
|
119
110
|
while (((b = frt_is_read_byte(is)) & 0x80) != 0) {
|
@@ -126,8 +117,7 @@ void frt_is2os_copy_vints(FrtInStream *is, FrtOutStream *os, int cnt)
|
|
126
117
|
/**
|
127
118
|
* Test argument used to test the store->each function
|
128
119
|
*/
|
129
|
-
struct FileNameListArg
|
130
|
-
{
|
120
|
+
struct FileNameListArg {
|
131
121
|
int count;
|
132
122
|
int size;
|
133
123
|
int total_len;
|
@@ -137,8 +127,7 @@ struct FileNameListArg
|
|
137
127
|
/**
|
138
128
|
* Test function used to test store->each function
|
139
129
|
*/
|
140
|
-
static void add_file_name(const char *fname, void *arg)
|
141
|
-
{
|
130
|
+
static void add_file_name(const char *fname, void *arg) {
|
142
131
|
struct FileNameListArg *fnl = (struct FileNameListArg *)arg;
|
143
132
|
if (fnl->count >= fnl->size) {
|
144
133
|
fnl->size *= 2;
|
@@ -148,8 +137,7 @@ static void add_file_name(const char *fname, void *arg)
|
|
148
137
|
fnl->total_len += strlen(fname) + 2;
|
149
138
|
}
|
150
139
|
|
151
|
-
char *
|
152
|
-
{
|
140
|
+
char *frt_store_folder_to_s(FrtStore *store, const char *folder_name) {
|
153
141
|
struct FileNameListArg fnl;
|
154
142
|
char *buf, *b;
|
155
143
|
int i;
|
@@ -158,7 +146,7 @@ char *frt_store_to_s(FrtStore *store)
|
|
158
146
|
fnl.total_len = 10;
|
159
147
|
fnl.files = FRT_ALLOC_N(char *, 16);
|
160
148
|
|
161
|
-
store->each(store, &add_file_name, &fnl);
|
149
|
+
store->each(store, folder_name, &add_file_name, &fnl);
|
162
150
|
qsort(fnl.files, fnl.count, sizeof(char *), &frt_scmp);
|
163
151
|
b = buf = FRT_ALLOC_N(char, fnl.total_len);
|
164
152
|
|
@@ -21,7 +21,8 @@ typedef struct FrtStore FrtStore;
|
|
21
21
|
typedef struct FrtLock FrtLock;
|
22
22
|
|
23
23
|
struct FrtLock {
|
24
|
-
char *
|
24
|
+
const char *folder_name;
|
25
|
+
const char *name;
|
25
26
|
FrtStore *store;
|
26
27
|
int (*obtain)(FrtLock *lock);
|
27
28
|
int (*is_locked)(FrtLock *lock);
|
@@ -30,8 +31,9 @@ struct FrtLock {
|
|
30
31
|
};
|
31
32
|
|
32
33
|
typedef struct MDBXInfo {
|
33
|
-
MDBX_env
|
34
|
-
char
|
34
|
+
MDBX_env *env;
|
35
|
+
const char *path;
|
36
|
+
FrtStore *temp_store;
|
35
37
|
} MDBXInfo;
|
36
38
|
|
37
39
|
struct FrtStore {
|
@@ -39,7 +41,6 @@ struct FrtStore {
|
|
39
41
|
pthread_mutex_t mutex_i; /* for internal use only */
|
40
42
|
pthread_mutex_t mutex; /* external mutex for use outside */
|
41
43
|
union {
|
42
|
-
char *path; /* for fs_store only */
|
43
44
|
FrtHash *ht; /* for ram_store only */
|
44
45
|
MDBXInfo *mdbx; /* for mdbx store only */
|
45
46
|
} dir;
|
@@ -51,52 +52,76 @@ struct FrtStore {
|
|
51
52
|
FrtHashSet *locks;
|
52
53
|
|
53
54
|
/**
|
54
|
-
* Create the
|
55
|
+
* Create the folder +folder_name+ in the store if it
|
56
|
+
* doesn't exist.
|
55
57
|
*
|
56
|
-
* @param store
|
58
|
+
* @param self store
|
59
|
+
* @param folder_name the name of the folder to create
|
60
|
+
* @raise FRT_IO_ERROR if the folder cannot be created
|
61
|
+
*/
|
62
|
+
void (*create_folder)(FrtStore *self, const char *folder_name);
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Remove the folder +folder_name+ from the store.
|
66
|
+
*
|
67
|
+
* @param self store
|
68
|
+
* @param folder_name the name of the folder to remove
|
69
|
+
* @raise FRT_IO_ERROR if the folder cannot be created
|
70
|
+
*/
|
71
|
+
void (*remove_folder)(FrtStore *self, const char *folder_name);
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Create the file +filename+ in the store.
|
75
|
+
*
|
76
|
+
* @param self store
|
77
|
+
* @param folder_name the name of the folder
|
57
78
|
* @param filename the name of the file to create
|
58
79
|
* @raise FRT_IO_ERROR if the file cannot be created
|
59
80
|
*/
|
60
|
-
void (*touch)(FrtStore *
|
81
|
+
void (*touch)(FrtStore *self, const char *folder_name, const char *filename);
|
61
82
|
|
62
83
|
/**
|
63
|
-
* Return true if a file of name +filename+ exists in
|
84
|
+
* Return true if a file of name +filename+ exists in store.
|
64
85
|
*
|
65
|
-
* @param store
|
86
|
+
* @param self store
|
87
|
+
* @param folder_name the name of the folder
|
66
88
|
* @param filename the name of the file to check for
|
67
89
|
* @returns true if the file exists
|
68
|
-
* @raise FRT_IO_ERROR if there is an error checking for the files
|
90
|
+
* @raise FRT_IO_ERROR if there is an error checking for the files existence
|
69
91
|
*/
|
70
|
-
int (*exists)(FrtStore *
|
92
|
+
int (*exists)(FrtStore *self, const char *folder_name, const char *filename);
|
71
93
|
|
72
94
|
/**
|
73
|
-
* Remove the file +filename+ from the
|
95
|
+
* Remove the file +filename+ from the store.
|
74
96
|
*
|
75
|
-
* @param store
|
97
|
+
* @param self store
|
98
|
+
* @param folder_name the name of the folder
|
76
99
|
* @param filename the name of the file to remove
|
77
100
|
* @returns On success, zero is returned. On error, -1 is returned, and errno
|
78
101
|
* is set appropriately.
|
79
102
|
*/
|
80
|
-
int (*remove)(FrtStore *
|
103
|
+
int (*remove)(FrtStore *self, const char *folder_name, const char *filename);
|
81
104
|
|
82
105
|
/**
|
83
|
-
* Rename the file in the
|
106
|
+
* Rename the file in the store from the name +from+ to the name +to+.
|
84
107
|
*
|
85
|
-
* @param store
|
108
|
+
* @param self store
|
109
|
+
* @param folder_name the name of the folder
|
86
110
|
* @param from the name of the file to rename
|
87
111
|
* @param to the new name of the file
|
88
112
|
* @raise FRT_IO_ERROR if there is an error renaming the file
|
89
113
|
*/
|
90
|
-
void (*rename)(FrtStore *
|
114
|
+
void (*rename)(FrtStore *self, const char *folder_name, const char *from, const char *to);
|
91
115
|
|
92
116
|
/**
|
93
117
|
* Returns the number of files in the store.
|
94
118
|
*
|
95
|
-
* @param store
|
119
|
+
* @param self store
|
120
|
+
* @param folder_name the name of the folder
|
96
121
|
* @return the number of files in the store
|
97
122
|
* @raise FRT_IO_ERROR if there is an error opening the directory
|
98
123
|
*/
|
99
|
-
int (*count)(FrtStore *
|
124
|
+
int (*count)(FrtStore *self, const char *folder_name);
|
100
125
|
|
101
126
|
/**
|
102
127
|
* Call the function +func+ with each filename in the store and the arg
|
@@ -104,80 +129,87 @@ struct FrtStore {
|
|
104
129
|
* as the argument. If you need to pass more than one argument, you should
|
105
130
|
* pass a struct.
|
106
131
|
*
|
107
|
-
* @param store
|
132
|
+
* @param self store
|
133
|
+
* @param folder_name the name of the folder
|
108
134
|
* @param func the function to call with each files name and the +arg+
|
109
135
|
* passed
|
110
136
|
* @param arg the argument to pass to the function
|
111
137
|
* @raise FRT_IO_ERROR if there is an error opening the directory
|
112
138
|
*/
|
113
|
-
void (*each)(FrtStore *
|
114
|
-
void *arg);
|
139
|
+
void (*each)(FrtStore *self, const char *folder_name, void (*func)(const char *fname, void *arg), void *arg);
|
115
140
|
|
116
141
|
/**
|
117
142
|
* Clear all the locks in the store.
|
118
143
|
*
|
119
|
-
* @param store
|
144
|
+
* @param self store
|
145
|
+
* @param folder_name the name of the folder
|
120
146
|
* @raise FRT_IO_ERROR if there is an error opening the directory
|
121
147
|
*/
|
122
|
-
void (*clear_locks)(FrtStore *
|
148
|
+
void (*clear_locks)(FrtStore *self, const char *folder_name);
|
123
149
|
|
124
150
|
/**
|
125
151
|
* Clear all files from the store except the lock files.
|
126
152
|
*
|
127
|
-
* @param store
|
153
|
+
* @param self store
|
154
|
+
* @param folder_name the name of the folder
|
128
155
|
* @raise FRT_IO_ERROR if there is an error deleting the files
|
129
156
|
*/
|
130
|
-
void (*clear)(FrtStore *
|
157
|
+
void (*clear)(FrtStore *self, const char *folder_name);
|
131
158
|
|
132
159
|
/**
|
133
160
|
* Clear all files from the store including the lock files.
|
134
161
|
*
|
135
|
-
* @param store
|
162
|
+
* @param self store
|
163
|
+
* @param folder_name the name of the folder
|
136
164
|
* @raise FRT_IO_ERROR if there is an error deleting the files
|
137
165
|
*/
|
138
|
-
void (*clear_all)(FrtStore *
|
166
|
+
void (*clear_all)(FrtStore *self, const char *folder_name);
|
139
167
|
|
140
168
|
/**
|
141
|
-
* Return the length of the file +filename+ in +store
|
169
|
+
* Return the length of the file +filename+ in +store+.
|
142
170
|
*
|
143
|
-
* @param store
|
171
|
+
* @param self store
|
172
|
+
* @param folder_name the name of the folder
|
144
173
|
* @param the name of the file to check the length of
|
145
174
|
* @return the length of the file in bytes
|
146
175
|
* @raise FRT_IO_ERROR if there is an error checking the file length
|
147
176
|
*/
|
148
|
-
frt_off_t (*length)(FrtStore *
|
177
|
+
frt_off_t (*length)(FrtStore *self, const char *folder_name, const char *filename);
|
149
178
|
|
150
179
|
/**
|
151
180
|
* Allocate the resources needed for the output stream in the +store+ with
|
152
|
-
* the name +filename
|
181
|
+
* the name +filename+.
|
153
182
|
*
|
154
|
-
* @param store
|
183
|
+
* @param self store
|
184
|
+
* @param folder_name the name of the folder
|
155
185
|
* @param filename the name of the output stream
|
156
|
-
* @return a newly allocated
|
186
|
+
* @return a newly allocated file stream
|
157
187
|
* @raise FRT_IO_ERROR if there is an error opening the output stream
|
158
188
|
* resources
|
159
189
|
*/
|
160
|
-
FrtOutStream *(*new_output)(FrtStore *
|
190
|
+
FrtOutStream *(*new_output)(FrtStore *self, const char *folder_name, const char *filename);
|
161
191
|
|
162
192
|
/**
|
163
|
-
* Open an input stream in the +store+ with the name +filename
|
193
|
+
* Open an input stream in the +store+ with the name +filename+.
|
164
194
|
*
|
165
|
-
* @param store
|
195
|
+
* @param self store
|
196
|
+
* @param folder_name the name of the folder
|
166
197
|
* @param filename the name of the input stream
|
167
198
|
* @raise FRT_FILE_NOT_FOUND_ERROR if the input stream cannot be opened
|
168
199
|
*/
|
169
|
-
FrtInStream *(*open_input)(FrtStore *
|
200
|
+
FrtInStream *(*open_input)(FrtStore *self, const char *folder_name, const char *filename);
|
170
201
|
|
171
202
|
/**
|
172
|
-
* Obtain a lock on the lock +lock
|
203
|
+
* Obtain a lock on the lock +lock+.
|
173
204
|
*
|
174
|
-
* @param store
|
205
|
+
* @param self store
|
206
|
+
* @param folder_name the name of the folder
|
175
207
|
* @param lock the lock to obtain
|
176
208
|
*/
|
177
|
-
FrtLock *(*open_lock_i)(FrtStore *
|
209
|
+
FrtLock *(*open_lock_i)(FrtStore *self, const char *folder_name, const char *lockname);
|
178
210
|
|
179
211
|
/**
|
180
|
-
* Returns true if +lock+ is locked. To test if the file is locked:wq
|
212
|
+
* Returns true if +lock+ is locked. To test if the file is locked:wq.
|
181
213
|
*
|
182
214
|
* @param lock the lock to test
|
183
215
|
* @raise FRT_IO_ERROR if there is an error detecting the lock status
|
@@ -188,9 +220,9 @@ struct FrtStore {
|
|
188
220
|
* Internal function to close the store freeing implementation specific
|
189
221
|
* resources.
|
190
222
|
*
|
191
|
-
* @param store
|
223
|
+
* @param self store
|
192
224
|
*/
|
193
|
-
void (*close_i)(FrtStore *
|
225
|
+
void (*close_i)(FrtStore *self);
|
194
226
|
|
195
227
|
/**
|
196
228
|
* Reference to be used within ruby realm.
|
@@ -220,12 +252,13 @@ extern FrtStore *frt_open_ram_store(FrtStore *new_store);
|
|
220
252
|
* method would be used for example to read an index into memory for faster
|
221
253
|
* searching.
|
222
254
|
*
|
223
|
-
* @param
|
224
|
-
*
|
225
|
-
* @param
|
255
|
+
* @param to_store the target store
|
256
|
+
* @param from_store the store, whose contents will be copied into the newly allocated RAM store
|
257
|
+
* @param folder_name folder to be copied, will be create in the target store, if it doesn't exist
|
258
|
+
* @param close_store close the from_store whose contents where copied
|
226
259
|
* @return a newly allocated RAM FrtStore.
|
227
260
|
*/
|
228
|
-
extern FrtStore *frt_open_ram_store_and_copy(FrtStore *
|
261
|
+
extern FrtStore *frt_open_ram_store_and_copy(FrtStore *to_store, FrtStore *from_store, const char *folder_name, bool close_store);
|
229
262
|
|
230
263
|
/*
|
231
264
|
* == RamStore functions ==
|
@@ -294,7 +327,7 @@ extern void frt_with_lock(FrtLock *lock, void (*func)(void *arg), void *arg);
|
|
294
327
|
* @raise FRT_IO_ERROR if the lock is already locked
|
295
328
|
* @see frt_with_lock
|
296
329
|
*/
|
297
|
-
extern void frt_with_lock_name(FrtStore *store, const char *lock_name, void (*func)(void *arg), void *arg);
|
330
|
+
extern void frt_with_lock_name(FrtStore *store, const char *folder_name, const char *lock_name, void (*func)(void *arg), void *arg);
|
298
331
|
|
299
332
|
/**
|
300
333
|
* Remove a reference to the store. If the reference count gets to zero free
|
@@ -325,13 +358,14 @@ extern void frt_is2os_copy_bytes(FrtInStream *is, FrtOutStream *os, int cnt);
|
|
325
358
|
extern void frt_is2os_copy_vints(FrtInStream *is, FrtOutStream *os, int cnt);
|
326
359
|
|
327
360
|
/**
|
328
|
-
* Print the filenames in a store to a buffer.
|
361
|
+
* Print the filenames in a store folder to a buffer.
|
329
362
|
*
|
330
363
|
* @param store the store to get the filenames from
|
364
|
+
* @param folder_name the folder to get the filenames from
|
331
365
|
*/
|
332
|
-
extern char *
|
366
|
+
extern char *frt_store_folder_to_s(FrtStore *store, const char *folder_name);
|
333
367
|
|
334
|
-
extern FrtLock *frt_open_lock(FrtStore *store, const char *lockname);
|
368
|
+
extern FrtLock *frt_open_lock(FrtStore *store, const char *folder_name, const char *lockname);
|
335
369
|
extern void frt_close_lock(FrtLock *lock);
|
336
370
|
|
337
371
|
/* required by submodules
|