Mercurial Hosting > luan
comparison src/luan/modules/lucene/Lucene.luan @ 1345:6f8988830098
unique LuceneIndex per dir
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 25 Feb 2019 11:00:10 -0700 |
parents | dc2af9d5463b |
children | af478a1bd23d |
comparison
equal
deleted
inserted
replaced
1344:dc2af9d5463b | 1345:6f8988830098 |
---|---|
10 local String = require "luan:String.luan" | 10 local String = require "luan:String.luan" |
11 local matches = String.matches or error() | 11 local matches = String.matches or error() |
12 local Rpc = require "luan:Rpc.luan" | 12 local Rpc = require "luan:Rpc.luan" |
13 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" | 13 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" |
14 local NumberFieldParser = require "java:luan.lib.queryparser.NumberFieldParser" | 14 local NumberFieldParser = require "java:luan.lib.queryparser.NumberFieldParser" |
15 local StringFieldParser = require "java:luan.lib.queryparser.StringFieldParser" | |
16 local SaneQueryParser = require "java:luan.lib.queryparser.SaneQueryParser" | 15 local SaneQueryParser = require "java:luan.lib.queryparser.SaneQueryParser" |
17 local Version = require "java:org.apache.lucene.util.Version" | |
18 local EnglishAnalyzer = require "java:org.apache.lucene.analysis.en.EnglishAnalyzer" | |
19 | 16 |
20 | 17 |
21 local Lucene = {} | 18 local Lucene = {} |
22 | 19 |
23 Lucene.instances = {} | 20 Lucene.instances = {} |
24 | 21 |
25 Lucene.type = { | 22 Lucene.type = { |
26 string = LuceneIndex.STRING_FIELD_PARSER; | 23 english = LuceneIndex.ENGLISH_FIELD_PARSER |
27 integer = NumberFieldParser.INT; | 24 string = LuceneIndex.STRING_FIELD_PARSER |
28 long = NumberFieldParser.LONG; | 25 integer = NumberFieldParser.INT |
29 double = NumberFieldParser.DOUBLE; | 26 long = NumberFieldParser.LONG |
30 | 27 double = NumberFieldParser.DOUBLE |
31 english = StringFieldParser.new(EnglishAnalyzer.new(Version.LUCENE_CURRENT)) | |
32 } | 28 } |
33 | 29 |
34 Lucene.literal = SaneQueryParser.literal | 30 Lucene.literal = SaneQueryParser.literal |
35 | 31 |
36 function Lucene.index(index_dir,default_type,default_fields) | 32 function Lucene.index(index_dir,default_type,default_fields) |
37 local index = {} | 33 local index = {} |
38 index.dir = index_dir | 34 index.dir = index_dir |
39 local java_index = LuceneIndex.new(index_dir,default_type,default_fields) | 35 local java_index, closer = LuceneIndex.getLuceneIndex(index_dir,default_type,default_fields) |
40 index.java = java_index | 36 index.java = java_index |
41 -- index.indexed_fields = java_index.indexedFieldsMeta.newTable() | 37 index.closer = closer or error() |
42 | 38 |
43 index.indexed_fields = {} | 39 index.indexed_fields = {} |
44 local mt = {} | 40 local mt = {} |
45 set_metatable(index.indexed_fields,mt) | 41 set_metatable(index.indexed_fields,mt) |
46 function mt.__index(_,key) | 42 function mt.__index(_,key) |
68 | 64 |
69 Lucene.instances[index] = true | 65 Lucene.instances[index] = true |
70 | 66 |
71 function index.close() | 67 function index.close() |
72 Lucene.instances[index] = nil | 68 Lucene.instances[index] = nil |
73 java_index.close() | 69 closer.close() |
74 end | 70 end |
75 | 71 |
76 function index.search( query, from, to, options ) | 72 function index.search( query, from, to, options ) |
77 from or error "missing 'from' parameter" | 73 from or error "missing 'from' parameter" |
78 to or error "missing 'to' parameter" | 74 to or error "missing 'to' parameter" |
146 function index.restore(zip_file) | 142 function index.restore(zip_file) |
147 java_index.run_in_lock( function() | 143 java_index.run_in_lock( function() |
148 local lucene_dir = uri("file:"..index.dir) | 144 local lucene_dir = uri("file:"..index.dir) |
149 local before_restore = lucene_dir.parent().child("before_restore.zip") | 145 local before_restore = lucene_dir.parent().child("before_restore.zip") |
150 index.zip(before_restore) | 146 index.zip(before_restore) |
151 java_index.close() | 147 java_index.doClose() |
152 lucene_dir.delete() | 148 lucene_dir.delete() |
153 Io.uri("os:unzip "..zip_file.canonical().to_string(),{dir=lucene_dir.parent()}).read_text() | 149 Io.uri("os:unzip "..zip_file.canonical().to_string(),{dir=lucene_dir.parent()}).read_text() |
154 java_index.reopen() | 150 java_index.reopen() |
155 end ) | 151 end ) |
156 end | 152 end |