diff lucene/src/luan/modules/lucene/LuceneIndex.java @ 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/LuceneIndex.java	Wed Oct 01 02:15:39 2014 +0000
+++ b/lucene/src/luan/modules/lucene/LuceneIndex.java	Wed Oct 01 06:55:14 2014 +0000
@@ -88,7 +88,7 @@
 	private long idLim = 0;
 	private final int idBatch = 10;
 
-	private void initId() {
+	private void initId() throws IOException {
 		TopDocs td = searcher.search(new TermQuery(new Term(FLD_TYPE,"next_id")),1);
 		switch(td.totalHits) {
 		case 0:
@@ -119,27 +119,6 @@
 		}
 	}
 
-	public LuanTable getDocument(String id) {
-		return getDocument(new Term(LuceneWriter.FLD_ID,id));
-	}
-
-	public LuanTable getDocument(Term term) {
-		LuceneSearcher searcher = openSearcher();
-		try {
-			TopDocs td = searcher.search(new TermQuery(term),1);
-			switch(td.totalHits) {
-			case 0:
-				return null;
-			case 1:
-				return searcher.doc(td.scoreDocs[0].doc);
-			default:
-				throw new RuntimeException();
-			}
-		} finally {
-			searcher.close();
-		}
-	}
-
 
 	public void backup(String zipFile) {
 		if( !zipFile.endsWith(".zip") )
@@ -180,6 +159,15 @@
 		}
 	}
 
+	public void Searcher(LuanState luan,LuanFunction fn) throws LuanException, IOException {
+		LuceneSearcher searcher = openSearcher();
+		try {
+			luan.call( fn, new Object[]{searcher.table()} );
+		} finally {
+			searcher.close();
+		}
+	}
+
 	private void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
 		t.put( method, new LuanJavaFunction(LuceneIndex.class.getMethod(method,parameterTypes),this) );
 	}
@@ -189,6 +177,8 @@
 		try {
 			add( tbl, "to_string" );
 			add( tbl, "backup", String.class );
+			add( tbl, "Writer", LuanState.class, LuanFunction.class );
+			add( tbl, "Searcher", LuanState.class, LuanFunction.class );
 		} catch(NoSuchMethodException e) {
 			throw new RuntimeException(e);
 		}