Mercurial Hosting > luan
annotate 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 |
rev | line source |
---|---|
1353
8d95711f6615
replace java() with require "java"
Franklin Schmidt <fschmidt@gmail.com>
parents:
1348
diff
changeset
|
1 require "java" |
693
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
625
diff
changeset
|
2 local Luan = require "luan:Luan.luan" |
503 | 3 local error = Luan.error |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
4 local ipairs = Luan.ipairs or error() |
1429
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
5 local pairs = Luan.pairs or error() |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
6 local type = Luan.type or error() |
796 | 7 local set_metatable = Luan.set_metatable or error() |
1365
6617763dfd76
fix logging and lucene backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
1353
diff
changeset
|
8 local Boot = require "luan:Boot.luan" |
693
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
625
diff
changeset
|
9 local Html = require "luan:Html.luan" |
1429
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
10 local Number = require "luan:Number.luan" |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
11 local integer = Number.integer or error() |
1548 | 12 local Time = require "luan:Time.luan" |
707
1ed9e55f0be8
replace lucene.backup with lucene.zip implemented in luan, and add lucene.snapshot
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
13 local Io = require "luan:Io.luan" |
746 | 14 local uri = Io.uri or error() |
707
1ed9e55f0be8
replace lucene.backup with lucene.zip implemented in luan, and add lucene.snapshot
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
15 local String = require "luan:String.luan" |
1ed9e55f0be8
replace lucene.backup with lucene.zip implemented in luan, and add lucene.snapshot
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
16 local matches = String.matches or error() |
749
85f5444fb7d4
add rcp lucene backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
748
diff
changeset
|
17 local Rpc = require "luan:Rpc.luan" |
321
7f7708e8fdd4
remove import statement
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
320
diff
changeset
|
18 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" |
1458 | 19 local NumberFieldParser = require "java:goodjava.lucene.queryparser.NumberFieldParser" |
1459 | 20 local GoodQueryParser = require "java:goodjava.lucene.queryparser.GoodQueryParser" |
1368
5225cd6ed478
add Lucene schedule_backups_to
Franklin Schmidt <fschmidt@gmail.com>
parents:
1367
diff
changeset
|
21 local Logging = require "luan:logging/Logging.luan" |
5225cd6ed478
add Lucene schedule_backups_to
Franklin Schmidt <fschmidt@gmail.com>
parents:
1367
diff
changeset
|
22 local logger = Logging.logger "Lucene" |
544
c5a93767cc5c
lucene overhaul, untested
Franklin Schmidt <fschmidt@gmail.com>
parents:
542
diff
changeset
|
23 |
320
fed1893821bf
remove global namespace
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
312
diff
changeset
|
24 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
796
diff
changeset
|
25 local Lucene = {} |
230
4438cb2e04d0
start lucene
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
26 |
1567 | 27 local indexes = {} |
28 | |
29 function Rpc.functions.lucene_backup(password,name) | |
30 Io.password == password or error "wrong password" | |
31 local index = indexes[name] or error("index not found: "..name) | |
32 local zip_file = index.dir.parent().child("backup.zip") | |
33 index.zip(zip_file) | |
34 return zip_file | |
35 end | |
36 | |
37 function Rpc.functions.lucene_restore(password,name,zip_file) | |
38 Io.password == password or error "wrong password" | |
39 local index = indexes[name] or error "index not found" | |
40 local backup_zip = index.dir.parent().child("backup.zip") | |
41 backup_zip.write(zip_file) | |
42 index.restore(backup_zip) | |
43 end | |
44 | |
45 | |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
796
diff
changeset
|
46 Lucene.type = { |
1345
6f8988830098
unique LuceneIndex per dir
Franklin Schmidt <fschmidt@gmail.com>
parents:
1344
diff
changeset
|
47 english = LuceneIndex.ENGLISH_FIELD_PARSER |
6f8988830098
unique LuceneIndex per dir
Franklin Schmidt <fschmidt@gmail.com>
parents:
1344
diff
changeset
|
48 string = LuceneIndex.STRING_FIELD_PARSER |
1532
060ff7695317
Lucene.type.lowercase
Franklin Schmidt <fschmidt@gmail.com>
parents:
1531
diff
changeset
|
49 lowercase = LuceneIndex.LOWERCASE_FIELD_PARSER |
1345
6f8988830098
unique LuceneIndex per dir
Franklin Schmidt <fschmidt@gmail.com>
parents:
1344
diff
changeset
|
50 integer = NumberFieldParser.INT |
6f8988830098
unique LuceneIndex per dir
Franklin Schmidt <fschmidt@gmail.com>
parents:
1344
diff
changeset
|
51 long = NumberFieldParser.LONG |
6f8988830098
unique LuceneIndex per dir
Franklin Schmidt <fschmidt@gmail.com>
parents:
1344
diff
changeset
|
52 double = NumberFieldParser.DOUBLE |
544
c5a93767cc5c
lucene overhaul, untested
Franklin Schmidt <fschmidt@gmail.com>
parents:
542
diff
changeset
|
53 } |
c5a93767cc5c
lucene overhaul, untested
Franklin Schmidt <fschmidt@gmail.com>
parents:
542
diff
changeset
|
54 |
1459 | 55 Lucene.quote = GoodQueryParser.quote |
547
0be287ab0309
add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
546
diff
changeset
|
56 |
1538
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1535
diff
changeset
|
57 local function get_file(f,name) |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1535
diff
changeset
|
58 type(f)=="table" or error(name.." must be table") |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1535
diff
changeset
|
59 f.to_uri_string and matches(f.to_uri_string(),"^file:") or error(name.." must be file") |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1535
diff
changeset
|
60 return f.java.file or error() |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1535
diff
changeset
|
61 end |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1535
diff
changeset
|
62 |
1395
9dfff82dfc59
finish postgres work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1392
diff
changeset
|
63 function Lucene.index(index_dir,options) |
303
fdb4bd391c28
add lucene close();
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
64 local index = {} |
1567 | 65 if options.name ~= nil then |
66 indexes[options.name] = index | |
67 options.name = nil | |
68 end | |
591
790d5de23042
add "strict" param to Io.repr();
Franklin Schmidt <fschmidt@gmail.com>
parents:
547
diff
changeset
|
69 index.dir = index_dir |
1538
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1535
diff
changeset
|
70 index_dir = get_file(index_dir) |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1535
diff
changeset
|
71 options = options or {} |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1535
diff
changeset
|
72 options.log_dir = options.log_dir and get_file(options.log_dir) |
1548 | 73 options.log_time = options.log_time or Time.period{days=30} |
1538
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1535
diff
changeset
|
74 local java_index = LuceneIndex.getLuceneIndex(index_dir,options) |
1129
3234a14bb1f8
minor lucene changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
1088
diff
changeset
|
75 index.java = java_index |
796 | 76 |
77 index.indexed_fields = {} | |
78 local mt = {} | |
79 set_metatable(index.indexed_fields,mt) | |
80 function mt.__index(_,key) | |
81 return java_index.getIndexedFieldParser(key) | |
82 end | |
83 function mt.__new_index(_,key,value) | |
84 return java_index.setIndexedFieldParser(key,value) | |
85 end | |
618
5e495e4e560b
add lucene indexed_only_fields
Franklin Schmidt <fschmidt@gmail.com>
parents:
617
diff
changeset
|
86 |
303
fdb4bd391c28
add lucene close();
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
87 index.to_string = java_index.to_string |
707
1ed9e55f0be8
replace lucene.backup with lucene.zip implemented in luan, and add lucene.snapshot
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
88 index.snapshot = java_index.snapshot |
545
ddcd4296107a
clean up lucene search
Franklin Schmidt <fschmidt@gmail.com>
parents:
544
diff
changeset
|
89 index.advanced_search = java_index.advanced_search |
ddcd4296107a
clean up lucene search
Franklin Schmidt <fschmidt@gmail.com>
parents:
544
diff
changeset
|
90 index.search_in_transaction = java_index.search_in_transaction |
1534 | 91 index.delete_all = java_index.delete_all |
92 index.delete = java_index.delete | |
1535 | 93 index.reindex = java_index.reindex |
1533
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
94 --index.save = java_index.save |
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
95 index.is_in_transaction = java_index.is_in_transaction |
1379 | 96 index.run_in_transaction = java_index.run_in_transaction |
591
790d5de23042
add "strict" param to Io.repr();
Franklin Schmidt <fschmidt@gmail.com>
parents:
547
diff
changeset
|
97 index.ensure_open = java_index.ensure_open |
624
8281a248c47e
add lucene highlighter
Franklin Schmidt <fschmidt@gmail.com>
parents:
622
diff
changeset
|
98 index.highlighter = java_index.highlighter |
1341
a015a0b5c388
add Html.decode(), Lucene.count_tokens(), lucene boosts, Sql.database.set()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1330
diff
changeset
|
99 index.count_tokens = java_index.count_tokens |
1544
35601f15ecc3
add lucene log tag and restore_from_log
Franklin Schmidt <fschmidt@gmail.com>
parents:
1541
diff
changeset
|
100 index.tag = java_index.tag |
709 | 101 |
1556 | 102 index.relog = java_index.relog |
1544
35601f15ecc3
add lucene log tag and restore_from_log
Franklin Schmidt <fschmidt@gmail.com>
parents:
1541
diff
changeset
|
103 index.restore_from_log = java_index.restore_from_log |
1556 | 104 index.force_restore_from_log = java_index.force_restore_from_log |
1538
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1535
diff
changeset
|
105 |
1453 | 106 index.has_postgres_backup = java_index.hasPostgresBackup() |
107 index.rebuild_postgres_backup = java_index.rebuild_postgres_backup | |
1528
3bd4d7963456
use goodjava/lucene/api
Franklin Schmidt <fschmidt@gmail.com>
parents:
1527
diff
changeset
|
108 index.restore_from_postgres = java_index.restore_from_postgres |
1556 | 109 index.force_restore_from_postgres = java_index.force_restore_from_postgres |
1453 | 110 index.check = java_index.check |
1387
bc40bc9aab3a
start postgres backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
1379
diff
changeset
|
111 |
1533
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
112 function index.not_in_transaction() end |
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
113 |
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
114 function index.check_in_transaction() |
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
115 if not index.is_in_transaction() then |
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
116 index.not_in_transaction() |
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
117 end |
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
118 end |
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
119 |
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
120 function index.save(doc) |
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
121 index.check_in_transaction() |
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
122 java_index.save(doc) |
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
123 end |
28f06ac6ce39
add not_in_transaction
Franklin Schmidt <fschmidt@gmail.com>
parents:
1532
diff
changeset
|
124 |
1342
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
125 function index.search( query, from, to, options ) |
770 | 126 from or error "missing 'from' parameter" |
127 to or error "missing 'to' parameter" | |
1342
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
128 options = options or {} |
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
129 local explain_fld = options.explain |
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
130 local score_fld = options.score |
545
ddcd4296107a
clean up lucene search
Franklin Schmidt <fschmidt@gmail.com>
parents:
544
diff
changeset
|
131 local results = {} |
1342
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
132 local function fn(i,doc_fn,score) |
545
ddcd4296107a
clean up lucene search
Franklin Schmidt <fschmidt@gmail.com>
parents:
544
diff
changeset
|
133 if i >= from then |
1342
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
134 local doc |
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
135 if explain_fld == nil then |
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
136 doc = doc_fn() |
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
137 else |
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
138 local explanation |
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
139 doc, explanation = doc_fn("explain") |
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
140 doc[explain_fld] = explanation.toString() |
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
141 end |
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
142 if score_fld ~= nil then |
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
143 doc[score_fld] = score |
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
144 end |
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
145 results[#results+1] = doc |
545
ddcd4296107a
clean up lucene search
Franklin Schmidt <fschmidt@gmail.com>
parents:
544
diff
changeset
|
146 end |
ddcd4296107a
clean up lucene search
Franklin Schmidt <fschmidt@gmail.com>
parents:
544
diff
changeset
|
147 end |
1342
60599adc27b8
add lucene search options
Franklin Schmidt <fschmidt@gmail.com>
parents:
1341
diff
changeset
|
148 local total_hits = index.advanced_search(query,fn,to,options.sort) |
545
ddcd4296107a
clean up lucene search
Franklin Schmidt <fschmidt@gmail.com>
parents:
544
diff
changeset
|
149 return results, total_hits |
257
c5c60eca33dd
allow Lucene search for 0 rows
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
233
diff
changeset
|
150 end |
c5c60eca33dd
allow Lucene search for 0 rows
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
233
diff
changeset
|
151 |
c5c60eca33dd
allow Lucene search for 0 rows
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
233
diff
changeset
|
152 function index.get_document(query) |
545
ddcd4296107a
clean up lucene search
Franklin Schmidt <fschmidt@gmail.com>
parents:
544
diff
changeset
|
153 local doc |
1348 | 154 local function fn(_,doc_fn,_) |
545
ddcd4296107a
clean up lucene search
Franklin Schmidt <fschmidt@gmail.com>
parents:
544
diff
changeset
|
155 doc = doc_fn() |
257
c5c60eca33dd
allow Lucene search for 0 rows
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
233
diff
changeset
|
156 end |
545
ddcd4296107a
clean up lucene search
Franklin Schmidt <fschmidt@gmail.com>
parents:
544
diff
changeset
|
157 local total_hits = index.advanced_search(query,fn,1) |
1457 | 158 total_hits <= 1 or error("found "..total_hits.." documents for query: "..query) |
257
c5c60eca33dd
allow Lucene search for 0 rows
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
233
diff
changeset
|
159 return doc |
c5c60eca33dd
allow Lucene search for 0 rows
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
233
diff
changeset
|
160 end |
c5c60eca33dd
allow Lucene search for 0 rows
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
233
diff
changeset
|
161 |
c5c60eca33dd
allow Lucene search for 0 rows
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
233
diff
changeset
|
162 function index.count(query) |
545
ddcd4296107a
clean up lucene search
Franklin Schmidt <fschmidt@gmail.com>
parents:
544
diff
changeset
|
163 return index.advanced_search(query) |
232
9ce18106f95a
more lucene work
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
230
diff
changeset
|
164 end |
9ce18106f95a
more lucene work
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
230
diff
changeset
|
165 |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
166 function index.html_highlighter(query,formatter,container_tags) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
167 local highlighter = index.highlighter(query,formatter) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
168 return function(html) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
169 local list = Html.parse(html,container_tags) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
170 local result = {} |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
171 for _, obj in ipairs(list) do |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
172 if type(obj) == "string" then |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
173 obj = highlighter(obj) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
174 end |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
175 result[#result+1] = obj |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
176 end |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
177 return Html.to_string(result) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
178 end |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
179 end |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
624
diff
changeset
|
180 |
707
1ed9e55f0be8
replace lucene.backup with lucene.zip implemented in luan, and add lucene.snapshot
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
181 function index.zip(zip_file) |
761
99356cfde2f0
remove horrible java zip
Franklin Schmidt <fschmidt@gmail.com>
parents:
757
diff
changeset
|
182 index.snapshot( function(dir_path,file_names) |
99356cfde2f0
remove horrible java zip
Franklin Schmidt <fschmidt@gmail.com>
parents:
757
diff
changeset
|
183 zip_file.delete() |
99356cfde2f0
remove horrible java zip
Franklin Schmidt <fschmidt@gmail.com>
parents:
757
diff
changeset
|
184 local zip_path = zip_file.canonical().to_string() |
99356cfde2f0
remove horrible java zip
Franklin Schmidt <fschmidt@gmail.com>
parents:
757
diff
changeset
|
185 local dir = uri("file:"..dir_path) |
99356cfde2f0
remove horrible java zip
Franklin Schmidt <fschmidt@gmail.com>
parents:
757
diff
changeset
|
186 local dir_name = dir.name() |
99356cfde2f0
remove horrible java zip
Franklin Schmidt <fschmidt@gmail.com>
parents:
757
diff
changeset
|
187 local options = {dir=dir.parent()} |
707
1ed9e55f0be8
replace lucene.backup with lucene.zip implemented in luan, and add lucene.snapshot
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
188 for _, file_name in ipairs(file_names) do |
761
99356cfde2f0
remove horrible java zip
Franklin Schmidt <fschmidt@gmail.com>
parents:
757
diff
changeset
|
189 local cmd = "zip "..zip_path.." "..dir_name.."/"..file_name |
1431 | 190 uri("os:"..cmd,options).read_text() |
707
1ed9e55f0be8
replace lucene.backup with lucene.zip implemented in luan, and add lucene.snapshot
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
191 end |
1ed9e55f0be8
replace lucene.backup with lucene.zip implemented in luan, and add lucene.snapshot
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
192 end ) |
1ed9e55f0be8
replace lucene.backup with lucene.zip implemented in luan, and add lucene.snapshot
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
193 end |
1365
6617763dfd76
fix logging and lucene backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
1353
diff
changeset
|
194 index.zip = Boot.no_security(index.zip) |
707
1ed9e55f0be8
replace lucene.backup with lucene.zip implemented in luan, and add lucene.snapshot
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
195 |
754 | 196 function index.restore(zip_file) |
756
9092e52f94eb
better synchronization for lucene restore
Franklin Schmidt <fschmidt@gmail.com>
parents:
754
diff
changeset
|
197 java_index.run_in_lock( function() |
1369
709f7498a363
change Lucene.index() and add Lucene.recover()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1368
diff
changeset
|
198 local lucene_dir = index.dir |
756
9092e52f94eb
better synchronization for lucene restore
Franklin Schmidt <fschmidt@gmail.com>
parents:
754
diff
changeset
|
199 local before_restore = lucene_dir.parent().child("before_restore.zip") |
9092e52f94eb
better synchronization for lucene restore
Franklin Schmidt <fschmidt@gmail.com>
parents:
754
diff
changeset
|
200 index.zip(before_restore) |
1398 | 201 java_index.close() |
756
9092e52f94eb
better synchronization for lucene restore
Franklin Schmidt <fschmidt@gmail.com>
parents:
754
diff
changeset
|
202 lucene_dir.delete() |
1431 | 203 uri("os:unzip "..zip_file.canonical().to_string(),{dir=lucene_dir.parent()}).read_text() |
756
9092e52f94eb
better synchronization for lucene restore
Franklin Schmidt <fschmidt@gmail.com>
parents:
754
diff
changeset
|
204 java_index.reopen() |
9092e52f94eb
better synchronization for lucene restore
Franklin Schmidt <fschmidt@gmail.com>
parents:
754
diff
changeset
|
205 end ) |
754 | 206 end |
1365
6617763dfd76
fix logging and lucene backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
1353
diff
changeset
|
207 index.restore = Boot.no_security(index.restore) |
754 | 208 |
1429
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
209 function index.update(steps) |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
210 local version = 0 |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
211 for i in pairs(steps) do |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
212 if version < i then |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
213 version = i |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
214 end |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
215 end |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
216 local doc = index.get_document"type:version" or { type="version", version=integer(0) } |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
217 while doc.version < version do |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
218 doc.version = integer(doc.version + 1) |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
219 logger.error("step "..doc.version) |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
220 index.run_in_transaction( function() |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
221 local step = steps[doc.version] or error("missing step "..doc.version) |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
222 step() |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
223 index.save(doc) |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
224 end ) |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
225 end |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
226 end |
82415c9c0015
move versioning into Lucene
Franklin Schmidt <fschmidt@gmail.com>
parents:
1427
diff
changeset
|
227 |
230
4438cb2e04d0
start lucene
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
228 return index |
4438cb2e04d0
start lucene
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
229 end |
503 | 230 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
796
diff
changeset
|
231 return Lucene |