Mercurial Hosting > luan
diff 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 diff
--- a/lucene/src/luan/modules/lucene/Lucene.luan Wed Oct 01 02:15:39 2014 +0000 +++ b/lucene/src/luan/modules/lucene/Lucene.luan Wed Oct 01 06:55:14 2014 +0000 @@ -2,12 +2,12 @@ import "luan.modules.lucene.LuceneIndex" standard_fields = { - "type" = "type index"; - "id" = "id index"; + type = "type index"; + id = "id index"; } function Index(indexDir) - local index LuceneIndex.new(indexDir).table() + local index = LuceneIndex.new(indexDir).table() function index.save_document(doc) index.Writer( function(writer) @@ -21,5 +21,17 @@ 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