view lucene/src/luan/modules/lucene/Lucene.luan @ 233:ef39bc4d3f70

basic lucene works git-svn-id: https://luan-java.googlecode.com/svn/trunk@234 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 02 Oct 2014 02:58:55 +0000
parents 9ce18106f95a
children c5c60eca33dd
line wrap: on
line source

import "Java"
import "luan.modules.lucene.LuceneIndex"


function Index(indexDir)
	local index = LuceneIndex.new(indexDir).table()

	function index.save_document(doc)
		index.Writer( function(writer)
			writer.save_document(doc)
		end )
	end

	function index.delete_documents(terms)
		index.Writer( function(writer)
			writer.delete_documents(terms)
		end )
	end

	function index.get_document(query)
		return index.Searcher( function(searcher)
			local results, _, total_hits = searcher.search(query,1)
			if total_hits == 0 then
				return nil
			elseif total_hits > 1 then
				error( "found " .. total_hits .. " documents" )
			end
			return results()
		end )
	end

	return index
end