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