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