changeset 303:fdb4bd391c28

add lucene close(); add Web_server.start(); git-svn-id: https://luan-java.googlecode.com/svn/trunk@304 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 18 Dec 2014 07:51:29 +0000
parents 2f8938fc518c
children 03e9cda4748d
files dist/jars/luan-core-trunk.jar dist/jars/luan-logging-trunk.jar dist/jars/luan-lucene-trunk.jar dist/jars/luan-mail-trunk.jar dist/jars/luan-web-trunk.jar lucene/src/luan/modules/lucene/Lucene.luan lucene/src/luan/modules/lucene/LuceneIndex.java web/src/luan/modules/web/Web_server.luan
diffstat 8 files changed, 22 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
Binary file dist/jars/luan-core-trunk.jar has changed
Binary file dist/jars/luan-logging-trunk.jar has changed
Binary file dist/jars/luan-lucene-trunk.jar has changed
Binary file dist/jars/luan-mail-trunk.jar has changed
Binary file dist/jars/luan-web-trunk.jar has changed
--- a/lucene/src/luan/modules/lucene/Lucene.luan	Thu Dec 18 04:56:30 2014 +0000
+++ b/lucene/src/luan/modules/lucene/Lucene.luan	Thu Dec 18 07:51:29 2014 +0000
@@ -11,7 +11,16 @@
 
 
 function Index(indexDir)
-	local index = LuceneIndex.new(indexDir).table()
+	local index = {}
+	local java_index = LuceneIndex.new(indexDir)
+	index.fields = java_index.fields
+	index.to_string = java_index.to_string
+	index.backup = java_index.backup
+	index.Writer = java_index.Writer
+	index.Searcher = java_index.Searcher
+	index.delete_all = java_index.delete_all
+	index.map_field_name = java_index.map_field_name
+	index.close = java_index.close
 
 	function index.save_document(doc)
 		index.Writer( function(writer)
--- a/lucene/src/luan/modules/lucene/LuceneIndex.java	Thu Dec 18 04:56:30 2014 +0000
+++ b/lucene/src/luan/modules/lucene/LuceneIndex.java	Thu Dec 18 07:51:29 2014 +0000
@@ -39,7 +39,7 @@
 	final IndexWriter writer;
 	private DirectoryReader reader;
 	private LuceneSearcher searcher;
-	final FieldTable fields = new FieldTable();
+	public final FieldTable fields = new FieldTable();
 
 	public LuceneIndex(LuanState luan,String indexDirStr) throws LuanException, IOException {
 		File indexDir = new File(indexDirStr);
@@ -183,24 +183,9 @@
 		}
 	}
 
-	private void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
-		t.put( method, new LuanJavaFunction(LuceneIndex.class.getMethod(method,parameterTypes),this) );
-	}
-
-	public LuanTable table() {
-		LuanTable tbl = Luan.newTable();
-		try {
-			tbl.put("fields",fields);
-			add( tbl, "to_string" );
-			add( tbl, "backup", LuanState.class, String.class );
-			add( tbl, "Writer", LuanState.class, LuanFunction.class );
-			add( tbl, "Searcher", LuanState.class, LuanFunction.class );
-			add( tbl, "delete_all" );
-			add( tbl, "map_field_name", String.class );
-		} catch(NoSuchMethodException e) {
-			throw new RuntimeException(e);
-		}
-		return tbl;
+	public void close() throws IOException {
+		writer.close();
+		reader.close();
 	}
 
 }
--- a/web/src/luan/modules/web/Web_server.luan	Thu Dec 18 04:56:30 2014 +0000
+++ b/web/src/luan/modules/web/Web_server.luan	Thu Dec 18 07:51:29 2014 +0000
@@ -1,8 +1,8 @@
 import "luan:String"
 import "luan:Io"
 import "luan:Package"
+import "luan:logging/Logging"  -- initialize logging
 import "luan:web/Http"
-import "luan:logging/Logging"  -- initialize logging
 
 java()
 import "java:org.eclipse.jetty.server.Server"
@@ -67,9 +67,6 @@
 local hc = HandlerCollection.new()
 hc.setHandlers { SessionHandler.new(), handler_wrapper, DefaultHandler.new(), log_handler }
 
--- override to config server
-function config_server(server)
-end 
 
 function init(dir)
 	dir = dir.gsub("/$","")  -- remove trailing '/' if any
@@ -85,12 +82,15 @@
 	resource_handler.setResourceBase(Io.Uri(base).to_string())
 	resource_handler.setWelcomeFiles {welcome_file}
 	luan_handler.setWelcomeFile(welcome_file)
+	server = Server.new(port)
+	server.setHandler(hc)
+end
+
+function start()
+	server.start()
 end
 
 function serve(dir)
 	init(dir)
-	local server = Server.new(port)
-	server.setHandler(hc);
-	config_server(server)
-	server.start()
+	start()
 end