Mercurial Hosting > luan
comparison src/luan/modules/lucene/Lucene.luan @ 1417:c7f9dd062eda
lucene cleanup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 18 Oct 2019 19:38:08 -0600 |
parents | 5b8f76e26ab7 |
children | e48290f3d9fb |
comparison
equal
deleted
inserted
replaced
1416:db57d562c4bd | 1417:c7f9dd062eda |
---|---|
8 local Html = require "luan:Html.luan" | 8 local Html = require "luan:Html.luan" |
9 local Io = require "luan:Io.luan" | 9 local Io = require "luan:Io.luan" |
10 local uri = Io.uri or error() | 10 local uri = Io.uri or error() |
11 local String = require "luan:String.luan" | 11 local String = require "luan:String.luan" |
12 local matches = String.matches or error() | 12 local matches = String.matches or error() |
13 local Thread = require "luan:Thread.luan" | |
14 local schedule = Thread.schedule or error() | |
15 local run_in_lock = Thread.run_in_lock or error() | |
16 local Time = require "luan:Time.luan" | |
17 local Rpc = require "luan:Rpc.luan" | 13 local Rpc = require "luan:Rpc.luan" |
18 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" | 14 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" |
19 local NumberFieldParser = require "java:goodjava.queryparser.NumberFieldParser" | 15 local NumberFieldParser = require "java:goodjava.queryparser.NumberFieldParser" |
20 local SaneQueryParser = require "java:goodjava.queryparser.SaneQueryParser" | 16 local SaneQueryParser = require "java:goodjava.queryparser.SaneQueryParser" |
21 local Logging = require "luan:logging/Logging.luan" | 17 local Logging = require "luan:logging/Logging.luan" |
31 long = NumberFieldParser.LONG | 27 long = NumberFieldParser.LONG |
32 double = NumberFieldParser.DOUBLE | 28 double = NumberFieldParser.DOUBLE |
33 } | 29 } |
34 | 30 |
35 Lucene.literal = SaneQueryParser.literal | 31 Lucene.literal = SaneQueryParser.literal |
36 | |
37 -- function Lucene.index(index_dir,default_type,default_fields) | |
38 | 32 |
39 function Lucene.index(index_dir,options) | 33 function Lucene.index(index_dir,options) |
40 type(index_dir)=="table" or error "index_dir must be table" | 34 type(index_dir)=="table" or error "index_dir must be table" |
41 index_dir.to_uri_string and matches(index_dir.to_uri_string(),"^file:") or error "must be file" | 35 index_dir.to_uri_string and matches(index_dir.to_uri_string(),"^file:") or error "must be file" |
42 options = options or {} | 36 options = options or {} |
135 end | 129 end |
136 return Html.to_string(result) | 130 return Html.to_string(result) |
137 end | 131 end |
138 end | 132 end |
139 | 133 |
140 function index.backup_to(backup_dir) | |
141 backup_dir.delete() | |
142 backup_dir.mkdir() | |
143 index.snapshot( function(dir_path,file_names) | |
144 local lucene_dir = uri("file:"..dir_path) | |
145 for _, file_name in ipairs(file_names) do | |
146 local lucene_file = lucene_dir.child(file_name) | |
147 local backup_file = backup_dir.child(file_name) | |
148 backup_file.link_to(lucene_file) | |
149 end | |
150 end ) | |
151 end | |
152 | |
153 function index.zip(zip_file) | 134 function index.zip(zip_file) |
154 index.snapshot( function(dir_path,file_names) | 135 index.snapshot( function(dir_path,file_names) |
155 zip_file.delete() | 136 zip_file.delete() |
156 local zip_path = zip_file.canonical().to_string() | 137 local zip_path = zip_file.canonical().to_string() |
157 local dir = uri("file:"..dir_path) | 138 local dir = uri("file:"..dir_path) |