Mercurial Hosting > luan
diff src/luan/modules/lucene/Lucene.luan @ 1369:709f7498a363
change Lucene.index() and add Lucene.recover()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 19 Jun 2019 00:26:10 -0600 |
parents | 5225cd6ed478 |
children | 5c3702f60200 |
line wrap: on
line diff
--- a/src/luan/modules/lucene/Lucene.luan Tue Jun 18 21:56:53 2019 -0600 +++ b/src/luan/modules/lucene/Lucene.luan Wed Jun 19 00:26:10 2019 -0600 @@ -37,9 +37,11 @@ Lucene.literal = SaneQueryParser.literal function Lucene.index(index_dir,default_type,default_fields) + type(index_dir)=="table" or error "index_dir must be table" + index_dir.to_uri_string and matches(index_dir.to_uri_string(),"^file:") or error "must be file" local index = {} index.dir = index_dir - local java_index, closer = LuceneIndex.getLuceneIndex(index_dir,default_type,default_fields) + local java_index, closer = LuceneIndex.getLuceneIndex(index_dir.java.file,default_type,default_fields) index.java = java_index index.closer = closer or error() @@ -145,7 +147,7 @@ end function index.schedule_backups_to(backup_dir,repeating_delay) - local lucene_dir = uri("file:"..index.dir) + local lucene_dir = index.dir local function backup() if backup_dir.last_modified() < lucene_dir.last_modified() then run_for_backup(function() @@ -178,7 +180,7 @@ function index.restore(zip_file) java_index.run_in_lock( function() - local lucene_dir = uri("file:"..index.dir) + local lucene_dir = index.dir local before_restore = lucene_dir.parent().child("before_restore.zip") index.zip(before_restore) java_index.doClose() @@ -197,14 +199,14 @@ function Rpc.functions.lucene_backup(password) Io.password == password or error "wrong password" - local zip_file = uri("file:"..index.dir).parent().child("backup.zip") + 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 = uri("file:"..index.dir).parent().child("backup.zip") + local backup_zip = index.dir.parent().child("backup.zip") backup_zip.write(zip_file) index.restore(backup_zip) end @@ -217,4 +219,14 @@ return index end +function Lucene.recover(index_dir,restore_dir) + if not index_dir.exists() and restore_dir.exists() then + index_dir.mkdir() + for _, child in ipairs(restore_dir.children()) do + index_dir.child(child.name()).link_to(child) + end + logger.error "recovered" + end +end + return Lucene