diff 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
line wrap: on
line diff
--- a/src/luan/modules/lucene/Lucene.luan	Tue Feb 19 08:14:40 2019 -0700
+++ b/src/luan/modules/lucene/Lucene.luan	Wed Feb 20 12:09:51 2019 -0700
@@ -73,16 +73,30 @@
 		java_index.close()
 	end
 
-	function index.search(query, from, to, sort)
+	function index.search( query, from, to, options )
 		from or error "missing 'from' parameter"
 		to or error "missing 'to' parameter"
+		options = options or {}
+		local explain_fld = options.explain
+		local score_fld = options.score
 		local results = {}
-		local function fn(i,doc_fn)
+		local function fn(i,doc_fn,score)
 			if i >= from then
-				results[#results+1] = doc_fn()
+				local doc
+				if explain_fld == nil then
+					doc = doc_fn()
+				else
+					local explanation
+					doc, explanation = doc_fn("explain")
+					doc[explain_fld] = explanation.toString()
+				end
+				if score_fld ~= nil then
+					doc[score_fld] = score
+				end
+				results[#results+1] = doc
 			end
 		end
-		local total_hits = index.advanced_search(query,fn,to,sort)
+		local total_hits = index.advanced_search(query,fn,to,options.sort)
 		return results, total_hits
 	end