isomorfeus-ferret 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +612 -0
- data/README.md +44 -0
- data/ext/isomorfeus_ferret_ext/benchmark.c +223 -0
- data/ext/isomorfeus_ferret_ext/benchmark.h +45 -0
- data/ext/isomorfeus_ferret_ext/benchmarks_all.h +25 -0
- data/ext/isomorfeus_ferret_ext/bm_bitvector.c +123 -0
- data/ext/isomorfeus_ferret_ext/bm_hash.c +118 -0
- data/ext/isomorfeus_ferret_ext/bm_micro_string.c +40 -0
- data/ext/isomorfeus_ferret_ext/bm_store.c +93 -0
- data/ext/isomorfeus_ferret_ext/email.rl +21 -0
- data/ext/isomorfeus_ferret_ext/extconf.rb +5 -0
- data/ext/isomorfeus_ferret_ext/fio_tmpfile.h +53 -0
- data/ext/isomorfeus_ferret_ext/frb_analysis.c +2577 -0
- data/ext/isomorfeus_ferret_ext/frb_index.c +3457 -0
- data/ext/isomorfeus_ferret_ext/frb_lang.c +9 -0
- data/ext/isomorfeus_ferret_ext/frb_lang.h +17 -0
- data/ext/isomorfeus_ferret_ext/frb_qparser.c +629 -0
- data/ext/isomorfeus_ferret_ext/frb_search.c +4460 -0
- data/ext/isomorfeus_ferret_ext/frb_store.c +515 -0
- data/ext/isomorfeus_ferret_ext/frb_threading.h +30 -0
- data/ext/isomorfeus_ferret_ext/frb_utils.c +1127 -0
- data/ext/isomorfeus_ferret_ext/frt_analysis.c +1644 -0
- data/ext/isomorfeus_ferret_ext/frt_analysis.h +247 -0
- data/ext/isomorfeus_ferret_ext/frt_array.c +124 -0
- data/ext/isomorfeus_ferret_ext/frt_array.h +54 -0
- data/ext/isomorfeus_ferret_ext/frt_bitvector.c +95 -0
- data/ext/isomorfeus_ferret_ext/frt_bitvector.h +586 -0
- data/ext/isomorfeus_ferret_ext/frt_compound_io.c +374 -0
- data/ext/isomorfeus_ferret_ext/frt_config.h +44 -0
- data/ext/isomorfeus_ferret_ext/frt_document.c +134 -0
- data/ext/isomorfeus_ferret_ext/frt_document.h +52 -0
- data/ext/isomorfeus_ferret_ext/frt_except.c +95 -0
- data/ext/isomorfeus_ferret_ext/frt_except.h +188 -0
- data/ext/isomorfeus_ferret_ext/frt_field_index.c +233 -0
- data/ext/isomorfeus_ferret_ext/frt_field_index.h +42 -0
- data/ext/isomorfeus_ferret_ext/frt_filter.c +157 -0
- data/ext/isomorfeus_ferret_ext/frt_fs_store.c +502 -0
- data/ext/isomorfeus_ferret_ext/frt_global.c +427 -0
- data/ext/isomorfeus_ferret_ext/frt_global.h +290 -0
- data/ext/isomorfeus_ferret_ext/frt_hash.c +518 -0
- data/ext/isomorfeus_ferret_ext/frt_hash.h +466 -0
- data/ext/isomorfeus_ferret_ext/frt_hashset.c +191 -0
- data/ext/isomorfeus_ferret_ext/frt_hashset.h +206 -0
- data/ext/isomorfeus_ferret_ext/frt_helper.c +62 -0
- data/ext/isomorfeus_ferret_ext/frt_helper.h +13 -0
- data/ext/isomorfeus_ferret_ext/frt_ind.c +353 -0
- data/ext/isomorfeus_ferret_ext/frt_ind.h +54 -0
- data/ext/isomorfeus_ferret_ext/frt_index.c +6377 -0
- data/ext/isomorfeus_ferret_ext/frt_index.h +880 -0
- data/ext/isomorfeus_ferret_ext/frt_lang.c +104 -0
- data/ext/isomorfeus_ferret_ext/frt_lang.h +44 -0
- data/ext/isomorfeus_ferret_ext/frt_mempool.c +87 -0
- data/ext/isomorfeus_ferret_ext/frt_mempool.h +33 -0
- data/ext/isomorfeus_ferret_ext/frt_multimapper.c +349 -0
- data/ext/isomorfeus_ferret_ext/frt_multimapper.h +52 -0
- data/ext/isomorfeus_ferret_ext/frt_posh.c +1006 -0
- data/ext/isomorfeus_ferret_ext/frt_posh.h +973 -0
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +147 -0
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +147 -0
- data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +1612 -0
- data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +157 -0
- data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +209 -0
- data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +281 -0
- data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +147 -0
- data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +672 -0
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +3084 -0
- data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +1182 -0
- data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +98 -0
- data/ext/isomorfeus_ferret_ext/frt_q_range.c +665 -0
- data/ext/isomorfeus_ferret_ext/frt_q_span.c +2386 -0
- data/ext/isomorfeus_ferret_ext/frt_q_term.c +311 -0
- data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +166 -0
- data/ext/isomorfeus_ferret_ext/frt_ram_store.c +460 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner.c +899 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner.h +28 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +6705 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +4419 -0
- data/ext/isomorfeus_ferret_ext/frt_search.c +1824 -0
- data/ext/isomorfeus_ferret_ext/frt_search.h +924 -0
- data/ext/isomorfeus_ferret_ext/frt_similarity.c +150 -0
- data/ext/isomorfeus_ferret_ext/frt_similarity.h +79 -0
- data/ext/isomorfeus_ferret_ext/frt_sort.c +796 -0
- data/ext/isomorfeus_ferret_ext/frt_stopwords.c +395 -0
- data/ext/isomorfeus_ferret_ext/frt_store.c +680 -0
- data/ext/isomorfeus_ferret_ext/frt_store.h +789 -0
- data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +72 -0
- data/ext/isomorfeus_ferret_ext/frt_threading.h +23 -0
- data/ext/isomorfeus_ferret_ext/frt_win32.h +54 -0
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +409 -0
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +95 -0
- data/ext/isomorfeus_ferret_ext/libstemmer.c +93 -0
- data/ext/isomorfeus_ferret_ext/libstemmer.h +73 -0
- data/ext/isomorfeus_ferret_ext/q_parser.y +1366 -0
- data/ext/isomorfeus_ferret_ext/scanner.h +28 -0
- data/ext/isomorfeus_ferret_ext/scanner.in +43 -0
- data/ext/isomorfeus_ferret_ext/scanner.rl +84 -0
- data/ext/isomorfeus_ferret_ext/scanner_mb.rl +200 -0
- data/ext/isomorfeus_ferret_ext/scanner_utf8.rl +85 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +324 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +610 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +1104 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +749 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +1233 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +490 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +1217 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +1052 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +283 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +735 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +1003 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +1079 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +293 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +984 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +686 -0
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.c +325 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.c +620 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.c +1111 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.c +754 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.c +1242 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.c +495 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.c +1220 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.c +1059 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.c +285 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.c +741 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.c +1009 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.c +990 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.c +680 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.c +1083 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.c +294 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.c +2191 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_api.c +66 -0
- data/ext/isomorfeus_ferret_ext/stem_api.h +26 -0
- data/ext/isomorfeus_ferret_ext/stem_header.h +57 -0
- data/ext/isomorfeus_ferret_ext/stem_modules.h +190 -0
- data/ext/isomorfeus_ferret_ext/stem_modules.txt +50 -0
- data/ext/isomorfeus_ferret_ext/stem_utilities.c +478 -0
- data/ext/isomorfeus_ferret_ext/test.c +850 -0
- data/ext/isomorfeus_ferret_ext/test.h +416 -0
- data/ext/isomorfeus_ferret_ext/test_1710.c +63 -0
- data/ext/isomorfeus_ferret_ext/test_analysis.c +1221 -0
- data/ext/isomorfeus_ferret_ext/test_array.c +272 -0
- data/ext/isomorfeus_ferret_ext/test_bitvector.c +600 -0
- data/ext/isomorfeus_ferret_ext/test_compound_io.c +170 -0
- data/ext/isomorfeus_ferret_ext/test_document.c +156 -0
- data/ext/isomorfeus_ferret_ext/test_except.c +244 -0
- data/ext/isomorfeus_ferret_ext/test_fields.c +522 -0
- data/ext/isomorfeus_ferret_ext/test_file_deleter.c +185 -0
- data/ext/isomorfeus_ferret_ext/test_filter.c +331 -0
- data/ext/isomorfeus_ferret_ext/test_fs_store.c +25 -0
- data/ext/isomorfeus_ferret_ext/test_global.c +299 -0
- data/ext/isomorfeus_ferret_ext/test_hash.c +485 -0
- data/ext/isomorfeus_ferret_ext/test_hashset.c +288 -0
- data/ext/isomorfeus_ferret_ext/test_helper.c +47 -0
- data/ext/isomorfeus_ferret_ext/test_highlighter.c +548 -0
- data/ext/isomorfeus_ferret_ext/test_index.c +2323 -0
- data/ext/isomorfeus_ferret_ext/test_lang.c +74 -0
- data/ext/isomorfeus_ferret_ext/test_mempool.c +102 -0
- data/ext/isomorfeus_ferret_ext/test_multimapper.c +64 -0
- data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +213 -0
- data/ext/isomorfeus_ferret_ext/test_q_const_score.c +84 -0
- data/ext/isomorfeus_ferret_ext/test_q_filtered.c +61 -0
- data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +241 -0
- data/ext/isomorfeus_ferret_ext/test_q_parser.c +464 -0
- data/ext/isomorfeus_ferret_ext/test_q_span.c +575 -0
- data/ext/isomorfeus_ferret_ext/test_ram_store.c +77 -0
- data/ext/isomorfeus_ferret_ext/test_search.c +1874 -0
- data/ext/isomorfeus_ferret_ext/test_segments.c +167 -0
- data/ext/isomorfeus_ferret_ext/test_similarity.c +25 -0
- data/ext/isomorfeus_ferret_ext/test_sort.c +333 -0
- data/ext/isomorfeus_ferret_ext/test_store.c +591 -0
- data/ext/isomorfeus_ferret_ext/test_store.h +3 -0
- data/ext/isomorfeus_ferret_ext/test_term.c +351 -0
- data/ext/isomorfeus_ferret_ext/test_term_vectors.c +373 -0
- data/ext/isomorfeus_ferret_ext/test_test.c +83 -0
- data/ext/isomorfeus_ferret_ext/test_threading.c +188 -0
- data/ext/isomorfeus_ferret_ext/testhelper.c +561 -0
- data/ext/isomorfeus_ferret_ext/testhelper.h +25 -0
- data/ext/isomorfeus_ferret_ext/tests_all.h +87 -0
- data/ext/isomorfeus_ferret_ext/uchar-ucs4.rl +1854 -0
- data/ext/isomorfeus_ferret_ext/uchar-utf8.rl +1999 -0
- data/ext/isomorfeus_ferret_ext/url.rl +27 -0
- data/ext/isomorfeus_ferret_ext/word_list.h +15156 -0
- data/lib/isomorfeus/ferret/document.rb +132 -0
- data/lib/isomorfeus/ferret/field_symbol.rb +85 -0
- data/lib/isomorfeus/ferret/index/field_infos.rb +48 -0
- data/lib/isomorfeus/ferret/index/index.rb +970 -0
- data/lib/isomorfeus/ferret/monitor.rb +323 -0
- data/lib/isomorfeus/ferret/stdlib_patches.rb +151 -0
- data/lib/isomorfeus/ferret/version.rb +5 -0
- data/lib/isomorfeus-ferret.rb +8 -0
- metadata +307 -0
@@ -0,0 +1,515 @@
|
|
1
|
+
#include "frt_store.h"
|
2
|
+
#include "isomorfeus_ferret.h"
|
3
|
+
|
4
|
+
static ID id_ref_cnt;
|
5
|
+
VALUE cLock;
|
6
|
+
VALUE cLockError;
|
7
|
+
VALUE cDirectory;
|
8
|
+
VALUE cRAMDirectory;
|
9
|
+
VALUE cFSDirectory;
|
10
|
+
|
11
|
+
/****************************************************************************
|
12
|
+
*
|
13
|
+
* Lock Methods
|
14
|
+
*
|
15
|
+
****************************************************************************/
|
16
|
+
|
17
|
+
void
|
18
|
+
frb_unwrap_locks(FrtStore *store)
|
19
|
+
{
|
20
|
+
FrtHashSetEntry *hse = store->locks->first;
|
21
|
+
for (; hse; hse = hse->next) {
|
22
|
+
void *lock = hse->elem;
|
23
|
+
VALUE rlock = object_get(lock);
|
24
|
+
if (rlock != Qnil) {
|
25
|
+
object_del(lock);
|
26
|
+
Frt_Unwrap_Struct(rlock);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
void
|
32
|
+
frb_lock_free(void *p)
|
33
|
+
{
|
34
|
+
FrtLock *lock = (FrtLock *)p;
|
35
|
+
object_del(p);
|
36
|
+
frt_close_lock(lock);
|
37
|
+
}
|
38
|
+
|
39
|
+
void
|
40
|
+
frb_lock_mark(void *p)
|
41
|
+
{
|
42
|
+
FrtLock *lock = (FrtLock *)p;
|
43
|
+
frb_gc_mark(lock->store);
|
44
|
+
}
|
45
|
+
|
46
|
+
#define GET_LOCK(lock, self) Data_Get_Struct(self, FrtLock, lock)
|
47
|
+
|
48
|
+
/*
|
49
|
+
* call-seq:
|
50
|
+
* lock.obtain(timeout = 1) -> bool
|
51
|
+
*
|
52
|
+
* Obtain a lock. Returns true if lock was successfully obtained. Make sure
|
53
|
+
* the lock is released using Lock#release. Otherwise you'll be left with a
|
54
|
+
* stale lock file.
|
55
|
+
*
|
56
|
+
* The timeout defaults to 1 second and 5 attempts are made to obtain the
|
57
|
+
* lock. If you're doing large batch updates on the index with multiple
|
58
|
+
* processes you may need to increase the lock timeout but 1 second will be
|
59
|
+
* substantial in most cases.
|
60
|
+
*
|
61
|
+
* timeout:: seconds to wait to obtain lock before timing out and returning
|
62
|
+
* false
|
63
|
+
* return:: true if lock was successfully obtained. Raises a
|
64
|
+
* Lock::LockError otherwise.
|
65
|
+
*/
|
66
|
+
static VALUE
|
67
|
+
frb_lock_obtain(int argc, VALUE *argv, VALUE self)
|
68
|
+
{
|
69
|
+
VALUE rtimeout;
|
70
|
+
int timeout = 1;
|
71
|
+
FrtLock *lock;
|
72
|
+
GET_LOCK(lock, self);
|
73
|
+
|
74
|
+
if (rb_scan_args(argc, argv, "01", &rtimeout) > 0) {
|
75
|
+
timeout = FIX2INT(rtimeout);
|
76
|
+
}
|
77
|
+
/* TODO: use the lock timeout */
|
78
|
+
(void)timeout;
|
79
|
+
if (!lock->obtain(lock)) {
|
80
|
+
rb_raise(cLockError, "could not obtain lock: #%s", lock->name);
|
81
|
+
}
|
82
|
+
return Qtrue;
|
83
|
+
}
|
84
|
+
|
85
|
+
/*
|
86
|
+
* call-seq:
|
87
|
+
* lock.while_locked(timeout = 1) { do_something() } -> bool
|
88
|
+
*
|
89
|
+
* Run the code in a block while a lock is obtained, automatically releasing
|
90
|
+
* the lock when the block returns.
|
91
|
+
*
|
92
|
+
* See Lock#obtain for more information on lock timeout.
|
93
|
+
*
|
94
|
+
* timeout:: seconds to wait to obtain lock before timing out and returning
|
95
|
+
* false
|
96
|
+
* return:: true if lock was successfully obtained. Raises a
|
97
|
+
* Lock::LockError otherwise.
|
98
|
+
*/
|
99
|
+
static VALUE
|
100
|
+
frb_lock_while_locked(int argc, VALUE *argv, VALUE self)
|
101
|
+
{
|
102
|
+
VALUE rtimeout;
|
103
|
+
int timeout = 1;
|
104
|
+
FrtLock *lock;
|
105
|
+
GET_LOCK(lock, self);
|
106
|
+
if (rb_scan_args(argc, argv, "01", &rtimeout) > 0) {
|
107
|
+
timeout = FIX2INT(rtimeout);
|
108
|
+
}
|
109
|
+
(void)timeout;
|
110
|
+
if (!lock->obtain(lock)) {
|
111
|
+
rb_raise(cLockError, "could not obtain lock: #%s", lock->name);
|
112
|
+
}
|
113
|
+
rb_yield(Qnil);
|
114
|
+
lock->release(lock);
|
115
|
+
return Qtrue;
|
116
|
+
}
|
117
|
+
|
118
|
+
/*
|
119
|
+
* call-seq:
|
120
|
+
* lock.locked? -> bool
|
121
|
+
*
|
122
|
+
* Returns true if the lock has been obtained.
|
123
|
+
*/
|
124
|
+
static VALUE
|
125
|
+
frb_lock_is_locked(VALUE self)
|
126
|
+
{
|
127
|
+
FrtLock *lock;
|
128
|
+
GET_LOCK(lock, self);
|
129
|
+
return lock->is_locked(lock) ? Qtrue : Qfalse;
|
130
|
+
}
|
131
|
+
|
132
|
+
/*
|
133
|
+
* call-seq:
|
134
|
+
* lock.release() -> self
|
135
|
+
*
|
136
|
+
* Release the lock. This should only be called by the process which obtains
|
137
|
+
* the lock.
|
138
|
+
*/
|
139
|
+
static VALUE
|
140
|
+
frb_lock_release(VALUE self)
|
141
|
+
{
|
142
|
+
FrtLock *lock;
|
143
|
+
GET_LOCK(lock, self);
|
144
|
+
lock->release(lock);
|
145
|
+
return self;
|
146
|
+
}
|
147
|
+
|
148
|
+
/****************************************************************************
|
149
|
+
*
|
150
|
+
* Directory Methods
|
151
|
+
*
|
152
|
+
****************************************************************************/
|
153
|
+
|
154
|
+
void
|
155
|
+
frb_dir_free(FrtStore *store)
|
156
|
+
{
|
157
|
+
frb_unwrap_locks(store);
|
158
|
+
object_del(store);
|
159
|
+
frt_store_deref(store);
|
160
|
+
}
|
161
|
+
|
162
|
+
/*
|
163
|
+
* call-seq:
|
164
|
+
* dir.close() -> nil
|
165
|
+
*
|
166
|
+
* It is a good idea to close a directory when you have finished using it.
|
167
|
+
* Although the garbage collector will currently handle this for you, this
|
168
|
+
* behaviour may change in future.
|
169
|
+
*/
|
170
|
+
static VALUE
|
171
|
+
frb_dir_close(VALUE self)
|
172
|
+
{
|
173
|
+
FrtStore *store = DATA_PTR(self);
|
174
|
+
int ref_cnt = FIX2INT(rb_ivar_get(self, id_ref_cnt)) - 1;
|
175
|
+
rb_ivar_set(self, id_ref_cnt, INT2FIX(ref_cnt));
|
176
|
+
if (ref_cnt < 0) {
|
177
|
+
Frt_Unwrap_Struct(self);
|
178
|
+
object_del(store);
|
179
|
+
frb_unwrap_locks(store);
|
180
|
+
frt_store_deref(store);
|
181
|
+
}
|
182
|
+
return Qnil;
|
183
|
+
}
|
184
|
+
|
185
|
+
/*
|
186
|
+
* call-seq:
|
187
|
+
* dir.exists?(file_name) -> nil
|
188
|
+
*
|
189
|
+
* Return true if a file with the name +file_name+ exists in the directory.
|
190
|
+
*/
|
191
|
+
static VALUE
|
192
|
+
frb_dir_exists(VALUE self, VALUE rfname)
|
193
|
+
{
|
194
|
+
FrtStore *store = DATA_PTR(self);
|
195
|
+
StringValue(rfname);
|
196
|
+
return store->exists(store, rs2s(rfname)) ? Qtrue : Qfalse;
|
197
|
+
}
|
198
|
+
|
199
|
+
/*
|
200
|
+
* call-seq:
|
201
|
+
* dir.touch(file_name) -> nil
|
202
|
+
*
|
203
|
+
* Create an empty file in the directory with the name +file_name+.
|
204
|
+
*/
|
205
|
+
static VALUE
|
206
|
+
frb_dir_touch(VALUE self, VALUE rfname)
|
207
|
+
{
|
208
|
+
FrtStore *store = DATA_PTR(self);
|
209
|
+
StringValue(rfname);
|
210
|
+
store->touch(store, rs2s(rfname));
|
211
|
+
return Qnil;
|
212
|
+
}
|
213
|
+
|
214
|
+
/*
|
215
|
+
* call-seq:
|
216
|
+
* dir.delete(file_name) -> nil
|
217
|
+
*
|
218
|
+
* Remove file +file_name+ from the directory. Returns true if successful.
|
219
|
+
*/
|
220
|
+
static VALUE
|
221
|
+
frb_dir_delete(VALUE self, VALUE rfname)
|
222
|
+
{
|
223
|
+
FrtStore *store = DATA_PTR(self);
|
224
|
+
StringValue(rfname);
|
225
|
+
return (store->remove(store, rs2s(rfname)) == 0) ? Qtrue : Qfalse;
|
226
|
+
}
|
227
|
+
|
228
|
+
/*
|
229
|
+
* call-seq:
|
230
|
+
* dir.count -> integer
|
231
|
+
*
|
232
|
+
* Return a count of the number of files in the directory.
|
233
|
+
*/
|
234
|
+
static VALUE
|
235
|
+
frb_dir_file_count(VALUE self)
|
236
|
+
{
|
237
|
+
FrtStore *store = DATA_PTR(self);
|
238
|
+
return INT2FIX(store->count(store));
|
239
|
+
}
|
240
|
+
|
241
|
+
/*
|
242
|
+
* call-seq:
|
243
|
+
* dir.refresh -> self
|
244
|
+
*
|
245
|
+
* Delete all files in the directory. It gives you a clean slate.
|
246
|
+
*/
|
247
|
+
static VALUE
|
248
|
+
frb_dir_refresh(VALUE self)
|
249
|
+
{
|
250
|
+
FrtStore *store = DATA_PTR(self);
|
251
|
+
store->clear_all(store);
|
252
|
+
return self;
|
253
|
+
}
|
254
|
+
|
255
|
+
/*
|
256
|
+
* call-seq:
|
257
|
+
* dir.rename(from, to) -> self
|
258
|
+
*
|
259
|
+
* Rename a file from +from+ to +to+. An error will be raised if the file
|
260
|
+
* doesn't exist or there is some other type of IOError.
|
261
|
+
*/
|
262
|
+
static VALUE
|
263
|
+
frb_dir_rename(VALUE self, VALUE rfrom, VALUE rto)
|
264
|
+
{
|
265
|
+
FrtStore *store = DATA_PTR(self);
|
266
|
+
StringValue(rfrom);
|
267
|
+
StringValue(rto);
|
268
|
+
store->rename(store, rs2s(rfrom), rs2s(rto));
|
269
|
+
return self;
|
270
|
+
}
|
271
|
+
|
272
|
+
/*
|
273
|
+
* call-seq:
|
274
|
+
* dir.make_lock(lock_name) -> self
|
275
|
+
*
|
276
|
+
* Make a lock with the name +lock_name+. Note that lockfiles will be stored
|
277
|
+
* in the directory with other files but they won't be visible to you. You
|
278
|
+
* should avoid using files with a .lck extension as this extension is
|
279
|
+
* reserved for lock files
|
280
|
+
*/
|
281
|
+
static VALUE
|
282
|
+
frb_dir_make_lock(VALUE self, VALUE rlock_name)
|
283
|
+
{
|
284
|
+
VALUE rlock;
|
285
|
+
FrtLock *lock;
|
286
|
+
FrtStore *store = DATA_PTR(self);
|
287
|
+
StringValue(rlock_name);
|
288
|
+
lock = frt_open_lock(store, rs2s(rlock_name));
|
289
|
+
rlock = Data_Wrap_Struct(cLock, &frb_lock_mark, &frb_lock_free, lock);
|
290
|
+
object_add(lock, rlock);
|
291
|
+
return rlock;
|
292
|
+
}
|
293
|
+
|
294
|
+
/****************************************************************************
|
295
|
+
*
|
296
|
+
* RAMDirectory Methods
|
297
|
+
*
|
298
|
+
****************************************************************************/
|
299
|
+
|
300
|
+
/*
|
301
|
+
* call-seq:
|
302
|
+
* RAMDirectory.new(dir = nil)
|
303
|
+
*
|
304
|
+
* Create a new RAMDirectory.
|
305
|
+
*
|
306
|
+
* You can optionally load another Directory (usually a FSDirectory) into
|
307
|
+
* memory. This may be useful to speed up search performance but usually the
|
308
|
+
* speedup won't be worth the trouble. Be sure to benchmark.
|
309
|
+
*
|
310
|
+
* dir:: Directory to load into memory
|
311
|
+
*/
|
312
|
+
static VALUE
|
313
|
+
frb_ramdir_init(int argc, VALUE *argv, VALUE self)
|
314
|
+
{
|
315
|
+
VALUE rdir;
|
316
|
+
FrtStore *store;
|
317
|
+
switch (rb_scan_args(argc, argv, "01", &rdir)) {
|
318
|
+
case 1: {
|
319
|
+
FrtStore *ostore;
|
320
|
+
Data_Get_Struct(rdir, FrtStore, ostore);
|
321
|
+
store = frt_open_ram_store_and_copy(ostore, false);
|
322
|
+
break;
|
323
|
+
}
|
324
|
+
default: store = frt_open_ram_store();
|
325
|
+
}
|
326
|
+
Frt_Wrap_Struct(self, NULL, &frb_dir_free, store);
|
327
|
+
object_add(store, self);
|
328
|
+
rb_ivar_set(self, id_ref_cnt, INT2FIX(0));
|
329
|
+
return self;
|
330
|
+
}
|
331
|
+
|
332
|
+
/****************************************************************************
|
333
|
+
*
|
334
|
+
* FSDirectory Methods
|
335
|
+
*
|
336
|
+
****************************************************************************/
|
337
|
+
|
338
|
+
/*
|
339
|
+
* call-seq:
|
340
|
+
* FSDirectory.new(/path/to/index/, create = false)
|
341
|
+
*
|
342
|
+
* Create a new FSDirectory at +/path/to/index/+ which must be a valid path
|
343
|
+
* on your file system. If it doesn't exist it will be created. You can also
|
344
|
+
* specify the +create+ parameter. If +create+ is true the FSDirectory will
|
345
|
+
* be refreshed as new. That is to say, any existing files in the directory
|
346
|
+
* will be deleted. The default value for +create+ is false.
|
347
|
+
*
|
348
|
+
* path:: path to index directory. Must be a valid path on your system
|
349
|
+
* create:: set to true if you want any existing files in the directory to be
|
350
|
+
* deleted
|
351
|
+
*/
|
352
|
+
static VALUE
|
353
|
+
frb_fsdir_new(int argc, VALUE *argv, VALUE klass)
|
354
|
+
{
|
355
|
+
VALUE self, rpath, rcreate;
|
356
|
+
FrtStore *store;
|
357
|
+
bool create;
|
358
|
+
|
359
|
+
rb_scan_args(argc, argv, "11", &rpath, &rcreate);
|
360
|
+
StringValue(rpath);
|
361
|
+
create = RTEST(rcreate);
|
362
|
+
if (create) {
|
363
|
+
frb_create_dir(rpath);
|
364
|
+
}
|
365
|
+
if (!rb_funcall(rb_cFile, id_is_directory, 1, rpath)) {
|
366
|
+
rb_raise(rb_eIOError, "No directory <%s> found. Use :create => true"
|
367
|
+
" to create one.", rs2s(rpath));
|
368
|
+
}
|
369
|
+
store = frt_open_fs_store(rs2s(rpath));
|
370
|
+
if (create) store->clear_all(store);
|
371
|
+
if ((self = object_get(store)) == Qnil) {
|
372
|
+
self = Data_Wrap_Struct(klass, NULL, &frb_dir_free, store);
|
373
|
+
object_add(store, self);
|
374
|
+
rb_ivar_set(self, id_ref_cnt, INT2FIX(0));
|
375
|
+
}
|
376
|
+
else {
|
377
|
+
int ref_cnt = FIX2INT(rb_ivar_get(self, id_ref_cnt)) + 1;
|
378
|
+
rb_ivar_set(self, id_ref_cnt, INT2FIX(ref_cnt));
|
379
|
+
FRT_DEREF(store);
|
380
|
+
}
|
381
|
+
return self;
|
382
|
+
}
|
383
|
+
|
384
|
+
/****************************************************************************
|
385
|
+
*
|
386
|
+
* Init Function
|
387
|
+
*
|
388
|
+
****************************************************************************/
|
389
|
+
|
390
|
+
/*
|
391
|
+
* Document-class: Ferret::Store::Directory
|
392
|
+
*
|
393
|
+
* A Directory is an object which is used to access the index storage.
|
394
|
+
* Ruby's IO API is not used so that we can use different storage
|
395
|
+
* mechanisms to store the index. Some examples are;
|
396
|
+
*
|
397
|
+
* * File system based storage (currently implemented as FSDirectory)
|
398
|
+
* * RAM based storage (currently implemented as RAMDirectory)
|
399
|
+
* * Database based storage
|
400
|
+
*
|
401
|
+
* NOTE: Once a file has been written and closed, it can no longer be
|
402
|
+
* modified. To make any changes to the file it must be deleted and
|
403
|
+
* rewritten. For this reason, the method to open a file for writing is
|
404
|
+
* called _create_output_, while the method to open a file for reading is
|
405
|
+
* called _open_input_ If there is a risk of simultaneous modifications of
|
406
|
+
* the files then locks should be used. See Lock to find out how.
|
407
|
+
*/
|
408
|
+
void
|
409
|
+
Init_Directory(void)
|
410
|
+
{
|
411
|
+
cDirectory = rb_define_class_under(mStore, "Directory", rb_cObject);
|
412
|
+
rb_define_const(cDirectory, "LOCK_PREFIX", rb_str_new2(FRT_LOCK_PREFIX));
|
413
|
+
rb_define_method(cDirectory, "close", frb_dir_close, 0);
|
414
|
+
rb_define_method(cDirectory, "exists?", frb_dir_exists, 1);
|
415
|
+
rb_define_method(cDirectory, "touch", frb_dir_touch, 1);
|
416
|
+
rb_define_method(cDirectory, "delete", frb_dir_delete, 1);
|
417
|
+
rb_define_method(cDirectory, "file_count", frb_dir_file_count, 0);
|
418
|
+
rb_define_method(cDirectory, "refresh", frb_dir_refresh, 0);
|
419
|
+
rb_define_method(cDirectory, "rename", frb_dir_rename, 2);
|
420
|
+
rb_define_method(cDirectory, "make_lock", frb_dir_make_lock, 1);
|
421
|
+
}
|
422
|
+
|
423
|
+
/*
|
424
|
+
* Document-class: Ferret::Store::Lock
|
425
|
+
*
|
426
|
+
* A Lock is used to lock a data source so that not more than one
|
427
|
+
* output stream can access a data source at one time. It is possible
|
428
|
+
* that locks could be disabled. For example a read only index stored
|
429
|
+
* on a CDROM would have no need for a lock.
|
430
|
+
*
|
431
|
+
* You can use a lock in two ways. Firstly:
|
432
|
+
*
|
433
|
+
* write_lock = @directory.make_lock(LOCK_NAME)
|
434
|
+
* write_lock.obtain(WRITE_LOCK_TIME_OUT)
|
435
|
+
* ... # Do your file modifications # ...
|
436
|
+
* write_lock.release()
|
437
|
+
*
|
438
|
+
* Alternatively you could use the while locked method. This ensures that
|
439
|
+
* the lock will be released once processing has finished.
|
440
|
+
*
|
441
|
+
* write_lock = @directory.make_lock(LOCK_NAME)
|
442
|
+
* write_lock.while_locked(WRITE_LOCK_TIME_OUT) do
|
443
|
+
* ... # Do your file modifications # ...
|
444
|
+
* end
|
445
|
+
*/
|
446
|
+
void
|
447
|
+
Init_Lock(void)
|
448
|
+
{
|
449
|
+
cLock = rb_define_class_under(mStore, "Lock", rb_cObject);
|
450
|
+
rb_define_method(cLock, "obtain", frb_lock_obtain, -1);
|
451
|
+
rb_define_method(cLock, "while_locked", frb_lock_while_locked, -1);
|
452
|
+
rb_define_method(cLock, "release", frb_lock_release, 0);
|
453
|
+
rb_define_method(cLock, "locked?", frb_lock_is_locked, 0);
|
454
|
+
|
455
|
+
cLockError = rb_define_class_under(cLock, "LockError", rb_eStandardError);
|
456
|
+
}
|
457
|
+
|
458
|
+
/*
|
459
|
+
* Document-class: Ferret::Store::RAMDirectory
|
460
|
+
*
|
461
|
+
* Memory resident Directory implementation. You should use a RAMDirectory
|
462
|
+
* during testing but otherwise you should stick with FSDirectory. While
|
463
|
+
* loading an index into memory may slightly speed things up, on most
|
464
|
+
* operating systems there won't be much difference so it wouldn't be worth
|
465
|
+
* your trouble.
|
466
|
+
*/
|
467
|
+
void
|
468
|
+
Init_RAMDirectory(void)
|
469
|
+
{
|
470
|
+
cRAMDirectory = rb_define_class_under(mStore, "RAMDirectory", cDirectory);
|
471
|
+
rb_define_alloc_func(cRAMDirectory, frb_data_alloc);
|
472
|
+
rb_define_method(cRAMDirectory, "initialize", frb_ramdir_init, -1);
|
473
|
+
}
|
474
|
+
|
475
|
+
/*
|
476
|
+
* Document-class: Ferret::Store::RAMDirectory
|
477
|
+
*
|
478
|
+
* File-system resident Directory implementation. The FSDirectory will use a
|
479
|
+
* single directory to store all of it's files. You should not otherwise
|
480
|
+
* touch this directory. Modifying the files in the directory will corrupt
|
481
|
+
* the index. The one exception to this rule is you may need to delete stale
|
482
|
+
* lock files which have a ".lck" extension.
|
483
|
+
*/
|
484
|
+
void
|
485
|
+
Init_FSDirectory(void)
|
486
|
+
{
|
487
|
+
cFSDirectory = rb_define_class_under(mStore, "FSDirectory", cDirectory);
|
488
|
+
rb_define_alloc_func(cFSDirectory, frb_data_alloc);
|
489
|
+
rb_define_singleton_method(cFSDirectory, "new", frb_fsdir_new, -1);
|
490
|
+
}
|
491
|
+
|
492
|
+
/* rdoc hack
|
493
|
+
extern VALUE mFerret = rb_define_module("Ferret");
|
494
|
+
*/
|
495
|
+
|
496
|
+
/*
|
497
|
+
* Document-module: Ferret::Store
|
498
|
+
*
|
499
|
+
* The Store module contains all the classes required to handle the storing
|
500
|
+
* of an index.
|
501
|
+
*
|
502
|
+
* NOTE: You can currently store an index on a file-system or in memory. If
|
503
|
+
* you want to add a different type of Directory, like a database Directory
|
504
|
+
* for instance, you will to implement it in C.
|
505
|
+
*/
|
506
|
+
void
|
507
|
+
Init_Store(void)
|
508
|
+
{
|
509
|
+
id_ref_cnt = rb_intern("@id_ref_cnt");
|
510
|
+
mStore = rb_define_module_under(mFerret, "Store");
|
511
|
+
Init_Directory();
|
512
|
+
Init_Lock();
|
513
|
+
Init_RAMDirectory();
|
514
|
+
Init_FSDirectory();
|
515
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#ifndef FRT_THREADING_H
|
2
|
+
#define FRT_THREADING_H
|
3
|
+
|
4
|
+
#include "frt_hash.h"
|
5
|
+
#define UNTHREADED 1
|
6
|
+
|
7
|
+
typedef void * frt_mutex_t;
|
8
|
+
typedef struct FrtHash *frt_thread_key_t;
|
9
|
+
typedef int frt_thread_once_t;
|
10
|
+
#define FRT_MUTEX_INITIALIZER NULL
|
11
|
+
#define FRT_THREAD_ONCE_INIT 1;
|
12
|
+
#define frt_mutex_init(a, b)
|
13
|
+
#define frt_mutex_lock(a)
|
14
|
+
#define frt_mutex_trylock(a)
|
15
|
+
#define frt_mutex_unlock(a)
|
16
|
+
#define frt_mutex_destroy(a)
|
17
|
+
#define frt_thread_key_create(a, b) frb_thread_key_create(a, b)
|
18
|
+
#define frt_thread_key_delete(a) frb_thread_key_delete(a)
|
19
|
+
#define frt_thread_setspecific(a, b) frb_thread_setspecific(a, b)
|
20
|
+
#define frt_thread_getspecific(a) frb_thread_getspecific(a)
|
21
|
+
#define frt_thread_exit(a)
|
22
|
+
#define frt_thread_once(a, b) frb_thread_once(a, b)
|
23
|
+
|
24
|
+
void frb_thread_once(int *once_control, void (*init_routine)(void));
|
25
|
+
void frb_thread_key_create(frt_thread_key_t *key, frt_free_ft destroy);
|
26
|
+
void frb_thread_key_delete(frt_thread_key_t key);
|
27
|
+
void frb_thread_setspecific(frt_thread_key_t key, const void *pointer);
|
28
|
+
void *frb_thread_getspecific(frt_thread_key_t key);
|
29
|
+
|
30
|
+
#endif
|