Mercurial Hosting > luan
view lucene/src/luan/modules/lucene/Lucene.luan @ 272:eb27e765affb
rename Io.protocols to Io.schemes and "class:" to "java:"
git-svn-id: https://luan-java.googlecode.com/svn/trunk@273 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 31 Oct 2014 04:50:24 +0000 |
parents | 9e0d4452e649 |
children | 4d53e9fc1bd9 |
line wrap: on
line source
import "luan:Java" import "java:luan.modules.lucene.LuceneIndex" 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_first(query, sort) return index.Searcher( function(searcher) local results, _, total_hits = searcher.search(query,1,sort) return results(), total_hits end ) end function index.get_document(query) local doc, total_hits = index.get_first(query); if total_hits > 1 then error( "found " .. total_hits .. " documents" ) end return doc end function index.count(query) return index.Searcher( function(searcher) local _, _, total_hits = searcher.search(query,0) return total_hits end ) end return index end