changeset 707:1ed9e55f0be8

replace lucene.backup with lucene.zip implemented in luan, and add lucene.snapshot
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 18 May 2016 15:46:51 -0600
parents 30c87c859277
children 77e0c859c8a3
files lucene/src/luan/modules/lucene/Lucene.luan lucene/src/luan/modules/lucene/LuceneIndex.java
diffstat 2 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
diff -r 30c87c859277 -r 1ed9e55f0be8 lucene/src/luan/modules/lucene/Lucene.luan
--- a/lucene/src/luan/modules/lucene/Lucene.luan	Tue May 17 19:00:25 2016 -0600
+++ b/lucene/src/luan/modules/lucene/Lucene.luan	Wed May 18 15:46:51 2016 -0600
@@ -4,6 +4,9 @@
 local ipairs = Luan.ipairs or error()
 local type = Luan.type or error()
 local Html = require "luan:Html.luan"
+local Io = require "luan:Io.luan"
+local String = require "luan:String.luan"
+local matches = String.matches or error()
 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex"
 local NumberFieldParser = require "java:sane.lucene.queryparser.NumberFieldParser"
 local StringFieldParser = require "java:sane.lucene.queryparser.StringFieldParser"
@@ -35,7 +38,8 @@
 	index.indexed_only_fields = java_index.indexed_only_fields
 
 	index.to_string = java_index.to_string
-	index.backup = java_index.backup
+--	index.backup = java_index.backup
+	index.snapshot = java_index.snapshot
 	index.advanced_search = java_index.advanced_search
 	index.search_in_transaction = java_index.search_in_transaction
 	index.delete_all = java_index.delete_all
@@ -87,6 +91,17 @@
 		end
 	end
 
+	function index.zip(zip_file)
+		matches(zip_file,[[\.zip$]]) or error("file "..zip_file.." doesn't end with '.zip'")
+		index.snapshot( function(dir,file_names)
+			local t = {}
+			for _, file_name in ipairs(file_names) do
+				t[file_name] = "file:"..dir.."/"..file_name
+			end
+			Io.zip(zip_file,t)
+		end )
+	end
+
 	return index
 end
 
diff -r 30c87c859277 -r 1ed9e55f0be8 lucene/src/luan/modules/lucene/LuceneIndex.java
--- a/lucene/src/luan/modules/lucene/LuceneIndex.java	Tue May 17 19:00:25 2016 -0600
+++ b/lucene/src/luan/modules/lucene/LuceneIndex.java	Wed May 18 15:46:51 2016 -0600
@@ -276,7 +276,7 @@
 		return id;
 	}
 
-
+/*
 	public void backup(String zipFile) throws LuanException, IOException {
 		if( !zipFile.endsWith(".zip") )
 			throw new LuanException("file "+zipFile+" doesn't end with '.zip'");
@@ -295,6 +295,17 @@
 			snapshotDeletionPolicy.release(ic);
 		}
 	}
+*/
+	public Object snapshot(LuanState luan,LuanFunction fn) throws LuanException, IOException {
+		IndexCommit ic = snapshotDeletionPolicy.snapshot();
+		try {
+			String dir = fileDir.toString();
+			LuanTable fileNames = new LuanTable(new ArrayList(ic.getFileNames()));
+			return fn.call(luan,new Object[]{dir,fileNames});
+		} finally {
+			snapshotDeletionPolicy.release(ic);
+		}
+	}