comparison src/luan/modules/lucene/Lucene.luan @ 1342:60599adc27b8

add lucene search options
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 20 Feb 2019 12:09:51 -0700
parents a015a0b5c388
children 7d9a1f8894b0
comparison
equal deleted inserted replaced
1341:a015a0b5c388 1342:60599adc27b8
71 function index.close() 71 function index.close()
72 Lucene.instances[index] = nil 72 Lucene.instances[index] = nil
73 java_index.close() 73 java_index.close()
74 end 74 end
75 75
76 function index.search(query, from, to, sort) 76 function index.search( query, from, to, options )
77 from or error "missing 'from' parameter" 77 from or error "missing 'from' parameter"
78 to or error "missing 'to' parameter" 78 to or error "missing 'to' parameter"
79 options = options or {}
80 local explain_fld = options.explain
81 local score_fld = options.score
79 local results = {} 82 local results = {}
80 local function fn(i,doc_fn) 83 local function fn(i,doc_fn,score)
81 if i >= from then 84 if i >= from then
82 results[#results+1] = doc_fn() 85 local doc
86 if explain_fld == nil then
87 doc = doc_fn()
88 else
89 local explanation
90 doc, explanation = doc_fn("explain")
91 doc[explain_fld] = explanation.toString()
92 end
93 if score_fld ~= nil then
94 doc[score_fld] = score
95 end
96 results[#results+1] = doc
83 end 97 end
84 end 98 end
85 local total_hits = index.advanced_search(query,fn,to,sort) 99 local total_hits = index.advanced_search(query,fn,to,options.sort)
86 return results, total_hits 100 return results, total_hits
87 end 101 end
88 102
89 function index.get_document(query) 103 function index.get_document(query)
90 local doc 104 local doc