Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- a/src/luan/modules/lucene/Lucene.luan Thu Nov 12 16:59:47 2020 -0700 +++ b/src/luan/modules/lucene/Lucene.luan Sat Nov 14 20:05:07 2020 -0700 @@ -24,6 +24,25 @@ local Lucene = {} +local indexes = {} + +function Rpc.functions.lucene_backup(password,name) + Io.password == password or error "wrong password" + local index = indexes[name] or error("index not found: "..name) + local zip_file = index.dir.parent().child("backup.zip") + index.zip(zip_file) + return zip_file +end + +function Rpc.functions.lucene_restore(password,name,zip_file) + Io.password == password or error "wrong password" + local index = indexes[name] or error "index not found" + local backup_zip = index.dir.parent().child("backup.zip") + backup_zip.write(zip_file) + index.restore(backup_zip) +end + + Lucene.type = { english = LuceneIndex.ENGLISH_FIELD_PARSER string = LuceneIndex.STRING_FIELD_PARSER @@ -43,6 +62,10 @@ function Lucene.index(index_dir,options) local index = {} + if options.name ~= nil then + indexes[options.name] = index + options.name = nil + end index.dir = index_dir index_dir = get_file(index_dir) options = options or {} @@ -202,31 +225,6 @@ end end - local function multi_error(...) - error "multiple lucene instances" - end - - if Rpc.functions.lucene_backup == nil then - - function Rpc.functions.lucene_backup(password) - Io.password == password or error "wrong password" - local zip_file = index.dir.parent().child("backup.zip") - index.zip(zip_file) - return zip_file - end - - function Rpc.functions.lucene_restore(password,zip_file) - Io.password == password or error "wrong password" - local backup_zip = index.dir.parent().child("backup.zip") - backup_zip.write(zip_file) - index.restore(backup_zip) - end - - else - Rpc.functions.lucene_backup = multi_error - Rpc.functions.lucene_restore = multi_error - end - return index end