diff lucene/src/luan/modules/lucene/Lucene.luan @ 625:a3c1e11fb6aa

rewrite much of Html to be more understandable; add Lucene html_highlighter();
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 12 Jan 2016 23:52:56 -0700
parents 8281a248c47e
children ca169567ce07
line wrap: on
line diff
--- a/lucene/src/luan/modules/lucene/Lucene.luan	Thu Jan 07 18:46:07 2016 -0700
+++ b/lucene/src/luan/modules/lucene/Lucene.luan	Tue Jan 12 23:52:56 2016 -0700
@@ -1,6 +1,9 @@
 java()
 local Luan = require "luan:Luan"
 local error = Luan.error
+local ipairs = Luan.ipairs or error()
+local type = Luan.type or error()
+local Html = require "luan:Html"
 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex"
 local NumberFieldParser = require "java:sane.lucene.queryparser.NumberFieldParser"
 local StringFieldParser = require "java:sane.lucene.queryparser.StringFieldParser"
@@ -69,6 +72,21 @@
 		return index.advanced_search(query)
 	end
 
+	function index.html_highlighter(query,formatter,container_tags)
+		local highlighter = index.highlighter(query,formatter)
+		return function(html)
+			local list = Html.parse(html,container_tags)
+			local result = {}
+			for _, obj in ipairs(list) do
+				if type(obj) == "string" then
+					obj = highlighter(obj)
+				end
+				result[#result+1] = obj
+			end
+			return Html.to_string(result)
+		end
+	end
+
 	return index
 end