view lucene/src/luan/modules/lucene/Lucene.luan @ 232:9ce18106f95a

more lucene work git-svn-id: https://luan-java.googlecode.com/svn/trunk@233 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Wed, 01 Oct 2014 06:55:14 +0000
parents 4438cb2e04d0
children ef39bc4d3f70
line wrap: on
line source

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

standard_fields = {
	type = "type index";
	id = "id index";
}

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)
		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