Mercurial Hosting > luan
comparison lucene/src/luan/modules/lucene/Lucene.luan @ 257:c5c60eca33dd
allow Lucene search for 0 rows
git-svn-id: https://luan-java.googlecode.com/svn/trunk@258 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 28 Oct 2014 03:05:37 +0000 |
parents | ef39bc4d3f70 |
children | 9e0d4452e649 |
comparison
equal
deleted
inserted
replaced
256:15122d724ce4 | 257:c5c60eca33dd |
---|---|
15 index.Writer( function(writer) | 15 index.Writer( function(writer) |
16 writer.delete_documents(terms) | 16 writer.delete_documents(terms) |
17 end ) | 17 end ) |
18 end | 18 end |
19 | 19 |
20 function index.get_first(query, sort) | |
21 return index.Searcher( function(searcher) | |
22 local results, _, total_hits = searcher.search(query,1,sort) | |
23 return results(), total_hits | |
24 end ) | |
25 end | |
26 | |
20 function index.get_document(query) | 27 function index.get_document(query) |
28 local doc, total_hits = index.get_first(query); | |
29 if total_hits > 1 then | |
30 error( "found " .. total_hits .. " documents" ) | |
31 end | |
32 return doc | |
33 end | |
34 | |
35 function index.count(query) | |
21 return index.Searcher( function(searcher) | 36 return index.Searcher( function(searcher) |
22 local results, _, total_hits = searcher.search(query,1) | 37 local _, _, total_hits = searcher.search(query,0) |
23 if total_hits == 0 then | 38 return total_hits |
24 return nil | |
25 elseif total_hits > 1 then | |
26 error( "found " .. total_hits .. " documents" ) | |
27 end | |
28 return results() | |
29 end ) | 39 end ) |
30 end | 40 end |
31 | 41 |
32 return index | 42 return index |
33 end | 43 end |