Mercurial Hosting > luan
diff lucene/src/luan/modules/lucene/Lucene.luan @ 545:ddcd4296107a
clean up lucene search
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 14 Jun 2015 01:34:42 -0600 |
parents | c5a93767cc5c |
children | eaef1005ab87 |
line wrap: on
line diff
--- a/lucene/src/luan/modules/lucene/Lucene.luan Fri Jun 12 19:11:44 2015 -0600 +++ b/lucene/src/luan/modules/lucene/Lucene.luan Sun Jun 14 01:34:42 2015 -0600 @@ -16,47 +16,51 @@ function M.index(indexDir) local index = {} - local java_index = LuceneIndex.new(indexDir) + local java_index = LuceneIndex.new(indexDir,index) index.indexed_fields = java_index.indexedFieldsMeta.newTable() index.to_string = java_index.to_string index.backup = java_index.backup - index.Writer = java_index.Writer - index.Searcher = java_index.Searcher + index.writer = java_index.writer + index.advanced_search = java_index.advanced_search + index.search_in_transaction = java_index.search_in_transaction index.delete_all = java_index.delete_all index.close = java_index.close function index.save_document(doc) - index.Writer( function(writer) + index.writer( function(writer) writer.save_document(doc) end ) end function index.delete_documents(terms) - index.Writer( function(writer) + index.writer( function(writer) writer.delete_documents(terms) end ) end - function index.get_first(query, sort) - return index.Searcher( function(searcher) - local results, _, total_hits = searcher.search(query,1,sort) - return results(), total_hits - end ) + function index.search(query, from, to, sort) + local results = {} + local function fn(i,doc_fn) + if i >= from then + results[#results+1] = doc_fn() + end + end + local total_hits = index.advanced_search(query,fn,to,sort) + return results, total_hits end function index.get_document(query) - local doc, total_hits = index.get_first(query); - if total_hits > 1 then - error( "found " .. total_hits .. " documents" ) + local doc + local function fn(_,doc_fn) + doc = doc_fn() end + local total_hits = index.advanced_search(query,fn,1) + total_hits <= 1 or error( "found " .. total_hits .. " documents" ) return doc end function index.count(query) - return index.Searcher( function(searcher) - local _, _, total_hits = searcher.search(query,0) - return total_hits - end ) + return index.advanced_search(query) end return index