isomorfeus-ferret 0.12.6 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +101 -19
- data/README.md +85 -16
- data/ext/isomorfeus_ferret_ext/bm_bitvector.c +22 -30
- data/ext/isomorfeus_ferret_ext/bm_hash.c +6 -12
- data/ext/isomorfeus_ferret_ext/bm_micro_string.c +3 -6
- data/ext/isomorfeus_ferret_ext/bm_store.c +11 -22
- data/ext/isomorfeus_ferret_ext/brotli_common_constants.c +15 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_constants.h +200 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_context.c +156 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_context.h +113 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.c +5914 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.h +64 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_platform.c +22 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_platform.h +594 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_transform.c +291 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_transform.h +85 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_version.h +26 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.c +76 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.h +351 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +2608 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.c +339 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.h +121 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_prefix.h +732 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_state.c +159 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_state.h +365 -0
- data/ext/isomorfeus_ferret_ext/brotli_decode.h +344 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.c +145 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.h +39 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.c +843 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.h +95 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_inc.h +163 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.c +35 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.h +63 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost_inc.h +127 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_block_encoder_inc.h +34 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.c +194 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.h +51 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter_inc.h +440 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.c +1314 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.h +84 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.c +56 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.h +48 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_cluster_inc.h +320 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_command.c +28 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_command.h +190 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.c +790 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.h +61 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.c +645 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.h +54 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.c +1846 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.h +25 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +1927 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.c +33 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.h +43 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.c +503 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.h +122 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode_static.h +539 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.c +105 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.h +66 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_find_match_length.h +79 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash.h +488 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_composite_inc.h +125 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_forgetful_chain_inc.h +293 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match64_inc.h +267 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_inc.h +262 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_quickly_inc.h +266 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_rolling_inc.h +212 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_to_binary_tree_inc.h +329 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.c +100 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.h +63 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_histogram_inc.h +51 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.c +175 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.h +30 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_memory.c +170 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_memory.h +114 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.c +663 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.h +105 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_metablock_inc.h +183 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_params.h +46 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_prefix.h +53 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_quality.h +165 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_ringbuffer.h +167 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.c +486 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.h +40 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict_lut.h +5864 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.c +85 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.h +32 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_write_bits.h +87 -0
- data/ext/isomorfeus_ferret_ext/brotli_encode.h +448 -0
- data/ext/isomorfeus_ferret_ext/brotli_port.h +288 -0
- data/ext/isomorfeus_ferret_ext/brotli_types.h +83 -0
- data/ext/isomorfeus_ferret_ext/bzlib.c +1572 -0
- data/ext/isomorfeus_ferret_ext/bzlib.h +282 -0
- data/ext/isomorfeus_ferret_ext/bzlib_blocksort.c +1094 -0
- data/ext/isomorfeus_ferret_ext/bzlib_compress.c +672 -0
- data/ext/isomorfeus_ferret_ext/bzlib_crctable.c +104 -0
- data/ext/isomorfeus_ferret_ext/bzlib_decompress.c +652 -0
- data/ext/isomorfeus_ferret_ext/bzlib_huffman.c +205 -0
- data/ext/isomorfeus_ferret_ext/bzlib_private.h +509 -0
- data/ext/isomorfeus_ferret_ext/bzlib_randtable.c +84 -0
- data/ext/isomorfeus_ferret_ext/fio_tmpfile.h +53 -53
- data/ext/isomorfeus_ferret_ext/frb_analysis.c +785 -1192
- data/ext/isomorfeus_ferret_ext/frb_index.c +513 -464
- data/ext/isomorfeus_ferret_ext/frb_qparser.c +48 -60
- data/ext/isomorfeus_ferret_ext/frb_search.c +1520 -1002
- data/ext/isomorfeus_ferret_ext/frb_store.c +96 -96
- data/ext/isomorfeus_ferret_ext/frb_threading.h +0 -1
- data/ext/isomorfeus_ferret_ext/frb_utils.c +147 -196
- data/ext/isomorfeus_ferret_ext/frt_analysis.c +695 -1090
- data/ext/isomorfeus_ferret_ext/frt_analysis.h +174 -170
- data/ext/isomorfeus_ferret_ext/frt_array.c +2 -4
- data/ext/isomorfeus_ferret_ext/frt_bitvector.c +9 -16
- data/ext/isomorfeus_ferret_ext/frt_bitvector.h +32 -81
- data/ext/isomorfeus_ferret_ext/frt_document.c +15 -20
- data/ext/isomorfeus_ferret_ext/frt_document.h +10 -9
- data/ext/isomorfeus_ferret_ext/frt_except.c +5 -12
- data/ext/isomorfeus_ferret_ext/frt_field_index.c +3 -3
- data/ext/isomorfeus_ferret_ext/frt_field_index.h +6 -7
- data/ext/isomorfeus_ferret_ext/frt_filter.c +35 -46
- data/ext/isomorfeus_ferret_ext/frt_fs_store.c +2 -0
- data/ext/isomorfeus_ferret_ext/frt_global.c +91 -200
- data/ext/isomorfeus_ferret_ext/frt_global.h +7 -18
- data/ext/isomorfeus_ferret_ext/frt_hash.c +1 -2
- data/ext/isomorfeus_ferret_ext/frt_ind.c +32 -35
- data/ext/isomorfeus_ferret_ext/frt_ind.h +9 -9
- data/ext/isomorfeus_ferret_ext/frt_index.c +714 -384
- data/ext/isomorfeus_ferret_ext/frt_index.h +274 -290
- data/ext/isomorfeus_ferret_ext/frt_lang.c +0 -2
- data/ext/isomorfeus_ferret_ext/frt_mempool.c +1 -2
- data/ext/isomorfeus_ferret_ext/frt_multimapper.c +4 -7
- data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +68 -91
- data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +35 -38
- data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +53 -72
- data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +25 -32
- data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +21 -23
- data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +66 -103
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +207 -195
- data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +20 -16
- data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +17 -14
- data/ext/isomorfeus_ferret_ext/frt_q_range.c +102 -131
- data/ext/isomorfeus_ferret_ext/frt_q_span.c +179 -178
- data/ext/isomorfeus_ferret_ext/frt_q_term.c +47 -60
- data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +18 -16
- data/ext/isomorfeus_ferret_ext/frt_ram_store.c +46 -84
- data/ext/isomorfeus_ferret_ext/frt_search.c +105 -146
- data/ext/isomorfeus_ferret_ext/frt_search.h +331 -320
- data/ext/isomorfeus_ferret_ext/frt_similarity.c +5 -13
- data/ext/isomorfeus_ferret_ext/frt_similarity.h +7 -12
- data/ext/isomorfeus_ferret_ext/frt_sort.c +105 -149
- data/ext/isomorfeus_ferret_ext/frt_store.c +13 -7
- data/ext/isomorfeus_ferret_ext/frt_store.h +10 -2
- data/ext/isomorfeus_ferret_ext/frt_threading.h +0 -1
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +22 -112
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +2 -32
- data/ext/isomorfeus_ferret_ext/lz4.c +2495 -0
- data/ext/isomorfeus_ferret_ext/lz4.h +774 -0
- data/ext/isomorfeus_ferret_ext/lz4frame.c +1899 -0
- data/ext/isomorfeus_ferret_ext/lz4frame.h +623 -0
- data/ext/isomorfeus_ferret_ext/lz4hc.c +1615 -0
- data/ext/isomorfeus_ferret_ext/lz4hc.h +413 -0
- data/ext/isomorfeus_ferret_ext/lz4xxhash.c +1030 -0
- data/ext/isomorfeus_ferret_ext/lz4xxhash.h +328 -0
- data/ext/isomorfeus_ferret_ext/stem_modules.h +0 -86
- data/ext/isomorfeus_ferret_ext/test.c +0 -17
- data/ext/isomorfeus_ferret_ext/test_1710.c +11 -12
- data/ext/isomorfeus_ferret_ext/test_analysis.c +590 -583
- data/ext/isomorfeus_ferret_ext/test_compound_io.c +1 -1
- data/ext/isomorfeus_ferret_ext/test_document.c +19 -15
- data/ext/isomorfeus_ferret_ext/test_except.c +1 -2
- data/ext/isomorfeus_ferret_ext/test_fields.c +111 -100
- data/ext/isomorfeus_ferret_ext/test_file_deleter.c +10 -27
- data/ext/isomorfeus_ferret_ext/test_filter.c +11 -8
- data/ext/isomorfeus_ferret_ext/test_global.c +0 -46
- data/ext/isomorfeus_ferret_ext/test_hash.c +2 -2
- data/ext/isomorfeus_ferret_ext/test_hashset.c +1 -1
- data/ext/isomorfeus_ferret_ext/test_highlighter.c +15 -11
- data/ext/isomorfeus_ferret_ext/test_index.c +373 -363
- data/ext/isomorfeus_ferret_ext/test_q_const_score.c +5 -3
- data/ext/isomorfeus_ferret_ext/test_q_filtered.c +5 -3
- data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +13 -10
- data/ext/isomorfeus_ferret_ext/test_q_parser.c +45 -7
- data/ext/isomorfeus_ferret_ext/test_q_span.c +15 -12
- data/ext/isomorfeus_ferret_ext/test_ram_store.c +3 -3
- data/ext/isomorfeus_ferret_ext/test_search.c +60 -64
- data/ext/isomorfeus_ferret_ext/test_segments.c +5 -4
- data/ext/isomorfeus_ferret_ext/test_sort.c +17 -14
- data/ext/isomorfeus_ferret_ext/test_store.c +2 -0
- data/ext/isomorfeus_ferret_ext/test_term.c +3 -1
- data/ext/isomorfeus_ferret_ext/test_term_vectors.c +9 -10
- data/ext/isomorfeus_ferret_ext/test_test.c +1 -2
- data/ext/isomorfeus_ferret_ext/test_threading.c +9 -10
- data/ext/isomorfeus_ferret_ext/testhelper.c +1 -2
- data/lib/isomorfeus/ferret/version.rb +1 -1
- metadata +113 -58
- data/ext/isomorfeus_ferret_ext/email.rl +0 -21
- data/ext/isomorfeus_ferret_ext/frt_scanner.c +0 -900
- data/ext/isomorfeus_ferret_ext/frt_scanner.h +0 -28
- data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +0 -6706
- data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +0 -4420
- data/ext/isomorfeus_ferret_ext/scanner.h +0 -28
- data/ext/isomorfeus_ferret_ext/scanner.in +0 -43
- data/ext/isomorfeus_ferret_ext/scanner.rl +0 -84
- data/ext/isomorfeus_ferret_ext/scanner_mb.rl +0 -200
- data/ext/isomorfeus_ferret_ext/scanner_utf8.rl +0 -85
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.c +0 -1167
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.c +0 -1433
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +0 -301
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +0 -590
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +0 -1049
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +0 -705
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +0 -1239
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +0 -477
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +0 -1217
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.h +0 -7
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.c +0 -394
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.c +0 -457
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +0 -1009
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +0 -259
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +0 -704
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +0 -948
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +0 -1028
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +0 -275
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.c +0 -849
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +0 -952
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +0 -669
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_modules.txt +0 -63
- data/ext/isomorfeus_ferret_ext/uchar-ucs4.rl +0 -1854
- data/ext/isomorfeus_ferret_ext/uchar-utf8.rl +0 -1999
- data/ext/isomorfeus_ferret_ext/url.rl +0 -27
@@ -3,6 +3,9 @@
|
|
3
3
|
#include "frt_search.h"
|
4
4
|
#include "frt_helper.h"
|
5
5
|
|
6
|
+
#undef close
|
7
|
+
#undef read
|
8
|
+
|
6
9
|
#define MTQ(query) ((FrtMultiTermQuery *)(query))
|
7
10
|
|
8
11
|
/***************************************************************************
|
@@ -15,14 +18,12 @@
|
|
15
18
|
* BoostedTerm
|
16
19
|
***************************************************************************/
|
17
20
|
|
18
|
-
typedef struct BoostedTerm
|
19
|
-
|
20
|
-
char *term;
|
21
|
+
typedef struct BoostedTerm {
|
22
|
+
char *term;
|
21
23
|
float boost;
|
22
24
|
} BoostedTerm;
|
23
25
|
|
24
|
-
static bool boosted_term_less_than(const BoostedTerm *bt1, const BoostedTerm *bt2)
|
25
|
-
{
|
26
|
+
static bool boosted_term_less_than(const BoostedTerm *bt1, const BoostedTerm *bt2) {
|
26
27
|
// if (bt1->boost == bt2->boost) { return (strcmp(bt1->term, bt2->term) < 0); }
|
27
28
|
// return (bt1->boost < bt2->boost);
|
28
29
|
if (bt1->boost < bt2->boost) {
|
@@ -34,14 +35,12 @@ static bool boosted_term_less_than(const BoostedTerm *bt1, const BoostedTerm *bt
|
|
34
35
|
return (strcmp(bt1->term, bt2->term) < 0);
|
35
36
|
}
|
36
37
|
|
37
|
-
static void boosted_term_destroy(BoostedTerm *self)
|
38
|
-
{
|
38
|
+
static void boosted_term_destroy(BoostedTerm *self) {
|
39
39
|
free(self->term);
|
40
40
|
free(self);
|
41
41
|
}
|
42
42
|
|
43
|
-
static BoostedTerm *boosted_term_new(const char *term, float boost)
|
44
|
-
{
|
43
|
+
static BoostedTerm *boosted_term_new(const char *term, float boost) {
|
45
44
|
BoostedTerm *self = FRT_ALLOC(BoostedTerm);
|
46
45
|
self->term = frt_estrdup(term);
|
47
46
|
self->boost = boost;
|
@@ -54,9 +53,8 @@ static BoostedTerm *boosted_term_new(const char *term, float boost)
|
|
54
53
|
|
55
54
|
#define TDE_READ_SIZE 16
|
56
55
|
|
57
|
-
typedef struct TermDocEnumWrapper
|
58
|
-
|
59
|
-
const char *term;
|
56
|
+
typedef struct TermDocEnumWrapper {
|
57
|
+
const char *term;
|
60
58
|
FrtTermDocEnum *tde;
|
61
59
|
float boost;
|
62
60
|
int doc;
|
@@ -67,14 +65,11 @@ typedef struct TermDocEnumWrapper
|
|
67
65
|
int pointer_max;
|
68
66
|
} TermDocEnumWrapper;
|
69
67
|
|
70
|
-
static bool tdew_less_than(const TermDocEnumWrapper *tdew1,
|
71
|
-
const TermDocEnumWrapper *tdew2)
|
72
|
-
{
|
68
|
+
static bool tdew_less_than(const TermDocEnumWrapper *tdew1, const TermDocEnumWrapper *tdew2) {
|
73
69
|
return (tdew1->doc < tdew2->doc);
|
74
70
|
}
|
75
71
|
|
76
|
-
static bool tdew_next(TermDocEnumWrapper *self)
|
77
|
-
{
|
72
|
+
static bool tdew_next(TermDocEnumWrapper *self) {
|
78
73
|
self->pointer++;
|
79
74
|
if (self->pointer >= self->pointer_max) {
|
80
75
|
/* refill buffer */
|
@@ -91,8 +86,7 @@ static bool tdew_next(TermDocEnumWrapper *self)
|
|
91
86
|
return true;
|
92
87
|
}
|
93
88
|
|
94
|
-
static bool tdew_skip_to(TermDocEnumWrapper *self, int doc_num)
|
95
|
-
{
|
89
|
+
static bool tdew_skip_to(TermDocEnumWrapper *self, int doc_num) {
|
96
90
|
FrtTermDocEnum *tde = self->tde;
|
97
91
|
|
98
92
|
while (++(self->pointer) < self->pointer_max) {
|
@@ -115,15 +109,12 @@ static bool tdew_skip_to(TermDocEnumWrapper *self, int doc_num)
|
|
115
109
|
}
|
116
110
|
}
|
117
111
|
|
118
|
-
static void tdew_destroy(TermDocEnumWrapper *self)
|
119
|
-
{
|
112
|
+
static void tdew_destroy(TermDocEnumWrapper *self) {
|
120
113
|
self->tde->close(self->tde);
|
121
114
|
free(self);
|
122
115
|
}
|
123
116
|
|
124
|
-
static TermDocEnumWrapper *tdew_new(const char *term, FrtTermDocEnum *tde,
|
125
|
-
float boost)
|
126
|
-
{
|
117
|
+
static TermDocEnumWrapper *tdew_new(const char *term, FrtTermDocEnum *tde, float boost) {
|
127
118
|
TermDocEnumWrapper *self = FRT_ALLOC_AND_ZERO(TermDocEnumWrapper);
|
128
119
|
self->term = term;
|
129
120
|
self->tde = tde;
|
@@ -139,28 +130,25 @@ static TermDocEnumWrapper *tdew_new(const char *term, FrtTermDocEnum *tde,
|
|
139
130
|
#define SCORE_CACHE_SIZE 32
|
140
131
|
#define MTSc(scorer) ((MultiTermScorer *)(scorer))
|
141
132
|
|
142
|
-
typedef struct MultiTermScorer
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
float
|
152
|
-
float
|
153
|
-
float total_score;
|
133
|
+
typedef struct MultiTermScorer {
|
134
|
+
FrtScorer super;
|
135
|
+
ID field;
|
136
|
+
frt_uchar *norms;
|
137
|
+
FrtWeight *weight;
|
138
|
+
TermDocEnumWrapper **tdew_a;
|
139
|
+
int tdew_cnt;
|
140
|
+
FrtPriorityQueue *tdew_pq;
|
141
|
+
float weight_value;
|
142
|
+
float score_cache[SCORE_CACHE_SIZE];
|
143
|
+
float total_score;
|
154
144
|
} MultiTermScorer;
|
155
145
|
|
156
|
-
static float multi_tsc_score(FrtScorer *self)
|
157
|
-
{
|
146
|
+
static float multi_tsc_score(FrtScorer *self) {
|
158
147
|
return MTSc(self)->total_score * MTSc(self)->weight_value
|
159
148
|
* frt_sim_decode_norm(self->similarity, MTSc(self)->norms[self->doc]);
|
160
149
|
}
|
161
150
|
|
162
|
-
static bool multi_tsc_next(FrtScorer *self)
|
163
|
-
{
|
151
|
+
static bool multi_tsc_next(FrtScorer *self) {
|
164
152
|
int curr_doc;
|
165
153
|
float total_score = 0.0f;
|
166
154
|
TermDocEnumWrapper *tdew;
|
@@ -188,15 +176,13 @@ static bool multi_tsc_next(FrtScorer *self)
|
|
188
176
|
int freq = tdew->freq;
|
189
177
|
if (freq < SCORE_CACHE_SIZE) {
|
190
178
|
total_score += mtsc->score_cache[freq] * tdew->boost;
|
191
|
-
}
|
192
|
-
else {
|
179
|
+
} else {
|
193
180
|
total_score += frt_sim_tf(self->similarity, (float)freq) * tdew->boost;
|
194
181
|
}
|
195
182
|
|
196
183
|
if (tdew_next(tdew)) {
|
197
184
|
frt_pq_down(tdew_pq);
|
198
|
-
}
|
199
|
-
else {
|
185
|
+
} else {
|
200
186
|
frt_pq_pop(tdew_pq);
|
201
187
|
}
|
202
188
|
|
@@ -206,8 +192,7 @@ static bool multi_tsc_next(FrtScorer *self)
|
|
206
192
|
return true;
|
207
193
|
}
|
208
194
|
|
209
|
-
static bool multi_tsc_advance_to(FrtScorer *self, int target_doc_num)
|
210
|
-
{
|
195
|
+
static bool multi_tsc_advance_to(FrtScorer *self, int target_doc_num) {
|
211
196
|
FrtPriorityQueue *tdew_pq = MTSc(self)->tdew_pq;
|
212
197
|
TermDocEnumWrapper *tdew;
|
213
198
|
if (tdew_pq == NULL) {
|
@@ -230,8 +215,7 @@ static bool multi_tsc_advance_to(FrtScorer *self, int target_doc_num)
|
|
230
215
|
&& (target_doc_num > tdew->doc)) {
|
231
216
|
if (tdew_skip_to(tdew, target_doc_num)) {
|
232
217
|
frt_pq_down(tdew_pq);
|
233
|
-
}
|
234
|
-
else {
|
218
|
+
} else {
|
235
219
|
frt_pq_pop(tdew_pq);
|
236
220
|
}
|
237
221
|
}
|
@@ -239,13 +223,11 @@ static bool multi_tsc_advance_to(FrtScorer *self, int target_doc_num)
|
|
239
223
|
return (frt_pq_top(tdew_pq) == NULL) ? false : true;
|
240
224
|
}
|
241
225
|
|
242
|
-
static bool multi_tsc_skip_to(FrtScorer *self, int target_doc_num)
|
243
|
-
{
|
226
|
+
static bool multi_tsc_skip_to(FrtScorer *self, int target_doc_num) {
|
244
227
|
return multi_tsc_advance_to(self, target_doc_num) && multi_tsc_next(self);
|
245
228
|
}
|
246
229
|
|
247
|
-
static FrtExplanation *multi_tsc_explain(FrtScorer *self, int doc_num)
|
248
|
-
{
|
230
|
+
static FrtExplanation *multi_tsc_explain(FrtScorer *self, int doc_num) {
|
249
231
|
MultiTermScorer *mtsc = MTSc(self);
|
250
232
|
TermDocEnumWrapper *tdew;
|
251
233
|
|
@@ -270,8 +252,7 @@ static FrtExplanation *multi_tsc_explain(FrtScorer *self, int doc_num)
|
|
270
252
|
* again */
|
271
253
|
if (tdew_next(tdew)) {
|
272
254
|
frt_pq_down(tdew_pq);
|
273
|
-
}
|
274
|
-
else {
|
255
|
+
} else {
|
275
256
|
frt_pq_pop(tdew_pq);
|
276
257
|
}
|
277
258
|
|
@@ -279,14 +260,12 @@ static FrtExplanation *multi_tsc_explain(FrtScorer *self, int doc_num)
|
|
279
260
|
&& tdew->doc == curr_doc);
|
280
261
|
expl->value = total_score;
|
281
262
|
return expl;
|
282
|
-
}
|
283
|
-
else {
|
263
|
+
} else {
|
284
264
|
return frt_expl_new(0.0f, "None of the required terms exist in the index");
|
285
265
|
}
|
286
266
|
}
|
287
267
|
|
288
|
-
static void multi_tsc_destroy(FrtScorer *self)
|
289
|
-
{
|
268
|
+
static void multi_tsc_destroy(FrtScorer *self) {
|
290
269
|
int i;
|
291
270
|
TermDocEnumWrapper **tdew_a = MTSc(self)->tdew_a;
|
292
271
|
for (i = MTSc(self)->tdew_cnt - 1; i >= 0; i--) {
|
@@ -297,10 +276,7 @@ static void multi_tsc_destroy(FrtScorer *self)
|
|
297
276
|
frt_scorer_destroy_i(self);
|
298
277
|
}
|
299
278
|
|
300
|
-
static FrtScorer *multi_tsc_new(FrtWeight *weight,
|
301
|
-
TermDocEnumWrapper **tdew_a, int tdew_cnt,
|
302
|
-
frt_uchar *norms)
|
303
|
-
{
|
279
|
+
static FrtScorer *multi_tsc_new(FrtWeight *weight, ID field, TermDocEnumWrapper **tdew_a, int tdew_cnt, frt_uchar *norms) {
|
304
280
|
int i;
|
305
281
|
FrtScorer *self = frt_scorer_new(MultiTermScorer, weight->similarity);
|
306
282
|
|
@@ -328,13 +304,11 @@ static FrtScorer *multi_tsc_new(FrtWeight *weight, FrtSymbol field,
|
|
328
304
|
* MultiTermWeight
|
329
305
|
***************************************************************************/
|
330
306
|
|
331
|
-
static char *multi_tw_to_s(FrtWeight *self)
|
332
|
-
{
|
307
|
+
static char *multi_tw_to_s(FrtWeight *self) {
|
333
308
|
return frt_strfmt("MultiTermWeight(%f)", self->value);
|
334
309
|
}
|
335
310
|
|
336
|
-
static FrtScorer *multi_tw_scorer(FrtWeight *self, FrtIndexReader *ir)
|
337
|
-
{
|
311
|
+
static FrtScorer *multi_tw_scorer(FrtWeight *self, FrtIndexReader *ir) {
|
338
312
|
FrtScorer *multi_tsc = NULL;
|
339
313
|
FrtPriorityQueue *boosted_terms = MTQ(self->query)->boosted_terms;
|
340
314
|
const int field_num = frt_fis_get_field_num(ir->fis, MTQ(self->query)->field);
|
@@ -360,16 +334,14 @@ static FrtScorer *multi_tw_scorer(FrtWeight *self, FrtIndexReader *ir)
|
|
360
334
|
if (tdew_cnt) {
|
361
335
|
multi_tsc = multi_tsc_new(self, MTQ(self->query)->field, tdew_a,
|
362
336
|
tdew_cnt, frt_ir_get_norms_i(ir, field_num));
|
363
|
-
}
|
364
|
-
else {
|
337
|
+
} else {
|
365
338
|
free(tdew_a);
|
366
339
|
}
|
367
340
|
}
|
368
341
|
return multi_tsc;
|
369
342
|
}
|
370
343
|
|
371
|
-
static FrtExplanation *multi_tw_explain(FrtWeight *self, FrtIndexReader *ir, int doc_num)
|
372
|
-
{
|
344
|
+
static FrtExplanation *multi_tw_explain(FrtWeight *self, FrtIndexReader *ir, int doc_num) {
|
373
345
|
FrtExplanation *expl;
|
374
346
|
FrtExplanation *idf_expl1;
|
375
347
|
FrtExplanation *idf_expl2;
|
@@ -397,7 +369,7 @@ static FrtExplanation *multi_tw_explain(FrtWeight *self, FrtIndexReader *ir, int
|
|
397
369
|
field_name);
|
398
370
|
}
|
399
371
|
|
400
|
-
query_str = self->query->to_s(self->query, (
|
372
|
+
query_str = self->query->to_s(self->query, (ID)NULL);
|
401
373
|
|
402
374
|
expl = frt_expl_new(0.0f, "weight(%s in %d), product of:", query_str, doc_num);
|
403
375
|
|
@@ -442,8 +414,7 @@ static FrtExplanation *multi_tw_explain(FrtWeight *self, FrtIndexReader *ir, int
|
|
442
414
|
if ((scorer = self->scorer(self, ir)) != NULL) {
|
443
415
|
tf_expl = scorer->explain(scorer, doc_num);
|
444
416
|
scorer->destroy(scorer);
|
445
|
-
}
|
446
|
-
else {
|
417
|
+
} else {
|
447
418
|
tf_expl = frt_expl_new(0.0f, "no terms were found");
|
448
419
|
}
|
449
420
|
frt_expl_add_detail(field_expl, tf_expl);
|
@@ -464,16 +435,14 @@ static FrtExplanation *multi_tw_explain(FrtWeight *self, FrtIndexReader *ir, int
|
|
464
435
|
if (query_expl->value == 1.0f) {
|
465
436
|
frt_expl_destroy(expl);
|
466
437
|
return field_expl;
|
467
|
-
}
|
468
|
-
else {
|
438
|
+
} else {
|
469
439
|
expl->value = (query_expl->value * field_expl->value);
|
470
440
|
frt_expl_add_detail(expl, field_expl);
|
471
441
|
return expl;
|
472
442
|
}
|
473
443
|
}
|
474
444
|
|
475
|
-
static FrtWeight *multi_tw_new(FrtQuery *query, FrtSearcher *searcher)
|
476
|
-
{
|
445
|
+
static FrtWeight *multi_tw_new(FrtQuery *query, FrtSearcher *searcher) {
|
477
446
|
int i;
|
478
447
|
int doc_freq = 0;
|
479
448
|
FrtWeight *self = w_new(FrtWeight, query);
|
@@ -502,8 +471,7 @@ static FrtWeight *multi_tw_new(FrtQuery *query, FrtSearcher *searcher)
|
|
502
471
|
* MultiTermQuery
|
503
472
|
***************************************************************************/
|
504
473
|
|
505
|
-
static char *multi_tq_to_s(FrtQuery *self,
|
506
|
-
{
|
474
|
+
static char *multi_tq_to_s(FrtQuery *self, ID default_field) {
|
507
475
|
int i;
|
508
476
|
FrtPriorityQueue *boosted_terms = MTQ(self)->boosted_terms, *bt_pq_clone;
|
509
477
|
BoostedTerm *bt;
|
@@ -551,14 +519,12 @@ static char *multi_tq_to_s(FrtQuery *self, FrtSymbol default_field)
|
|
551
519
|
return buffer;
|
552
520
|
}
|
553
521
|
|
554
|
-
static void multi_tq_destroy_i(FrtQuery *self)
|
555
|
-
{
|
522
|
+
static void multi_tq_destroy_i(FrtQuery *self) {
|
556
523
|
frt_pq_destroy(MTQ(self)->boosted_terms);
|
557
524
|
frt_q_destroy_i(self);
|
558
525
|
}
|
559
526
|
|
560
|
-
static void multi_tq_extract_terms(FrtQuery *self, FrtHashSet *terms)
|
561
|
-
{
|
527
|
+
static void multi_tq_extract_terms(FrtQuery *self, FrtHashSet *terms) {
|
562
528
|
int i;
|
563
529
|
FrtPriorityQueue *boosted_terms = MTQ(self)->boosted_terms;
|
564
530
|
for (i = boosted_terms->size; i > 0; i--) {
|
@@ -567,8 +533,7 @@ static void multi_tq_extract_terms(FrtQuery *self, FrtHashSet *terms)
|
|
567
533
|
}
|
568
534
|
}
|
569
535
|
|
570
|
-
static unsigned long long multi_tq_hash(FrtQuery *self)
|
571
|
-
{
|
536
|
+
static unsigned long long multi_tq_hash(FrtQuery *self) {
|
572
537
|
int i;
|
573
538
|
unsigned long long hash = frt_str_hash(rb_id2name(MTQ(self)->field));
|
574
539
|
FrtPriorityQueue *boosted_terms = MTQ(self)->boosted_terms;
|
@@ -579,8 +544,7 @@ static unsigned long long multi_tq_hash(FrtQuery *self)
|
|
579
544
|
return hash;
|
580
545
|
}
|
581
546
|
|
582
|
-
static int multi_tq_eq(FrtQuery *self, FrtQuery *o)
|
583
|
-
{
|
547
|
+
static int multi_tq_eq(FrtQuery *self, FrtQuery *o) {
|
584
548
|
int i;
|
585
549
|
FrtPriorityQueue *boosted_terms1 = MTQ(self)->boosted_terms;
|
586
550
|
FrtPriorityQueue *boosted_terms2 = MTQ(o)->boosted_terms;
|
@@ -599,9 +563,7 @@ static int multi_tq_eq(FrtQuery *self, FrtQuery *o)
|
|
599
563
|
return true;
|
600
564
|
}
|
601
565
|
|
602
|
-
static FrtMatchVector *multi_tq_get_matchv_i(FrtQuery *self, FrtMatchVector *mv,
|
603
|
-
FrtTermVector *tv)
|
604
|
-
{
|
566
|
+
static FrtMatchVector *multi_tq_get_matchv_i(FrtQuery *self, FrtMatchVector *mv, FrtTermVector *tv) {
|
605
567
|
if (tv->field == MTQ(self)->field) {
|
606
568
|
int i;
|
607
569
|
FrtPriorityQueue *boosted_terms = MTQ(self)->boosted_terms;
|
@@ -620,17 +582,16 @@ static FrtMatchVector *multi_tq_get_matchv_i(FrtQuery *self, FrtMatchVector *mv,
|
|
620
582
|
return mv;
|
621
583
|
}
|
622
584
|
|
623
|
-
FrtQuery *
|
624
|
-
|
625
|
-
|
585
|
+
FrtQuery *frt_multi_tq_alloc(void) {
|
586
|
+
return frt_q_new(FrtMultiTermQuery);
|
587
|
+
}
|
626
588
|
|
589
|
+
FrtQuery *frt_multi_tq_init_conf(FrtQuery *self, ID field, int max_terms, float min_boost) {
|
627
590
|
if (max_terms <= 0) {
|
628
|
-
FRT_RAISE(FRT_ARG_ERROR, ":max_terms must be greater than or equal to zero. "
|
629
|
-
|
591
|
+
FRT_RAISE(FRT_ARG_ERROR, ":max_terms must be greater than or equal to zero. %d < 0. ", max_terms);
|
592
|
+
free(self);
|
630
593
|
}
|
631
594
|
|
632
|
-
self = frt_q_new(FrtMultiTermQuery);
|
633
|
-
|
634
595
|
MTQ(self)->field = field;
|
635
596
|
MTQ(self)->boosted_terms = frt_pq_new(max_terms,
|
636
597
|
(frt_lt_ft)&boosted_term_less_than,
|
@@ -649,13 +610,16 @@ FrtQuery *frt_multi_tq_new_conf(FrtSymbol field, int max_terms, float min_boost)
|
|
649
610
|
return self;
|
650
611
|
}
|
651
612
|
|
652
|
-
FrtQuery *
|
653
|
-
|
613
|
+
FrtQuery *frt_multi_tq_new_conf(ID field, int max_terms, float min_boost) {
|
614
|
+
FrtQuery *self = frt_multi_tq_alloc();
|
615
|
+
return frt_multi_tq_init_conf(self, field, max_terms, min_boost);
|
616
|
+
}
|
617
|
+
|
618
|
+
FrtQuery *frt_multi_tq_new(ID field) {
|
654
619
|
return frt_multi_tq_new_conf(field, MULTI_TERM_QUERY_MAX_TERMS, 0.0f);
|
655
620
|
}
|
656
621
|
|
657
|
-
void frt_multi_tq_add_term_boost(FrtQuery *self, const char *term, float boost)
|
658
|
-
{
|
622
|
+
void frt_multi_tq_add_term_boost(FrtQuery *self, const char *term, float boost) {
|
659
623
|
if (boost > MTQ(self)->min_boost && term && term[0]) {
|
660
624
|
BoostedTerm *bt = boosted_term_new(term, boost);
|
661
625
|
FrtPriorityQueue *bt_pq = MTQ(self)->boosted_terms;
|
@@ -666,7 +630,6 @@ void frt_multi_tq_add_term_boost(FrtQuery *self, const char *term, float boost)
|
|
666
630
|
}
|
667
631
|
}
|
668
632
|
|
669
|
-
void frt_multi_tq_add_term(FrtQuery *self, const char *term)
|
670
|
-
{
|
633
|
+
void frt_multi_tq_add_term(FrtQuery *self, const char *term) {
|
671
634
|
frt_multi_tq_add_term_boost(self, term, 1.0f);
|
672
635
|
}
|