isomorfeus-ferret 0.17.2 → 0.17.3
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 +118 -125
- data/ext/isomorfeus_ferret_ext/frb_lazy_doc.c +14 -16
- data/ext/isomorfeus_ferret_ext/frb_search.c +31 -23
- 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 +2 -27
- 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 +13 -32
- 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_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 +20 -38
- data/ext/isomorfeus_ferret_ext/frt_index.c +292 -790
- data/ext/isomorfeus_ferret_ext/frt_index.h +1 -102
- 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 +85 -171
- data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +8 -16
- data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +1 -2
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +49 -98
- data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +52 -104
- data/ext/isomorfeus_ferret_ext/frt_q_range.c +6 -12
- data/ext/isomorfeus_ferret_ext/frt_q_span.c +113 -226
- 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 +82 -164
- data/ext/isomorfeus_ferret_ext/frt_similarity.c +11 -22
- data/ext/isomorfeus_ferret_ext/frt_similarity.h +1 -2
- 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 +40 -87
- 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 +15 -23
- data/ext/isomorfeus_ferret_ext/test_filter.c +17 -27
- 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 +277 -487
- 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 +60 -109
- 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 +14 -24
- 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 +14 -20
- 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 +1 -1
- data/lib/isomorfeus/ferret/version.rb +1 -1
- metadata +24 -4
@@ -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,20 +46,17 @@ 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
|
}
|
@@ -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;
|
@@ -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
|
@@ -10,8 +10,7 @@
|
|
10
10
|
*
|
11
11
|
****************************************************************************/
|
12
12
|
|
13
|
-
void frt_tv_destroy(FrtTermVector *tv)
|
14
|
-
{
|
13
|
+
void frt_tv_destroy(FrtTermVector *tv) {
|
15
14
|
int i = tv->term_cnt;
|
16
15
|
while (i > 0) {
|
17
16
|
i--;
|
@@ -23,8 +22,7 @@ void frt_tv_destroy(FrtTermVector *tv)
|
|
23
22
|
free(tv);
|
24
23
|
}
|
25
24
|
|
26
|
-
int frt_tv_scan_to_term_index(FrtTermVector *tv, const char *term)
|
27
|
-
{
|
25
|
+
int frt_tv_scan_to_term_index(FrtTermVector *tv, const char *term) {
|
28
26
|
int lo = 0; /* search starts array */
|
29
27
|
int hi = tv->term_cnt - 1; /* for 1st element < n, return its index */
|
30
28
|
int mid;
|
@@ -37,36 +35,30 @@ int frt_tv_scan_to_term_index(FrtTermVector *tv, const char *term)
|
|
37
35
|
cmp = strcmp(term, mid_term);
|
38
36
|
if (cmp < 0) {
|
39
37
|
hi = mid - 1;
|
40
|
-
}
|
41
|
-
else if (cmp > 0) {
|
38
|
+
} else if (cmp > 0) {
|
42
39
|
lo = mid + 1;
|
43
|
-
}
|
44
|
-
else { /* found a match */
|
40
|
+
} else { /* found a match */
|
45
41
|
return mid;
|
46
42
|
}
|
47
43
|
}
|
48
44
|
return lo;
|
49
45
|
}
|
50
46
|
|
51
|
-
int frt_tv_get_term_index(FrtTermVector *tv, const char *term)
|
52
|
-
{
|
47
|
+
int frt_tv_get_term_index(FrtTermVector *tv, const char *term) {
|
53
48
|
int index = frt_tv_scan_to_term_index(tv, term);
|
54
49
|
if (index < tv->term_cnt && (0 == strcmp(term, tv->terms[index].text))) {
|
55
50
|
/* found term */
|
56
51
|
return index;
|
57
|
-
}
|
58
|
-
else {
|
52
|
+
} else {
|
59
53
|
return -1;
|
60
54
|
}
|
61
55
|
}
|
62
56
|
|
63
|
-
FrtTVTerm *frt_tv_get_tv_term(FrtTermVector *tv, const char *term)
|
64
|
-
{
|
57
|
+
FrtTVTerm *frt_tv_get_tv_term(FrtTermVector *tv, const char *term) {
|
65
58
|
int index = frt_tv_get_term_index(tv, term);
|
66
59
|
if (index >= 0) {
|
67
60
|
return &(tv->terms[index]);
|
68
|
-
}
|
69
|
-
else {
|
61
|
+
} else {
|
70
62
|
return NULL;
|
71
63
|
}
|
72
64
|
}
|
@@ -4,20 +4,17 @@
|
|
4
4
|
#include "frt_global.h"
|
5
5
|
#include <io.h>
|
6
6
|
|
7
|
-
struct dirent
|
8
|
-
{
|
7
|
+
struct dirent {
|
9
8
|
char *d_name;
|
10
9
|
};
|
11
10
|
|
12
|
-
typedef struct DIR
|
13
|
-
{
|
11
|
+
typedef struct DIR {
|
14
12
|
struct _finddata_t find_data;
|
15
13
|
struct dirent de;
|
16
14
|
long handle;
|
17
15
|
} DIR;
|
18
16
|
|
19
|
-
DIR *opendir(const char *dirname)
|
20
|
-
{
|
17
|
+
DIR *opendir(const char *dirname) {
|
21
18
|
DIR *d = FRT_ALLOC_AND_ZERO(DIR);
|
22
19
|
char dirname_buf[FRT_MAX_FILE_PATH];
|
23
20
|
long ff_res;
|
@@ -33,8 +30,7 @@ DIR *opendir(const char *dirname)
|
|
33
30
|
return d;
|
34
31
|
}
|
35
32
|
|
36
|
-
struct dirent *readdir(DIR *d)
|
37
|
-
{
|
33
|
+
struct dirent *readdir(DIR *d) {
|
38
34
|
/* _findfirst already returned so do _findnext */
|
39
35
|
if (d->de.d_name != NULL) {
|
40
36
|
if (_findnext(d->handle, &d->find_data) < 0) {
|
@@ -45,8 +41,7 @@ struct dirent *readdir(DIR *d)
|
|
45
41
|
return &d->de;
|
46
42
|
}
|
47
43
|
|
48
|
-
void closedir(DIR *d)
|
49
|
-
{
|
44
|
+
void closedir(DIR *d) {
|
50
45
|
_findclose(d->handle);
|
51
46
|
free(d);
|
52
47
|
}
|
@@ -5,6 +5,8 @@
|
|
5
5
|
#include "frt_hashset.h"
|
6
6
|
#include "frt_threading.h"
|
7
7
|
|
8
|
+
const char *segm_idx_name = "segmented_index";
|
9
|
+
|
8
10
|
/* IDs */
|
9
11
|
ID id_new;
|
10
12
|
ID id_call;
|
@@ -32,21 +34,21 @@ VALUE sym_each;
|
|
32
34
|
/* Modules */
|
33
35
|
VALUE mIsomorfeus;
|
34
36
|
VALUE mFerret;
|
35
|
-
VALUE mStore;
|
36
|
-
VALUE mStringHelper;
|
37
|
-
VALUE mSpans;
|
38
37
|
|
39
38
|
/* Classes */
|
40
|
-
VALUE cTerm;
|
39
|
+
static VALUE cTerm;
|
41
40
|
VALUE cFileNotFoundError;
|
42
41
|
VALUE cParseError;
|
43
42
|
VALUE cStateError;
|
44
43
|
|
45
|
-
void Init_Benchmark(void);
|
46
|
-
void Init_Test(void);
|
44
|
+
extern void Init_Benchmark(void);
|
45
|
+
extern void Init_Test(void);
|
47
46
|
|
48
47
|
unsigned long value_hash(const void *key) {
|
49
|
-
|
48
|
+
/* double cast to prevent compiler warning:
|
49
|
+
* - first cast: pointer to number of same size
|
50
|
+
* - second cast: number to smaller number */
|
51
|
+
return (unsigned long)(uintptr_t)key;
|
50
52
|
}
|
51
53
|
|
52
54
|
int value_eq(const void *key1, const void *key2) {
|
@@ -119,15 +121,14 @@ ID frb_field(VALUE rfield) {
|
|
119
121
|
* Jeremie 'ahFeel' BORDIER
|
120
122
|
* ahFeel@rift.Fr
|
121
123
|
*/
|
122
|
-
char *json_concat_string(char *s, char *field) {
|
124
|
+
char *json_concat_string(char *s, const char *field) {
|
123
125
|
*(s++) = '"';
|
124
126
|
while (*field) {
|
125
127
|
if (*field == '"') {
|
126
128
|
*(s++) = '\'';
|
127
129
|
*(s++) = *(field++);
|
128
130
|
*(s++) = '\'';
|
129
|
-
}
|
130
|
-
else {
|
131
|
+
} else {
|
131
132
|
*(s++) = *(field++);
|
132
133
|
}
|
133
134
|
}
|
@@ -308,6 +309,6 @@ void Init_isomorfeus_ferret_ext(void) {
|
|
308
309
|
rb_define_const(mFerret, "FIX_INT_MAX", INT2FIX(INT_MAX >> 1));
|
309
310
|
}
|
310
311
|
|
311
|
-
|
312
|
+
void frb_raise(int excode, const char *msg) {
|
312
313
|
rb_raise(frb_get_error(ERROR_TYPES[excode]), "%s", msg);
|
313
314
|
}
|