comparison lucene/src/luan/modules/lucene/Lucene.luan @ 749:85f5444fb7d4

add rcp lucene backup
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 15 Jul 2016 01:18:01 -0600
parents de2418d11786
children 5e3970ccd86a
comparison
equal deleted inserted replaced
748:de2418d11786 749:85f5444fb7d4
6 local Html = require "luan:Html.luan" 6 local Html = require "luan:Html.luan"
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"
12 local Hosting = require "luan:host/Hosting.luan"
11 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" 13 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex"
12 local NumberFieldParser = require "java:luan.modules.lucene.queryparser.NumberFieldParser" 14 local NumberFieldParser = require "java:luan.modules.lucene.queryparser.NumberFieldParser"
13 local StringFieldParser = require "java:luan.modules.lucene.queryparser.StringFieldParser" 15 local StringFieldParser = require "java:luan.modules.lucene.queryparser.StringFieldParser"
14 local SaneQueryParser = require "java:luan.modules.lucene.queryparser.SaneQueryParser" 16 local SaneQueryParser = require "java:luan.modules.lucene.queryparser.SaneQueryParser"
15 local Version = require "java:org.apache.lucene.util.Version" 17 local Version = require "java:org.apache.lucene.util.Version"
100 return Html.to_string(result) 102 return Html.to_string(result)
101 end 103 end
102 end 104 end
103 105
104 function index.zip(zip_file) 106 function index.zip(zip_file)
105 matches(zip_file,[[\.zip$]]) or error("file "..zip_file.." doesn't end with '.zip'")
106 index.snapshot( function(dir,file_names) 107 index.snapshot( function(dir,file_names)
107 local t = {} 108 local t = {}
108 for _, file_name in ipairs(file_names) do 109 for _, file_name in ipairs(file_names) do
109 t[#t+1] = dir.."/"..file_name 110 t[#t+1] = dir.."/"..file_name
110 end 111 end
111 local base = uri("file:"..dir).parent().to_string() 112 local base = uri("file:"..dir).parent().to_string()
112 uri(zip_file).zip(base,t) 113 zip_file.zip(base,t)
113 end ) 114 end )
115 end
116
117 if Rpc.functions.backup == nil then
118 function Rpc.functions.lucene_backup(password)
119 if Hosting.password ~= nil and Hosting.password ~= password then
120 error "wrong password"
121 end
122 local zip_file = uri("file:"..index.dir).parent().child("backup.zip")
123 index.zip(zip_file)
124 return zip_file
125 end
126 else
127 function Rpc.functions.lucene_backup()
128 error "multiple lucene instance"
129 end
114 end 130 end
115 131
116 return index 132 return index
117 end 133 end
118 134