/
backend.rb
109 lines (93 loc) · 2 KB
/
backend.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
module Index
class Backend
attr_reader :bundle_name
attr_reader :prepared, :index, :weights, :similarity, :configuration
delegate :index_name, :category_name, :to => :@config
def initialize bundle_name, config
@bundle_name = bundle_name
@config = config
@prepared = File::Text.new config.prepared_index_path
end
# Delegators.
#
# Retrieving data.
#
def retrieve &block
prepared.retrieve &block
end
# Dumping.
#
def dump_index index_hash
index.dump index_hash
end
def dump_weights weights_hash
weights.dump weights_hash
end
def dump_similarity similarity_hash
similarity.dump similarity_hash
end
def dump_configuration configuration_hash
configuration.dump configuration_hash
end
# Loading.
#
def load_index
index.load
end
def load_similarity
similarity.load
end
def load_weights
weights.load
end
def load_configuration
configuration.load
end
# Cache ok?
#
def index_cache_ok?
index.cache_ok?
end
def similarity_cache_ok?
similarity.cache_ok?
end
def weights_cache_ok?
weights.cache_ok?
end
# Cache small?
#
def index_cache_small?
index.cache_small?
end
def similarity_cache_small?
similarity.cache_small?
end
def weights_cache_small?
weights.cache_small?
end
# Copies the indexes to the "backup" directory.
#
def backup
index.backup
weights.backup
similarity.backup
configuration.backup
end
# Restores the indexes from the "backup" directory.
#
def restore
index.restore
weights.restore
similarity.restore
configuration.restore
end
# Delete all index files.
#
def delete
index.delete
weights.delete
similarity.delete
configuration.delete
end
end
end