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