Mercurial Hosting > luan
comparison src/luan/modules/lucene/Lucene.luan @ 1567:349eef23a13c
lucene named backup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 14 Nov 2020 20:05:07 -0700 |
parents | 44e444a8da64 |
children | c922446f53aa |
comparison
equal
deleted
inserted
replaced
1566:364859d29ff5 | 1567:349eef23a13c |
---|---|
22 local logger = Logging.logger "Lucene" | 22 local logger = Logging.logger "Lucene" |
23 | 23 |
24 | 24 |
25 local Lucene = {} | 25 local Lucene = {} |
26 | 26 |
27 local indexes = {} | |
28 | |
29 function Rpc.functions.lucene_backup(password,name) | |
30 Io.password == password or error "wrong password" | |
31 local index = indexes[name] or error("index not found: "..name) | |
32 local zip_file = index.dir.parent().child("backup.zip") | |
33 index.zip(zip_file) | |
34 return zip_file | |
35 end | |
36 | |
37 function Rpc.functions.lucene_restore(password,name,zip_file) | |
38 Io.password == password or error "wrong password" | |
39 local index = indexes[name] or error "index not found" | |
40 local backup_zip = index.dir.parent().child("backup.zip") | |
41 backup_zip.write(zip_file) | |
42 index.restore(backup_zip) | |
43 end | |
44 | |
45 | |
27 Lucene.type = { | 46 Lucene.type = { |
28 english = LuceneIndex.ENGLISH_FIELD_PARSER | 47 english = LuceneIndex.ENGLISH_FIELD_PARSER |
29 string = LuceneIndex.STRING_FIELD_PARSER | 48 string = LuceneIndex.STRING_FIELD_PARSER |
30 lowercase = LuceneIndex.LOWERCASE_FIELD_PARSER | 49 lowercase = LuceneIndex.LOWERCASE_FIELD_PARSER |
31 integer = NumberFieldParser.INT | 50 integer = NumberFieldParser.INT |
41 return f.java.file or error() | 60 return f.java.file or error() |
42 end | 61 end |
43 | 62 |
44 function Lucene.index(index_dir,options) | 63 function Lucene.index(index_dir,options) |
45 local index = {} | 64 local index = {} |
65 if options.name ~= nil then | |
66 indexes[options.name] = index | |
67 options.name = nil | |
68 end | |
46 index.dir = index_dir | 69 index.dir = index_dir |
47 index_dir = get_file(index_dir) | 70 index_dir = get_file(index_dir) |
48 options = options or {} | 71 options = options or {} |
49 options.log_dir = options.log_dir and get_file(options.log_dir) | 72 options.log_dir = options.log_dir and get_file(options.log_dir) |
50 options.log_time = options.log_time or Time.period{days=30} | 73 options.log_time = options.log_time or Time.period{days=30} |
200 index.save(doc) | 223 index.save(doc) |
201 end ) | 224 end ) |
202 end | 225 end |
203 end | 226 end |
204 | 227 |
205 local function multi_error(...) | |
206 error "multiple lucene instances" | |
207 end | |
208 | |
209 if Rpc.functions.lucene_backup == nil then | |
210 | |
211 function Rpc.functions.lucene_backup(password) | |
212 Io.password == password or error "wrong password" | |
213 local zip_file = index.dir.parent().child("backup.zip") | |
214 index.zip(zip_file) | |
215 return zip_file | |
216 end | |
217 | |
218 function Rpc.functions.lucene_restore(password,zip_file) | |
219 Io.password == password or error "wrong password" | |
220 local backup_zip = index.dir.parent().child("backup.zip") | |
221 backup_zip.write(zip_file) | |
222 index.restore(backup_zip) | |
223 end | |
224 | |
225 else | |
226 Rpc.functions.lucene_backup = multi_error | |
227 Rpc.functions.lucene_restore = multi_error | |
228 end | |
229 | |
230 return index | 228 return index |
231 end | 229 end |
232 | 230 |
233 return Lucene | 231 return Lucene |