comparison lucene/src/luan/modules/lucene/Lucene.luan @ 754:1a101ac9ea46

add lucene restore
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 17 Jul 2016 19:21:52 -0600
parents 5e3970ccd86a
children 9092e52f94eb
comparison
equal deleted inserted replaced
753:5e3970ccd86a 754:1a101ac9ea46
7 local Io = require "luan:Io.luan" 7 local Io = require "luan:Io.luan"
8 local uri = Io.uri or error() 8 local uri = Io.uri or error()
9 local String = require "luan:String.luan" 9 local String = require "luan:String.luan"
10 local matches = String.matches or error() 10 local matches = String.matches or error()
11 local Rpc = require "luan:Rpc.luan" 11 local Rpc = require "luan:Rpc.luan"
12 local Thread = require "luan:Thread.luan"
13 local synchronized = Thread.synchronized or error()
12 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" 14 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex"
13 local NumberFieldParser = require "java:luan.modules.lucene.queryparser.NumberFieldParser" 15 local NumberFieldParser = require "java:luan.modules.lucene.queryparser.NumberFieldParser"
14 local StringFieldParser = require "java:luan.modules.lucene.queryparser.StringFieldParser" 16 local StringFieldParser = require "java:luan.modules.lucene.queryparser.StringFieldParser"
15 local SaneQueryParser = require "java:luan.modules.lucene.queryparser.SaneQueryParser" 17 local SaneQueryParser = require "java:luan.modules.lucene.queryparser.SaneQueryParser"
16 local Version = require "java:org.apache.lucene.util.Version" 18 local Version = require "java:org.apache.lucene.util.Version"
111 local base = uri("file:"..dir).parent().to_string() 113 local base = uri("file:"..dir).parent().to_string()
112 zip_file.zip(base,t) 114 zip_file.zip(base,t)
113 end ) 115 end )
114 end 116 end
115 117
118 function index.restore(zip_file)
119 local lucene_dir = uri("file:"..index.dir)
120 local before_restore = lucene_dir.parent().child("before_restore.zip")
121 index.zip(before_restore)
122 java_index.close()
123 lucene_dir.delete()
124 zip_file.unzip(lucene_dir.parent().to_string())
125 java_index.reopen()
126 end
127 index.restore = synchronized(index.restore)
128
129 local function multi_error()
130 error "multiple lucene instances"
131 end
132
116 if Rpc.functions.backup == nil then 133 if Rpc.functions.backup == nil then
134
117 function Rpc.functions.lucene_backup(password) 135 function Rpc.functions.lucene_backup(password)
118 if Io.password ~= password then 136 if Io.password ~= password then
119 error "wrong password" 137 error "wrong password"
120 end 138 end
121 local zip_file = uri("file:"..index.dir).parent().child("backup.zip") 139 local zip_file = uri("file:"..index.dir).parent().child("backup.zip")
122 index.zip(zip_file) 140 index.zip(zip_file)
123 return zip_file 141 return zip_file
124 end 142 end
143
144 function Rpc.functions.lucene_restore(password,zip_file)
145 if Io.password ~= password then
146 error "wrong password"
147 end
148 index.restore(zip_file)
149 end
150
125 else 151 else
126 function Rpc.functions.lucene_backup() 152 Rpc.functions.lucene_backup = multi_error
127 error "multiple lucene instance" 153 Rpc.functions.lucene_restore = multi_error
128 end
129 end 154 end
130 155
131 return index 156 return index
132 end 157 end
133 158