isomorfeus-ferret 0.13.8 → 0.13.9
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/frb_index.c +15 -21
- data/ext/isomorfeus_ferret_ext/frb_search.c +1 -4
- data/ext/isomorfeus_ferret_ext/frb_store.c +32 -34
- data/ext/isomorfeus_ferret_ext/frt_analysis.c +2 -2
- data/ext/isomorfeus_ferret_ext/frt_analysis.h +5 -5
- data/ext/isomorfeus_ferret_ext/frt_bitvector.c +1 -1
- data/ext/isomorfeus_ferret_ext/frt_bitvector.h +1 -1
- data/ext/isomorfeus_ferret_ext/frt_compound_io.c +34 -59
- data/ext/isomorfeus_ferret_ext/frt_except.c +1 -0
- data/ext/isomorfeus_ferret_ext/frt_filter.c +2 -4
- data/ext/isomorfeus_ferret_ext/frt_fs_store.c +11 -12
- data/ext/isomorfeus_ferret_ext/frt_global.c +6 -4
- data/ext/isomorfeus_ferret_ext/frt_global.h +1 -1
- data/ext/isomorfeus_ferret_ext/frt_hash.c +40 -48
- data/ext/isomorfeus_ferret_ext/frt_hash.h +14 -16
- data/ext/isomorfeus_ferret_ext/frt_ind.c +2 -3
- data/ext/isomorfeus_ferret_ext/frt_index.c +120 -193
- data/ext/isomorfeus_ferret_ext/frt_index.h +13 -13
- data/ext/isomorfeus_ferret_ext/frt_lang.c +1 -4
- data/ext/isomorfeus_ferret_ext/frt_multimapper.c +8 -9
- data/ext/isomorfeus_ferret_ext/frt_multimapper.h +1 -1
- data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +6 -6
- data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +8 -3
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +1742 -1742
- data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +1 -2
- data/ext/isomorfeus_ferret_ext/frt_q_span.c +11 -10
- data/ext/isomorfeus_ferret_ext/frt_ram_store.c +18 -34
- data/ext/isomorfeus_ferret_ext/frt_search.c +29 -28
- data/ext/isomorfeus_ferret_ext/frt_search.h +18 -19
- data/ext/isomorfeus_ferret_ext/frt_store.c +40 -33
- data/ext/isomorfeus_ferret_ext/frt_store.h +24 -26
- data/ext/isomorfeus_ferret_ext/frt_threading.h +12 -5
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +4 -3
- data/ext/isomorfeus_ferret_ext/test_1710.c +1 -2
- data/ext/isomorfeus_ferret_ext/test_compound_io.c +8 -8
- data/ext/isomorfeus_ferret_ext/test_fields.c +7 -7
- data/ext/isomorfeus_ferret_ext/test_file_deleter.c +1 -1
- data/ext/isomorfeus_ferret_ext/test_filter.c +4 -3
- data/ext/isomorfeus_ferret_ext/test_fs_store.c +1 -1
- data/ext/isomorfeus_ferret_ext/test_highlighter.c +3 -1
- data/ext/isomorfeus_ferret_ext/test_index.c +59 -59
- data/ext/isomorfeus_ferret_ext/test_q_const_score.c +2 -1
- data/ext/isomorfeus_ferret_ext/test_q_filtered.c +3 -2
- data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +3 -1
- data/ext/isomorfeus_ferret_ext/test_q_span.c +8 -1
- data/ext/isomorfeus_ferret_ext/test_ram_store.c +4 -4
- data/ext/isomorfeus_ferret_ext/test_search.c +9 -4
- data/ext/isomorfeus_ferret_ext/test_segments.c +4 -3
- data/ext/isomorfeus_ferret_ext/test_sort.c +17 -9
- data/ext/isomorfeus_ferret_ext/test_term.c +4 -2
- data/ext/isomorfeus_ferret_ext/test_term_vectors.c +2 -2
- data/ext/isomorfeus_ferret_ext/test_threading.c +5 -4
- data/lib/isomorfeus/ferret/index/index.rb +8 -3
- data/lib/isomorfeus/ferret/version.rb +1 -1
- metadata +2 -2
@@ -313,11 +313,8 @@ FrtFieldInfo *frt_fi_new(ID name, FrtStoreValue store, FrtCompressionType compre
|
|
313
313
|
return frt_fi_init(fi, name, store, compression, index, term_vector);
|
314
314
|
}
|
315
315
|
|
316
|
-
void frt_fi_deref(FrtFieldInfo *fi)
|
317
|
-
|
318
|
-
if (0 == --(fi->ref_cnt)) {
|
319
|
-
free(fi);
|
320
|
-
}
|
316
|
+
void frt_fi_deref(FrtFieldInfo *fi) {
|
317
|
+
if (FRT_DEREF(fi) == 0) free(fi);
|
321
318
|
}
|
322
319
|
|
323
320
|
FrtCompressionType frt_fi_get_compression(FrtFieldInfo *fi) {
|
@@ -369,13 +366,13 @@ FrtFieldInfos *frt_fis_alloc(void) {
|
|
369
366
|
return FRT_ALLOC(FrtFieldInfos);
|
370
367
|
}
|
371
368
|
|
372
|
-
FrtFieldInfos *frt_fis_init(FrtFieldInfos *fis, FrtStoreValue
|
373
|
-
fi_check_params(
|
369
|
+
FrtFieldInfos *frt_fis_init(FrtFieldInfos *fis, FrtStoreValue store_val, FrtCompressionType compression, FrtIndexValue index, FrtTermVectorValue term_vector) {
|
370
|
+
fi_check_params(store_val, compression, index, term_vector);
|
374
371
|
fis->field_dict = frt_h_new_ptr((frt_free_ft)&frt_fi_deref);
|
375
372
|
fis->size = 0;
|
376
373
|
fis->capa = FIELD_INFOS_INIT_CAPA;
|
377
374
|
fis->fields = FRT_ALLOC_N(FrtFieldInfo *, fis->capa);
|
378
|
-
fis->
|
375
|
+
fis->store_val = store_val;
|
379
376
|
fis->compression = compression;
|
380
377
|
fis->index = index;
|
381
378
|
fis->term_vector = term_vector;
|
@@ -416,7 +413,7 @@ int frt_fis_get_field_num(FrtFieldInfos *fis, ID name) {
|
|
416
413
|
FrtFieldInfo *frt_fis_get_or_add_field(FrtFieldInfos *fis, ID name) {
|
417
414
|
FrtFieldInfo *fi = (FrtFieldInfo *)frt_h_get(fis->field_dict, (void *)name);
|
418
415
|
if (!fi) {
|
419
|
-
fi = (FrtFieldInfo*)frt_fi_new(name, fis->
|
416
|
+
fi = (FrtFieldInfo*)frt_fi_new(name, fis->store_val, fis->compression, fis->index, fis->term_vector);
|
420
417
|
frt_fis_add_field(fis, fi);
|
421
418
|
}
|
422
419
|
return fi;
|
@@ -465,7 +462,7 @@ void frt_fis_write(FrtFieldInfos *fis, FrtOutStream *os)
|
|
465
462
|
FrtFieldInfo *fi;
|
466
463
|
const int fis_size = fis->size;
|
467
464
|
|
468
|
-
frt_os_write_vint(os, fis->
|
465
|
+
frt_os_write_vint(os, fis->store_val);
|
469
466
|
frt_os_write_vint(os, fis->index);
|
470
467
|
frt_os_write_vint(os, fis->term_vector);
|
471
468
|
frt_os_write_vint(os, fis->size);
|
@@ -537,7 +534,7 @@ char *frt_fis_to_s(FrtFieldInfos *fis)
|
|
537
534
|
" index: %s\n"
|
538
535
|
" term_vector: %s\n"
|
539
536
|
"fields:\n",
|
540
|
-
store_str[fis->
|
537
|
+
store_str[fis->store_val],
|
541
538
|
index_str[fis->index],
|
542
539
|
term_vector_str[fis->term_vector]);
|
543
540
|
for (i = 0; i < fis_size; i++) {
|
@@ -555,9 +552,8 @@ char *frt_fis_to_s(FrtFieldInfos *fis)
|
|
555
552
|
return buf;
|
556
553
|
}
|
557
554
|
|
558
|
-
void frt_fis_deref(FrtFieldInfos *fis)
|
559
|
-
{
|
560
|
-
if (0 == --(fis->ref_cnt)) {
|
555
|
+
void frt_fis_deref(FrtFieldInfos *fis) {
|
556
|
+
if (FRT_DEREF(fis) == 0) {
|
561
557
|
frt_h_destroy(fis->field_dict);
|
562
558
|
free(fis->fields);
|
563
559
|
free(fis);
|
@@ -589,6 +585,7 @@ FrtSegmentInfo *frt_si_new(char *name, int doc_cnt, FrtStore *store)
|
|
589
585
|
si->name = name;
|
590
586
|
si->doc_cnt = doc_cnt;
|
591
587
|
si->store = store;
|
588
|
+
FRT_REF(store);
|
592
589
|
si->del_gen = -1;
|
593
590
|
si->norm_gens = NULL;
|
594
591
|
si->norm_gens_size = 0;
|
@@ -602,6 +599,7 @@ static FrtSegmentInfo *si_read(FrtStore *store, FrtInStream *is)
|
|
602
599
|
FrtSegmentInfo *volatile si = FRT_ALLOC_AND_ZERO(FrtSegmentInfo);
|
603
600
|
FRT_TRY
|
604
601
|
si->store = store;
|
602
|
+
FRT_REF(store);
|
605
603
|
si->name = frt_is_read_string_safe(is);
|
606
604
|
si->doc_cnt = frt_is_read_vint(is);
|
607
605
|
si->del_gen = frt_is_read_vint(is);
|
@@ -616,6 +614,7 @@ static FrtSegmentInfo *si_read(FrtStore *store, FrtInStream *is)
|
|
616
614
|
}
|
617
615
|
si->use_compound_file = (bool)frt_is_read_byte(is);
|
618
616
|
FRT_XCATCHALL
|
617
|
+
frt_store_close(si->store);
|
619
618
|
free(si->name);
|
620
619
|
free(si);
|
621
620
|
FRT_XENDTRY
|
@@ -637,9 +636,9 @@ static void si_write(FrtSegmentInfo *si, FrtOutStream *os)
|
|
637
636
|
frt_os_write_byte(os, (frt_uchar)si->use_compound_file);
|
638
637
|
}
|
639
638
|
|
640
|
-
void
|
641
|
-
{
|
642
|
-
|
639
|
+
void frt_si_close(FrtSegmentInfo *si) {
|
640
|
+
if (FRT_DEREF(si) == 0) {
|
641
|
+
frt_store_close(si->store);
|
643
642
|
free(si->name);
|
644
643
|
free(si->norm_gens);
|
645
644
|
free(si);
|
@@ -760,8 +759,7 @@ static void which_gen_i(const char *file_name, void *arg)
|
|
760
759
|
}
|
761
760
|
}
|
762
761
|
|
763
|
-
static void si_put(FrtSegmentInfo *si, FILE *stream)
|
764
|
-
{
|
762
|
+
static void si_put(FrtSegmentInfo *si, FILE *stream) {
|
765
763
|
int i;
|
766
764
|
fprintf(stream, "\tSegmentInfo {\n");
|
767
765
|
fprintf(stream, "\t\tname = %s\n", si->name);
|
@@ -777,8 +775,7 @@ static void si_put(FrtSegmentInfo *si, FILE *stream)
|
|
777
775
|
fprintf(stream, "\t}\n");
|
778
776
|
}
|
779
777
|
|
780
|
-
void frt_sis_put(FrtSegmentInfos *sis, FILE *stream)
|
781
|
-
{
|
778
|
+
void frt_sis_put(FrtSegmentInfos *sis, FILE *stream) {
|
782
779
|
int i;
|
783
780
|
fprintf(stream, "SegmentInfos {\n");
|
784
781
|
fprintf(stream, "\tcounter = %"POSH_I64_PRINTF_PREFIX"d\n", sis->counter);
|
@@ -860,7 +857,6 @@ static void sis_find_segments_file(FrtStore *store, FindSegmentsFile *fsf, void
|
|
860
857
|
if (0 == method) {
|
861
858
|
gen = frt_sis_current_segment_generation(store);
|
862
859
|
if (gen == -1) {
|
863
|
-
// fprintf(stderr, ">>\n%s\n>>\n", frt_store_to_s(store));
|
864
860
|
FRT_RAISE(FRT_FILE_NOT_FOUND_ERROR, "couldn't find segments file");
|
865
861
|
}
|
866
862
|
}
|
@@ -946,32 +942,6 @@ static void sis_find_segments_file(FrtStore *store, FindSegmentsFile *fsf, void
|
|
946
942
|
return;
|
947
943
|
case FRT_IO_ERROR: case FRT_FILE_NOT_FOUND_ERROR: case FRT_EOF_ERROR:
|
948
944
|
FRT_HANDLED();
|
949
|
-
/*
|
950
|
-
if (gen != frt_sis_current_segment_generation(store)) {
|
951
|
-
fprintf(stderr, "%lld != %lld\n",
|
952
|
-
gen, frt_sis_current_segment_generation(store));
|
953
|
-
fprintf(stderr, "%s\n", xcontext.msg);
|
954
|
-
}
|
955
|
-
else {
|
956
|
-
char *sl = frt_store_to_s(store);
|
957
|
-
bool done = false;
|
958
|
-
fprintf(stderr, "%s\n>>>\n%s", xcontext.msg, sl);
|
959
|
-
free(sl);
|
960
|
-
while (!done) {
|
961
|
-
FRT_TRY
|
962
|
-
frt_sis_put(frt_sis_read(store), stderr);
|
963
|
-
done = true;
|
964
|
-
FRT_XCATCHALL
|
965
|
-
FRT_HANDLED();
|
966
|
-
FRT_XENDTRY
|
967
|
-
}
|
968
|
-
}
|
969
|
-
|
970
|
-
char *sl = frt_store_to_s(store);
|
971
|
-
fprintf(stderr, "%s\n>>>\n%s", xcontext.msg, sl);
|
972
|
-
free(sl);
|
973
|
-
*/
|
974
|
-
|
975
945
|
/* Save the original root cause: */
|
976
946
|
/* TODO:LOG "primary Exception on '" + segmentFileName + "': " +
|
977
947
|
* err + "'; will retry: retry=" + retry + "; gen = " + gen */
|
@@ -1031,8 +1001,9 @@ void frt_sis_destroy(FrtSegmentInfos *sis)
|
|
1031
1001
|
int i;
|
1032
1002
|
const int sis_size = sis->size;
|
1033
1003
|
for (i = 0; i < sis_size; i++) {
|
1034
|
-
|
1004
|
+
frt_si_close(sis->segs[i]);
|
1035
1005
|
}
|
1006
|
+
if (sis->store) frt_store_close(sis->store);
|
1036
1007
|
if (sis->fis) frt_fis_deref(sis->fis);
|
1037
1008
|
free(sis->segs);
|
1038
1009
|
free(sis);
|
@@ -1052,7 +1023,7 @@ void frt_sis_del_at(FrtSegmentInfos *sis, int at)
|
|
1052
1023
|
{
|
1053
1024
|
int i;
|
1054
1025
|
const int sis_size = --(sis->size);
|
1055
|
-
|
1026
|
+
frt_si_close(sis->segs[at]);
|
1056
1027
|
for (i = at; i < sis_size; i++) {
|
1057
1028
|
sis->segs[i] = sis->segs[i+1];
|
1058
1029
|
}
|
@@ -1063,7 +1034,7 @@ void frt_sis_del_from_to(FrtSegmentInfos *sis, int from, int to)
|
|
1063
1034
|
int i, num_to_del = to - from;
|
1064
1035
|
const int sis_size = sis->size -= num_to_del;
|
1065
1036
|
for (i = from; i < to; i++) {
|
1066
|
-
|
1037
|
+
frt_si_close(sis->segs[i]);
|
1067
1038
|
}
|
1068
1039
|
for (i = from; i < sis_size; i++) {
|
1069
1040
|
sis->segs[i] = sis->segs[i+num_to_del];
|
@@ -1083,6 +1054,7 @@ static void frt_sis_read_i(FrtStore *store, FindSegmentsFile *fsf, FrtIndexReade
|
|
1083
1054
|
FRT_TRY
|
1084
1055
|
is = store->open_input(store, seg_file_name);
|
1085
1056
|
sis->store = store;
|
1057
|
+
FRT_REF(store);
|
1086
1058
|
sis->generation = fsf->generation;
|
1087
1059
|
sis->format = frt_is_read_u32(is); /* do nothing. it's the first version */
|
1088
1060
|
sis->version = frt_is_read_u64(is);
|
@@ -1530,7 +1502,6 @@ FrtLazyDocField *frt_lazy_doc_get(FrtLazyDoc *self, ID field) {
|
|
1530
1502
|
|
1531
1503
|
FrtFieldsReader *frt_fr_open(FrtStore *store, const char *segment, FrtFieldInfos *fis) {
|
1532
1504
|
FrtFieldsReader *fr = FRT_ALLOC(FrtFieldsReader);
|
1533
|
-
FrtInStream *fdx_in;
|
1534
1505
|
char file_name[FRT_SEGMENT_NAME_MAX_LENGTH];
|
1535
1506
|
size_t segment_len = strlen(segment);
|
1536
1507
|
|
@@ -1541,9 +1512,10 @@ FrtFieldsReader *frt_fr_open(FrtStore *store, const char *segment, FrtFieldInfos
|
|
1541
1512
|
strcpy(file_name + segment_len, ".fdt");
|
1542
1513
|
fr->fdt_in = store->open_input(store, file_name);
|
1543
1514
|
strcpy(file_name + segment_len, ".fdx");
|
1544
|
-
|
1545
|
-
fr->size = frt_is_length(fdx_in) / FIELDS_IDX_PTR_SIZE;
|
1515
|
+
fr->fdx_in = store->open_input(store, file_name);
|
1516
|
+
fr->size = frt_is_length(fr->fdx_in) / FIELDS_IDX_PTR_SIZE;
|
1546
1517
|
fr->store = store;
|
1518
|
+
FRT_REF(store);
|
1547
1519
|
|
1548
1520
|
return fr;
|
1549
1521
|
}
|
@@ -1552,6 +1524,7 @@ FrtFieldsReader *frt_fr_clone(FrtFieldsReader *orig) {
|
|
1552
1524
|
FrtFieldsReader *fr = FRT_ALLOC(FrtFieldsReader);
|
1553
1525
|
|
1554
1526
|
memcpy(fr, orig, sizeof(FrtFieldsReader));
|
1527
|
+
FRT_REF(fr->store);
|
1555
1528
|
fr->fdx_in = frt_is_clone(orig->fdx_in);
|
1556
1529
|
fr->fdt_in = frt_is_clone(orig->fdt_in);
|
1557
1530
|
|
@@ -1561,6 +1534,7 @@ FrtFieldsReader *frt_fr_clone(FrtFieldsReader *orig) {
|
|
1561
1534
|
void frt_fr_close(FrtFieldsReader *fr) {
|
1562
1535
|
frt_is_close(fr->fdt_in);
|
1563
1536
|
frt_is_close(fr->fdx_in);
|
1537
|
+
frt_store_close(fr->store);
|
1564
1538
|
free(fr);
|
1565
1539
|
}
|
1566
1540
|
|
@@ -1778,8 +1752,7 @@ FrtHash *frt_fr_get_tv(FrtFieldsReader *fr, int doc_num)
|
|
1778
1752
|
return term_vectors;
|
1779
1753
|
}
|
1780
1754
|
|
1781
|
-
FrtTermVector *frt_fr_get_field_tv(FrtFieldsReader *fr, int doc_num, int field_num)
|
1782
|
-
{
|
1755
|
+
FrtTermVector *frt_fr_get_field_tv(FrtFieldsReader *fr, int doc_num, int field_num) {
|
1783
1756
|
FrtTermVector *tv = NULL;
|
1784
1757
|
|
1785
1758
|
if (doc_num >= 0 && doc_num < fr->size) {
|
@@ -2175,9 +2148,7 @@ static void sti_destroy(FrtSegmentTermIndex *sti)
|
|
2175
2148
|
free(sti);
|
2176
2149
|
}
|
2177
2150
|
|
2178
|
-
static void sti_ensure_index_is_read(FrtSegmentTermIndex *sti,
|
2179
|
-
FrtTermEnum *index_te)
|
2180
|
-
{
|
2151
|
+
static void sti_ensure_index_is_read(FrtSegmentTermIndex *sti, FrtTermEnum *index_te) {
|
2181
2152
|
if (NULL == sti->index_terms) {
|
2182
2153
|
int i;
|
2183
2154
|
int index_cnt = sti->index_cnt;
|
@@ -2241,8 +2212,7 @@ static int sti_get_index_offset(FrtSegmentTermIndex *sti, const char *term)
|
|
2241
2212
|
}\
|
2242
2213
|
} while (0)
|
2243
2214
|
|
2244
|
-
FrtSegmentFieldIndex *frt_sfi_open(FrtStore *store, const char *segment)
|
2245
|
-
{
|
2215
|
+
FrtSegmentFieldIndex *frt_sfi_open(FrtStore *store, const char *segment) {
|
2246
2216
|
int field_count;
|
2247
2217
|
FrtSegmentFieldIndex *sfi = FRT_ALLOC(FrtSegmentFieldIndex);
|
2248
2218
|
char file_name[FRT_SEGMENT_NAME_MAX_LENGTH];
|
@@ -2271,12 +2241,12 @@ FrtSegmentFieldIndex *frt_sfi_open(FrtStore *store, const char *segment)
|
|
2271
2241
|
|
2272
2242
|
sprintf(file_name, "%s.tix", segment);
|
2273
2243
|
is = store->open_input(store, file_name);
|
2244
|
+
FRT_DEREF(is);
|
2274
2245
|
sfi->index_te = frt_ste_new(is, sfi);
|
2275
2246
|
return sfi;
|
2276
2247
|
}
|
2277
2248
|
|
2278
|
-
void frt_sfi_close(FrtSegmentFieldIndex *sfi)
|
2279
|
-
{
|
2249
|
+
void frt_sfi_close(FrtSegmentFieldIndex *sfi) {
|
2280
2250
|
frt_mutex_destroy(&sfi->mutex);
|
2281
2251
|
frt_ste_close(sfi->index_te);
|
2282
2252
|
frt_h_destroy(sfi->field_dict);
|
@@ -2287,8 +2257,7 @@ void frt_sfi_close(FrtSegmentFieldIndex *sfi)
|
|
2287
2257
|
* SegmentTermEnum
|
2288
2258
|
****************************************************************************/
|
2289
2259
|
|
2290
|
-
static int term_read(char *buf, FrtInStream *is)
|
2291
|
-
{
|
2260
|
+
static int term_read(char *buf, FrtInStream *is) {
|
2292
2261
|
int start = (int)frt_is_read_vint(is);
|
2293
2262
|
int length = (int)frt_is_read_vint(is);
|
2294
2263
|
int total_length = start + length;
|
@@ -2297,8 +2266,7 @@ static int term_read(char *buf, FrtInStream *is)
|
|
2297
2266
|
return total_length;
|
2298
2267
|
}
|
2299
2268
|
|
2300
|
-
static char *ste_next(FrtTermEnum *te)
|
2301
|
-
{
|
2269
|
+
static char *ste_next(FrtTermEnum *te) {
|
2302
2270
|
FrtTermInfo *ti;
|
2303
2271
|
FrtInStream *is = STE(te)->is;
|
2304
2272
|
|
@@ -2323,32 +2291,27 @@ static char *ste_next(FrtTermEnum *te)
|
|
2323
2291
|
return te->curr_term;
|
2324
2292
|
}
|
2325
2293
|
|
2326
|
-
static void ste_reset(FrtTermEnum *te)
|
2327
|
-
{
|
2294
|
+
static void ste_reset(FrtTermEnum *te) {
|
2328
2295
|
STE(te)->pos = -1;
|
2329
2296
|
te->curr_term[0] = '\0';
|
2330
2297
|
te->curr_term_len = 0;
|
2331
2298
|
FRT_ZEROSET(&(te->curr_ti), FrtTermInfo);
|
2332
2299
|
}
|
2333
2300
|
|
2334
|
-
static FrtTermEnum *ste_set_field(FrtTermEnum *te, int field_num)
|
2335
|
-
|
2336
|
-
FrtSegmentTermIndex *sti
|
2337
|
-
= (FrtSegmentTermIndex *)frt_h_get_int(STE(te)->sfi->field_dict, field_num);
|
2301
|
+
static FrtTermEnum *ste_set_field(FrtTermEnum *te, int field_num) {
|
2302
|
+
FrtSegmentTermIndex *sti = (FrtSegmentTermIndex *)frt_h_get_int(STE(te)->sfi->field_dict, field_num);
|
2338
2303
|
ste_reset(te);
|
2339
2304
|
te->field_num = field_num;
|
2340
2305
|
if (sti) {
|
2341
2306
|
STE(te)->size = sti->size;
|
2342
2307
|
frt_is_seek(STE(te)->is, sti->ptr);
|
2343
|
-
}
|
2344
|
-
else {
|
2308
|
+
} else {
|
2345
2309
|
STE(te)->size = 0;
|
2346
2310
|
}
|
2347
2311
|
return te;
|
2348
2312
|
}
|
2349
2313
|
|
2350
|
-
static void frt_ste_index_seek(FrtTermEnum *te, FrtSegmentTermIndex *sti, int idx_offset)
|
2351
|
-
{
|
2314
|
+
static void frt_ste_index_seek(FrtTermEnum *te, FrtSegmentTermIndex *sti, int idx_offset) {
|
2352
2315
|
int term_len = sti->index_term_lens[idx_offset];
|
2353
2316
|
frt_is_seek(STE(te)->is, sti->index_ptrs[idx_offset]);
|
2354
2317
|
STE(te)->pos = STE(te)->sfi->index_interval * idx_offset - 1;
|
@@ -2359,11 +2322,9 @@ static void frt_ste_index_seek(FrtTermEnum *te, FrtSegmentTermIndex *sti, int id
|
|
2359
2322
|
te->curr_ti = sti->index_term_infos[idx_offset];
|
2360
2323
|
}
|
2361
2324
|
|
2362
|
-
static char *ste_scan_to(FrtTermEnum *te, const char *term)
|
2363
|
-
{
|
2325
|
+
static char *ste_scan_to(FrtTermEnum *te, const char *term) {
|
2364
2326
|
FrtSegmentFieldIndex *sfi = STE(te)->sfi;
|
2365
|
-
FrtSegmentTermIndex *sti
|
2366
|
-
= (FrtSegmentTermIndex *)frt_h_get_int(sfi->field_dict, te->field_num);
|
2327
|
+
FrtSegmentTermIndex *sti = (FrtSegmentTermIndex *)frt_h_get_int(sfi->field_dict, te->field_num);
|
2367
2328
|
if (sti && sti->size > 0) {
|
2368
2329
|
SFI_ENSURE_INDEX_IS_READ(sfi, sti);
|
2369
2330
|
if (term[0] == '\0') {
|
@@ -2383,9 +2344,7 @@ static char *ste_scan_to(FrtTermEnum *te, const char *term)
|
|
2383
2344
|
frt_ste_index_seek(te, sti, sti_get_index_offset(sti, term));
|
2384
2345
|
return te_skip_to(te, term);
|
2385
2346
|
}
|
2386
|
-
|
2387
|
-
return NULL;
|
2388
|
-
}
|
2347
|
+
return NULL;
|
2389
2348
|
}
|
2390
2349
|
|
2391
2350
|
static FrtSegmentTermEnum *ste_allocate(void) {
|
@@ -2398,8 +2357,7 @@ static FrtSegmentTermEnum *ste_allocate(void) {
|
|
2398
2357
|
return ste;
|
2399
2358
|
}
|
2400
2359
|
|
2401
|
-
FrtTermEnum *frt_ste_clone(FrtTermEnum *other_te)
|
2402
|
-
{
|
2360
|
+
FrtTermEnum *frt_ste_clone(FrtTermEnum *other_te) {
|
2403
2361
|
FrtSegmentTermEnum *ste = ste_allocate();
|
2404
2362
|
|
2405
2363
|
memcpy(ste, other_te, sizeof(FrtSegmentTermEnum));
|
@@ -2407,8 +2365,7 @@ FrtTermEnum *frt_ste_clone(FrtTermEnum *other_te)
|
|
2407
2365
|
return TE(ste);
|
2408
2366
|
}
|
2409
2367
|
|
2410
|
-
void frt_ste_close(FrtTermEnum *te)
|
2411
|
-
{
|
2368
|
+
void frt_ste_close(FrtTermEnum *te) {
|
2412
2369
|
frt_is_close(STE(te)->is);
|
2413
2370
|
free(te);
|
2414
2371
|
}
|
@@ -2422,8 +2379,7 @@ static char *frt_ste_get_term(FrtTermEnum *te, int pos)
|
|
2422
2379
|
else if (pos != ste->pos) {
|
2423
2380
|
int idx_int = ste->sfi->index_interval;
|
2424
2381
|
if ((pos < ste->pos) || pos > (1 + ste->pos / idx_int) * idx_int) {
|
2425
|
-
FrtSegmentTermIndex *sti = (FrtSegmentTermIndex *)frt_h_get_int(
|
2426
|
-
ste->sfi->field_dict, te->field_num);
|
2382
|
+
FrtSegmentTermIndex *sti = (FrtSegmentTermIndex *)frt_h_get_int(ste->sfi->field_dict, te->field_num);
|
2427
2383
|
SFI_ENSURE_INDEX_IS_READ(ste->sfi, sti);
|
2428
2384
|
frt_ste_index_seek(te, sti, pos / idx_int);
|
2429
2385
|
}
|
@@ -2443,6 +2399,7 @@ FrtTermEnum *frt_ste_new(FrtInStream *is, FrtSegmentFieldIndex *sfi)
|
|
2443
2399
|
|
2444
2400
|
TE(ste)->field_num = -1;
|
2445
2401
|
ste->is = is;
|
2402
|
+
FRT_REF(is);
|
2446
2403
|
ste->size = 0;
|
2447
2404
|
ste->pos = -1;
|
2448
2405
|
ste->sfi = sfi;
|
@@ -2490,25 +2447,6 @@ static bool tew_lt(const TermEnumWrapper *tew1, const TermEnumWrapper *tew2)
|
|
2490
2447
|
}
|
2491
2448
|
}
|
2492
2449
|
|
2493
|
-
/*
|
2494
|
-
static void tew_load_doc_map(TermEnumWrapper *tew)
|
2495
|
-
{
|
2496
|
-
int j = 0, i;
|
2497
|
-
FrtIndexReader *ir = tew->ir;
|
2498
|
-
int max_doc = ir->max_doc(ir);
|
2499
|
-
int *doc_map = tew->doc_map = FRT_ALLOC_N(int, max_doc);
|
2500
|
-
|
2501
|
-
for (i = 0; i < max_doc; i++) {
|
2502
|
-
if (ir->is_deleted(ir, i)) {
|
2503
|
-
doc_map[i] = -1;
|
2504
|
-
}
|
2505
|
-
else {
|
2506
|
-
doc_map[i] = j++;
|
2507
|
-
}
|
2508
|
-
}
|
2509
|
-
}
|
2510
|
-
*/
|
2511
|
-
|
2512
2450
|
static char *tew_next(TermEnumWrapper *tew)
|
2513
2451
|
{
|
2514
2452
|
return (tew->term = tew->te->next(tew->te));
|
@@ -2521,6 +2459,7 @@ static char *tew_skip_to(TermEnumWrapper *tew, const char *term)
|
|
2521
2459
|
|
2522
2460
|
static void tew_destroy(TermEnumWrapper *tew)
|
2523
2461
|
{
|
2462
|
+
frt_ir_close(tew->ir);
|
2524
2463
|
if (tew->doc_map) {
|
2525
2464
|
free(tew->doc_map);
|
2526
2465
|
}
|
@@ -2530,6 +2469,7 @@ static void tew_destroy(TermEnumWrapper *tew)
|
|
2530
2469
|
static TermEnumWrapper *tew_setup(TermEnumWrapper *tew, int index, FrtTermEnum *te, FrtIndexReader *ir) {
|
2531
2470
|
tew->index = index;
|
2532
2471
|
tew->ir = ir;
|
2472
|
+
FRT_REF(ir);
|
2533
2473
|
tew->te = te;
|
2534
2474
|
tew->term = te->curr_term;
|
2535
2475
|
tew->doc_map = NULL;
|
@@ -2689,11 +2629,13 @@ FrtTermInfosReader *frt_tir_open(FrtStore *store, FrtSegmentFieldIndex *sfi, con
|
|
2689
2629
|
char file_name[FRT_SEGMENT_NAME_MAX_LENGTH];
|
2690
2630
|
|
2691
2631
|
sprintf(file_name, "%s.tis", segment);
|
2692
|
-
|
2632
|
+
FrtInStream *is = store->open_input(store, file_name);
|
2633
|
+
FRT_DEREF(is);
|
2634
|
+
tir->orig_te = frt_ste_new(is, sfi);
|
2635
|
+
tir->thread_te = 0;
|
2693
2636
|
frt_thread_key_create(&tir->thread_te, NULL);
|
2694
2637
|
tir->te_bucket = frt_ary_new();
|
2695
2638
|
tir->field_num = -1;
|
2696
|
-
|
2697
2639
|
return tir;
|
2698
2640
|
}
|
2699
2641
|
|
@@ -2751,14 +2693,9 @@ char *frt_tir_get_term(FrtTermInfosReader *tir, int pos) {
|
|
2751
2693
|
}
|
2752
2694
|
}
|
2753
2695
|
|
2754
|
-
|
2755
2696
|
void frt_tir_close(FrtTermInfosReader *tir) {
|
2756
2697
|
frt_ary_destroy(tir->te_bucket, (frt_free_ft)&frt_ste_close);
|
2757
2698
|
frt_ste_close(tir->orig_te);
|
2758
|
-
|
2759
|
-
/* fix for some dodgy old versions of pthread */
|
2760
|
-
frt_thread_setspecific(tir->thread_te, NULL);
|
2761
|
-
|
2762
2699
|
frt_thread_key_delete(tir->thread_te);
|
2763
2700
|
free(tir);
|
2764
2701
|
}
|
@@ -3696,11 +3633,13 @@ FrtDeleter *frt_deleter_new(FrtSegmentInfos *sis, FrtStore *store) {
|
|
3696
3633
|
FrtDeleter *dlr = FRT_ALLOC(FrtDeleter);
|
3697
3634
|
dlr->sis = sis;
|
3698
3635
|
dlr->store = store;
|
3636
|
+
FRT_REF(store);
|
3699
3637
|
dlr->pending = frt_hs_new_str(&free);
|
3700
3638
|
return dlr;
|
3701
3639
|
}
|
3702
3640
|
|
3703
3641
|
void frt_deleter_destroy(FrtDeleter *dlr) {
|
3642
|
+
frt_store_close(dlr->store);
|
3704
3643
|
frt_hs_destroy(dlr->pending);
|
3705
3644
|
free(dlr);
|
3706
3645
|
}
|
@@ -3821,7 +3760,7 @@ void frt_deleter_find_deletable_files(FrtDeleter *dlr) {
|
|
3821
3760
|
FrtStore *store = dlr->store;
|
3822
3761
|
struct DelFilesArg dfa;
|
3823
3762
|
FrtHash *current = dfa.current
|
3824
|
-
= frt_h_new_str((frt_free_ft)NULL, (frt_free_ft)
|
3763
|
+
= frt_h_new_str((frt_free_ft)NULL, (frt_free_ft)frt_si_close);
|
3825
3764
|
dfa.dlr = dlr;
|
3826
3765
|
|
3827
3766
|
for(i = 0; i < sis->size; i++) {
|
@@ -4096,37 +4035,28 @@ void frt_ir_commit(FrtIndexReader *ir)
|
|
4096
4035
|
frt_mutex_unlock(&ir->mutex);
|
4097
4036
|
}
|
4098
4037
|
|
4099
|
-
void frt_ir_close(FrtIndexReader *ir)
|
4100
|
-
{
|
4101
|
-
|
4102
|
-
|
4038
|
+
void frt_ir_close(FrtIndexReader *ir) {
|
4039
|
+
if (ir->ref_cnt == 0) {
|
4040
|
+
fprintf(stderr, "ir ref_cnt to low\n");
|
4041
|
+
FRT_RAISE(FRT_STATE_ERROR, "ir ref_cnt to low\n");
|
4042
|
+
}
|
4043
|
+
|
4044
|
+
if (FRT_DEREF(ir) == 0) {
|
4045
|
+
frt_mutex_lock(&ir->mutex);
|
4103
4046
|
ir_commit_i(ir);
|
4104
4047
|
ir->close_i(ir);
|
4105
|
-
if (ir->store)
|
4106
|
-
|
4107
|
-
|
4108
|
-
if (ir->
|
4109
|
-
|
4110
|
-
}
|
4111
|
-
if (ir->cache) {
|
4112
|
-
frt_h_destroy(ir->cache);
|
4113
|
-
}
|
4114
|
-
if (ir->field_index_cache) {
|
4115
|
-
frt_h_destroy(ir->field_index_cache);
|
4116
|
-
}
|
4117
|
-
if (ir->deleter && ir->is_owner) {
|
4118
|
-
frt_deleter_destroy(ir->deleter);
|
4119
|
-
}
|
4048
|
+
if (ir->store) frt_store_close(ir->store);
|
4049
|
+
if (ir->is_owner && ir->sis) frt_sis_destroy(ir->sis);
|
4050
|
+
if (ir->cache) frt_h_destroy(ir->cache);
|
4051
|
+
if (ir->field_index_cache) frt_h_destroy(ir->field_index_cache);
|
4052
|
+
if (ir->deleter && ir->is_owner) frt_deleter_destroy(ir->deleter);
|
4120
4053
|
free(ir->fake_norms);
|
4121
4054
|
|
4122
|
-
frt_mutex_destroy(&ir->mutex);
|
4123
4055
|
frt_mutex_destroy(&ir->field_index_mutex);
|
4124
|
-
free(ir);
|
4125
|
-
}
|
4126
|
-
else {
|
4127
4056
|
frt_mutex_unlock(&ir->mutex);
|
4057
|
+
frt_mutex_destroy(&ir->mutex);
|
4058
|
+
free(ir);
|
4128
4059
|
}
|
4129
|
-
|
4130
4060
|
}
|
4131
4061
|
|
4132
4062
|
/**
|
@@ -4160,6 +4090,7 @@ static Norm *norm_create(FrtInStream *is, int field_num)
|
|
4160
4090
|
Norm *norm = FRT_ALLOC(Norm);
|
4161
4091
|
|
4162
4092
|
norm->is = is;
|
4093
|
+
FRT_REF(is);
|
4163
4094
|
norm->field_num = field_num;
|
4164
4095
|
norm->bytes = NULL;
|
4165
4096
|
norm->is_dirty = false;
|
@@ -4202,10 +4133,8 @@ static void norm_rewrite(Norm *norm, FrtStore *store, FrtDeleter *dlr,
|
|
4202
4133
|
#define SR(ir) ((FrtSegmentReader *)(ir))
|
4203
4134
|
#define SR_SIZE(ir) (SR(ir)->fr->size)
|
4204
4135
|
|
4205
|
-
static FrtFieldsReader *sr_fr(FrtSegmentReader *sr)
|
4206
|
-
{
|
4136
|
+
static FrtFieldsReader *sr_fr(FrtSegmentReader *sr) {
|
4207
4137
|
FrtFieldsReader *fr;
|
4208
|
-
|
4209
4138
|
if (NULL == (fr = (FrtFieldsReader *)frt_thread_getspecific(sr->thread_fr))) {
|
4210
4139
|
fr = frt_fr_clone(sr->fr);
|
4211
4140
|
frt_ary_push(sr->fr_bucket, fr);
|
@@ -4219,17 +4148,13 @@ static bool sr_is_deleted_i(FrtSegmentReader *sr, int doc_num)
|
|
4219
4148
|
return (NULL != sr->deleted_docs && frt_bv_get(sr->deleted_docs, doc_num));
|
4220
4149
|
}
|
4221
4150
|
|
4222
|
-
static void sr_get_norms_into_i(FrtSegmentReader *sr, int field_num,
|
4223
|
-
frt_uchar *buf)
|
4224
|
-
{
|
4151
|
+
static void sr_get_norms_into_i(FrtSegmentReader *sr, int field_num, frt_uchar *buf) {
|
4225
4152
|
Norm *norm = (Norm *)frt_h_get_int(sr->norms, field_num);
|
4226
4153
|
if (NULL == norm) {
|
4227
4154
|
memset(buf, 0, SR_SIZE(sr));
|
4228
|
-
}
|
4229
|
-
else if (NULL != norm->bytes) { /* can copy from cache */
|
4155
|
+
} else if (NULL != norm->bytes) { /* can copy from cache */
|
4230
4156
|
memcpy(buf, norm->bytes, SR_SIZE(sr));
|
4231
|
-
}
|
4232
|
-
else {
|
4157
|
+
} else {
|
4233
4158
|
FrtInStream *norm_in = frt_is_clone(norm->is);
|
4234
4159
|
/* read from disk */
|
4235
4160
|
frt_is_seek(norm_in, 0);
|
@@ -4238,8 +4163,7 @@ static void sr_get_norms_into_i(FrtSegmentReader *sr, int field_num,
|
|
4238
4163
|
}
|
4239
4164
|
}
|
4240
4165
|
|
4241
|
-
static frt_uchar *sr_get_norms_i(FrtSegmentReader *sr, int field_num)
|
4242
|
-
{
|
4166
|
+
static frt_uchar *sr_get_norms_i(FrtSegmentReader *sr, int field_num) {
|
4243
4167
|
Norm *norm = (Norm *)frt_h_get_int(sr->norms, field_num);
|
4244
4168
|
if (NULL == norm) { /* not an indexed field */
|
4245
4169
|
return NULL;
|
@@ -4253,8 +4177,7 @@ static frt_uchar *sr_get_norms_i(FrtSegmentReader *sr, int field_num)
|
|
4253
4177
|
return norm->bytes;
|
4254
4178
|
}
|
4255
4179
|
|
4256
|
-
static void sr_set_norm_i(FrtIndexReader *ir, int doc_num, int field_num, frt_uchar b)
|
4257
|
-
{
|
4180
|
+
static void sr_set_norm_i(FrtIndexReader *ir, int doc_num, int field_num, frt_uchar b) {
|
4258
4181
|
Norm *norm = (Norm *)frt_h_get_int(SR(ir)->norms, field_num);
|
4259
4182
|
if (NULL != norm) { /* has_norms */
|
4260
4183
|
ir->has_changes = true;
|
@@ -4264,8 +4187,7 @@ static void sr_set_norm_i(FrtIndexReader *ir, int doc_num, int field_num, frt_uc
|
|
4264
4187
|
}
|
4265
4188
|
}
|
4266
4189
|
|
4267
|
-
static void sr_delete_doc_i(FrtIndexReader *ir, int doc_num)
|
4268
|
-
{
|
4190
|
+
static void sr_delete_doc_i(FrtIndexReader *ir, int doc_num) {
|
4269
4191
|
if (NULL == SR(ir)->deleted_docs) {
|
4270
4192
|
SR(ir)->deleted_docs = frt_bv_new();
|
4271
4193
|
}
|
@@ -4276,8 +4198,7 @@ static void sr_delete_doc_i(FrtIndexReader *ir, int doc_num)
|
|
4276
4198
|
frt_bv_set(SR(ir)->deleted_docs, doc_num);
|
4277
4199
|
}
|
4278
4200
|
|
4279
|
-
static void sr_undelete_all_i(FrtIndexReader *ir)
|
4280
|
-
{
|
4201
|
+
static void sr_undelete_all_i(FrtIndexReader *ir) {
|
4281
4202
|
SR(ir)->undelete_all = true;
|
4282
4203
|
SR(ir)->deleted_docs_dirty = false;
|
4283
4204
|
ir->has_changes = true;
|
@@ -4287,8 +4208,7 @@ static void sr_undelete_all_i(FrtIndexReader *ir)
|
|
4287
4208
|
SR(ir)->deleted_docs = NULL;
|
4288
4209
|
}
|
4289
4210
|
|
4290
|
-
static void sr_set_deleter_i(FrtIndexReader *ir, FrtDeleter *deleter)
|
4291
|
-
{
|
4211
|
+
static void sr_set_deleter_i(FrtIndexReader *ir, FrtDeleter *deleter) {
|
4292
4212
|
ir->deleter = deleter;
|
4293
4213
|
}
|
4294
4214
|
|
@@ -4372,8 +4292,7 @@ static void sr_commit_i(FrtIndexReader *ir)
|
|
4372
4292
|
}
|
4373
4293
|
}
|
4374
4294
|
|
4375
|
-
static void sr_close_i(FrtIndexReader *ir)
|
4376
|
-
{
|
4295
|
+
static void sr_close_i(FrtIndexReader *ir) {
|
4377
4296
|
FrtSegmentReader *sr = SR(ir);
|
4378
4297
|
|
4379
4298
|
if (sr->fr) frt_fr_close(sr->fr);
|
@@ -4383,9 +4302,8 @@ static void sr_close_i(FrtIndexReader *ir)
|
|
4383
4302
|
if (sr->prx_in) frt_is_close(sr->prx_in);
|
4384
4303
|
if (sr->norms) frt_h_destroy(sr->norms);
|
4385
4304
|
if (sr->deleted_docs) frt_bv_destroy(sr->deleted_docs);
|
4386
|
-
if (sr->cfs_store)
|
4305
|
+
if (sr->cfs_store) frt_store_close(sr->cfs_store);
|
4387
4306
|
if (sr->fr_bucket) {
|
4388
|
-
frt_thread_setspecific(sr->thread_fr, NULL);
|
4389
4307
|
frt_thread_key_delete(sr->thread_fr);
|
4390
4308
|
frt_ary_destroy(sr->fr_bucket, (frt_free_ft)&frt_fr_close);
|
4391
4309
|
}
|
@@ -4492,8 +4410,7 @@ static FrtTermVector *sr_term_vector(FrtIndexReader *ir, int doc_num, ID field)
|
|
4492
4410
|
FrtFieldInfo *fi = (FrtFieldInfo *)frt_h_get(ir->fis->field_dict, (void *)field);
|
4493
4411
|
FrtFieldsReader *fr;
|
4494
4412
|
|
4495
|
-
if (!fi || !fi_store_term_vector(fi) || !SR(ir)->fr ||
|
4496
|
-
!(fr = sr_fr(SR(ir)))) {
|
4413
|
+
if (!fi || !fi_store_term_vector(fi) || !SR(ir)->fr || !(fr = sr_fr(SR(ir)))) {
|
4497
4414
|
return NULL;
|
4498
4415
|
}
|
4499
4416
|
|
@@ -4536,8 +4453,9 @@ static void sr_open_norms(FrtIndexReader *ir, FrtStore *cfs_store)
|
|
4536
4453
|
FrtStore *store = (si->use_compound_file && si->norm_gens[i] == 0) ?
|
4537
4454
|
cfs_store : ir->store;
|
4538
4455
|
if (si_norm_file_name(si, file_name, i)) {
|
4539
|
-
|
4540
|
-
|
4456
|
+
FrtInStream *is = store->open_input(store, file_name);
|
4457
|
+
FRT_DEREF(is);
|
4458
|
+
frt_h_set_int(SR(ir)->norms, i, norm_create(is, i));
|
4541
4459
|
}
|
4542
4460
|
}
|
4543
4461
|
SR(ir)->norms_dirty = false;
|
@@ -4576,6 +4494,7 @@ static FrtIndexReader *sr_setup_i(FrtSegmentReader *sr)
|
|
4576
4494
|
|
4577
4495
|
ir->type = FRT_SEGMENT_READER;
|
4578
4496
|
|
4497
|
+
sr->thread_fr = 0;
|
4579
4498
|
sr->cfs_store = NULL;
|
4580
4499
|
|
4581
4500
|
FRT_TRY
|
@@ -4909,11 +4828,11 @@ FrtMultiReader *frt_mr_init(FrtMultiReader *mr, FrtIndexReader **sub_readers, co
|
|
4909
4828
|
mr->max_doc = 0;
|
4910
4829
|
mr->num_docs_cache = -1;
|
4911
4830
|
mr->has_deletions = false;
|
4912
|
-
|
4913
4831
|
mr->starts = FRT_ALLOC_N(int, (r_cnt+1));
|
4914
4832
|
|
4915
4833
|
for (i = 0; i < r_cnt; i++) {
|
4916
4834
|
FrtIndexReader *sub_reader = sub_readers[i];
|
4835
|
+
FRT_REF(sub_reader);
|
4917
4836
|
mr->starts[i] = mr->max_doc;
|
4918
4837
|
mr->max_doc += sub_reader->max_doc(sub_reader); /* compute max_docs */
|
4919
4838
|
|
@@ -5029,7 +4948,6 @@ FrtIndexReader *frt_mr_open(FrtIndexReader *ir, FrtIndexReader **sub_readers, co
|
|
5029
4948
|
|
5030
4949
|
static void ir_open_i(FrtStore *store, FindSegmentsFile *fsf, FrtIndexReader *ir) {
|
5031
4950
|
volatile bool success = false;
|
5032
|
-
// FrtIndexReader *volatile ir = NULL;
|
5033
4951
|
FrtSegmentInfos *volatile sis = NULL;
|
5034
4952
|
FRT_TRY
|
5035
4953
|
do {
|
@@ -5040,21 +4958,24 @@ static void ir_open_i(FrtStore *store, FindSegmentsFile *fsf, FrtIndexReader *ir
|
|
5040
4958
|
fis = sis->fis;
|
5041
4959
|
if (sis->size == 1) {
|
5042
4960
|
ir = sr_open(sis, fis, 0, true, (FrtSegmentReader *)ir);
|
5043
|
-
}
|
5044
|
-
else {
|
4961
|
+
} else {
|
5045
4962
|
volatile int i;
|
5046
|
-
FrtIndexReader **readers =
|
4963
|
+
FrtIndexReader **readers = FRT_ALLOC_AND_ZERO_N(FrtIndexReader *, sis->size);
|
5047
4964
|
int num_segments = sis->size;
|
5048
|
-
|
5049
|
-
|
4965
|
+
FRT_TRY
|
4966
|
+
for (i = num_segments - 1; i >= 0; i--) {
|
5050
4967
|
readers[i] = sr_open(sis, fis, i, false, NULL);
|
5051
|
-
|
5052
|
-
|
4968
|
+
FRT_DEREF(readers[i]);
|
4969
|
+
}
|
4970
|
+
FRT_XCATCHALL
|
4971
|
+
for (i++; i < num_segments; i++) {
|
4972
|
+
if (readers[i]) {
|
4973
|
+
FRT_REF(readers[i]);
|
5053
4974
|
frt_ir_close(readers[i]);
|
5054
4975
|
}
|
5055
|
-
|
5056
|
-
|
5057
|
-
|
4976
|
+
}
|
4977
|
+
free(readers);
|
4978
|
+
FRT_XENDTRY
|
5058
4979
|
ir = frt_mr_open_i(store, sis, fis, readers, sis->size, ir);
|
5059
4980
|
}
|
5060
4981
|
fsf->ret.ir = ir;
|
@@ -5294,8 +5215,7 @@ static void dw_flush(FrtDocWriter *dw)
|
|
5294
5215
|
FrtPosting *p;
|
5295
5216
|
FrtOccurence *occ;
|
5296
5217
|
FrtStore *store = dw->store;
|
5297
|
-
FrtTermInfosWriter *tiw = frt_tiw_open(store, dw->si->name,
|
5298
|
-
dw->index_interval, skip_interval);
|
5218
|
+
FrtTermInfosWriter *tiw = frt_tiw_open(store, dw->si->name, dw->index_interval, skip_interval);
|
5299
5219
|
FrtTermInfo ti;
|
5300
5220
|
char file_name[FRT_SEGMENT_NAME_MAX_LENGTH];
|
5301
5221
|
FrtOutStream *frq_out, *prx_out;
|
@@ -5374,6 +5294,7 @@ FrtDocWriter *frt_dw_open(FrtIndexWriter *iw, FrtSegmentInfo *si)
|
|
5374
5294
|
dw->analyzer = iw->analyzer;
|
5375
5295
|
dw->fis = iw->fis;
|
5376
5296
|
dw->store = store;
|
5297
|
+
FRT_REF(store);
|
5377
5298
|
dw->fw = frt_fw_open(store, si->name, iw->fis);
|
5378
5299
|
dw->si = si;
|
5379
5300
|
|
@@ -5408,6 +5329,7 @@ void frt_dw_close(FrtDocWriter *dw)
|
|
5408
5329
|
if (dw->fw) {
|
5409
5330
|
frt_fw_close(dw->fw);
|
5410
5331
|
}
|
5332
|
+
frt_store_close(dw->store);
|
5411
5333
|
frt_h_destroy(dw->curr_plists);
|
5412
5334
|
frt_h_destroy(dw->fields);
|
5413
5335
|
frt_mp_destroy(dw->mp);
|
@@ -5659,6 +5581,7 @@ static SegmentMergeInfo *smi_new(int base, FrtStore *store, FrtSegmentInfo *si)
|
|
5659
5581
|
smi->base = base;
|
5660
5582
|
smi->si = si;
|
5661
5583
|
smi->orig_store = smi->store = store;
|
5584
|
+
FRT_REF(smi->orig_store);
|
5662
5585
|
sprintf(file_name, "%s.cfs", segment);
|
5663
5586
|
if (store->exists(store, file_name)) {
|
5664
5587
|
smi->store = frt_open_cmpd_store(store, file_name);
|
@@ -5683,7 +5606,9 @@ static void smi_load_term_input(SegmentMergeInfo *smi)
|
|
5683
5606
|
char file_name[FRT_SEGMENT_NAME_MAX_LENGTH];
|
5684
5607
|
smi->sfi = frt_sfi_open(store, segment);
|
5685
5608
|
sprintf(file_name, "%s.tis", segment);
|
5686
|
-
|
5609
|
+
FrtInStream *is = store->open_input(store, file_name);
|
5610
|
+
FRT_DEREF(is);
|
5611
|
+
smi->te = TE(frt_ste_new(is, smi->sfi));
|
5687
5612
|
sprintf(file_name, "%s.frq", segment);
|
5688
5613
|
smi->frq_in = store->open_input(store, file_name);
|
5689
5614
|
sprintf(file_name, "%s.prx", segment);
|
@@ -5704,8 +5629,9 @@ static void smi_close_term_input(SegmentMergeInfo *smi)
|
|
5704
5629
|
static void smi_destroy(SegmentMergeInfo *smi)
|
5705
5630
|
{
|
5706
5631
|
if (smi->store != smi->orig_store) {
|
5707
|
-
|
5632
|
+
frt_store_close(smi->store);
|
5708
5633
|
}
|
5634
|
+
frt_store_close(smi->orig_store);
|
5709
5635
|
if (smi->deleted_docs) {
|
5710
5636
|
frt_bv_destroy(smi->deleted_docs);
|
5711
5637
|
free(smi->doc_map);
|
@@ -5741,19 +5667,18 @@ typedef struct SegmentMerger {
|
|
5741
5667
|
FrtOutStream *prx_out;
|
5742
5668
|
} SegmentMerger;
|
5743
5669
|
|
5744
|
-
static SegmentMerger *sm_create(FrtIndexWriter *iw, FrtSegmentInfo *si,
|
5745
|
-
FrtSegmentInfo **seg_infos, const int seg_cnt)
|
5670
|
+
static SegmentMerger *sm_create(FrtIndexWriter *iw, FrtSegmentInfo *si, FrtSegmentInfo **seg_infos, const int seg_cnt)
|
5746
5671
|
{
|
5747
5672
|
int i;
|
5748
5673
|
SegmentMerger *sm = FRT_ALLOC_AND_ZERO_N(SegmentMerger, seg_cnt);
|
5749
5674
|
sm->store = iw->store;
|
5675
|
+
FRT_REF(sm->store);
|
5750
5676
|
sm->fis = iw->fis;
|
5751
5677
|
sm->si = si;
|
5752
5678
|
sm->doc_cnt = 0;
|
5753
5679
|
sm->smis = FRT_ALLOC_N(SegmentMergeInfo *, seg_cnt);
|
5754
5680
|
for (i = 0; i < seg_cnt; i++) {
|
5755
|
-
sm->smis[i] = smi_new(sm->doc_cnt, seg_infos[i]->store,
|
5756
|
-
seg_infos[i]);
|
5681
|
+
sm->smis[i] = smi_new(sm->doc_cnt, seg_infos[i]->store, seg_infos[i]);
|
5757
5682
|
sm->doc_cnt += sm->smis[i]->doc_cnt;
|
5758
5683
|
}
|
5759
5684
|
sm->seg_cnt = seg_cnt;
|
@@ -5768,6 +5693,7 @@ static void sm_destroy(SegmentMerger *sm)
|
|
5768
5693
|
for (i = 0; i < seg_cnt; i++) {
|
5769
5694
|
smi_destroy(sm->smis[i]);
|
5770
5695
|
}
|
5696
|
+
frt_store_close(sm->store);
|
5771
5697
|
free(sm->smis);
|
5772
5698
|
free(sm);
|
5773
5699
|
}
|
@@ -6352,8 +6278,9 @@ void frt_iw_close(FrtIndexWriter *iw)
|
|
6352
6278
|
iw->write_lock->release(iw->write_lock);
|
6353
6279
|
frt_close_lock(iw->write_lock);
|
6354
6280
|
iw->write_lock = NULL;
|
6355
|
-
|
6281
|
+
frt_store_close(iw->store);
|
6356
6282
|
frt_deleter_destroy(iw->deleter);
|
6283
|
+
frt_mutex_unlock(&iw->mutex);
|
6357
6284
|
frt_mutex_destroy(&iw->mutex);
|
6358
6285
|
free(iw);
|
6359
6286
|
}
|
@@ -6367,6 +6294,7 @@ FrtIndexWriter *frt_iw_open(FrtIndexWriter *iw, FrtStore *store, FrtAnalyzer *vo
|
|
6367
6294
|
iw = frt_iw_alloc();
|
6368
6295
|
frt_mutex_init(&iw->mutex, NULL);
|
6369
6296
|
iw->store = store;
|
6297
|
+
FRT_REF(store);
|
6370
6298
|
if (!config) {
|
6371
6299
|
config = &frt_default_config;
|
6372
6300
|
}
|
@@ -6375,14 +6303,14 @@ FrtIndexWriter *frt_iw_open(FrtIndexWriter *iw, FrtStore *store, FrtAnalyzer *vo
|
|
6375
6303
|
FRT_TRY
|
6376
6304
|
iw->write_lock = frt_open_lock(store, FRT_WRITE_LOCK_NAME);
|
6377
6305
|
if (!iw->write_lock->obtain(iw->write_lock)) {
|
6378
|
-
FRT_RAISE(FRT_LOCK_ERROR,
|
6379
|
-
"Couldn't obtain write lock when opening IndexWriter");
|
6306
|
+
FRT_RAISE(FRT_LOCK_ERROR, "Couldn't obtain write lock when opening IndexWriter");
|
6380
6307
|
}
|
6381
6308
|
|
6382
6309
|
iw->sis = frt_sis_read(store);
|
6383
6310
|
iw->fis = iw->sis->fis;
|
6384
6311
|
FRT_REF(iw->fis);
|
6385
6312
|
FRT_XCATCHALL
|
6313
|
+
frt_store_close(iw->store);
|
6386
6314
|
if (iw->write_lock) {
|
6387
6315
|
iw->write_lock->release(iw->write_lock);
|
6388
6316
|
frt_close_lock(iw->write_lock);
|
@@ -6400,7 +6328,6 @@ FrtIndexWriter *frt_iw_open(FrtIndexWriter *iw, FrtStore *store, FrtAnalyzer *vo
|
|
6400
6328
|
iw->deleter = frt_deleter_new(iw->sis, store);
|
6401
6329
|
deleter_delete_deletable_files(iw->deleter);
|
6402
6330
|
|
6403
|
-
FRT_REF(store);
|
6404
6331
|
return iw;
|
6405
6332
|
}
|
6406
6333
|
|