comparison 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
comparison
equal deleted inserted replaced
624:8281a248c47e 625:a3c1e11fb6aa
1 java() 1 java()
2 local Luan = require "luan:Luan" 2 local Luan = require "luan:Luan"
3 local error = Luan.error 3 local error = Luan.error
4 local ipairs = Luan.ipairs or error()
5 local type = Luan.type or error()
6 local Html = require "luan:Html"
4 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" 7 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex"
5 local NumberFieldParser = require "java:sane.lucene.queryparser.NumberFieldParser" 8 local NumberFieldParser = require "java:sane.lucene.queryparser.NumberFieldParser"
6 local StringFieldParser = require "java:sane.lucene.queryparser.StringFieldParser" 9 local StringFieldParser = require "java:sane.lucene.queryparser.StringFieldParser"
7 local SaneQueryParser = require "java:sane.lucene.queryparser.SaneQueryParser" 10 local SaneQueryParser = require "java:sane.lucene.queryparser.SaneQueryParser"
8 local Version = require "java:org.apache.lucene.util.Version" 11 local Version = require "java:org.apache.lucene.util.Version"
67 70
68 function index.count(query) 71 function index.count(query)
69 return index.advanced_search(query) 72 return index.advanced_search(query)
70 end 73 end
71 74
75 function index.html_highlighter(query,formatter,container_tags)
76 local highlighter = index.highlighter(query,formatter)
77 return function(html)
78 local list = Html.parse(html,container_tags)
79 local result = {}
80 for _, obj in ipairs(list) do
81 if type(obj) == "string" then
82 obj = highlighter(obj)
83 end
84 result[#result+1] = obj
85 end
86 return Html.to_string(result)
87 end
88 end
89
72 return index 90 return index
73 end 91 end
74 92
75 return M 93 return M