Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
231:a35417bf493a | 232:9ce18106f95a |
---|---|
1 import "Java" | 1 import "Java" |
2 import "luan.modules.lucene.LuceneIndex" | 2 import "luan.modules.lucene.LuceneIndex" |
3 | 3 |
4 standard_fields = { | 4 standard_fields = { |
5 "type" = "type index"; | 5 type = "type index"; |
6 "id" = "id index"; | 6 id = "id index"; |
7 } | 7 } |
8 | 8 |
9 function Index(indexDir) | 9 function Index(indexDir) |
10 local index LuceneIndex.new(indexDir).table() | 10 local index = LuceneIndex.new(indexDir).table() |
11 | 11 |
12 function index.save_document(doc) | 12 function index.save_document(doc) |
13 index.Writer( function(writer) | 13 index.Writer( function(writer) |
14 writer.save_document(doc) | 14 writer.save_document(doc) |
15 end ) | 15 end ) |
19 index.Writer( function(writer) | 19 index.Writer( function(writer) |
20 writer.delete_documents(terms) | 20 writer.delete_documents(terms) |
21 end ) | 21 end ) |
22 end | 22 end |
23 | 23 |
24 function index.get_document(query) | |
25 index.Searcher( function(searcher) | |
26 local results, _, total_hits = searcher.search(query,1) | |
27 if total_hits == 0 then | |
28 return nil | |
29 elseif total_hits > 1 then | |
30 error "found " .. total_hits .. " documents" | |
31 end | |
32 return results() | |
33 end ) | |
34 end | |
35 | |
24 return index | 36 return index |
25 end | 37 end |