changeset 1346:efd1c6380f2c

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 25 Feb 2019 12:29:33 -0700
parents 6f8988830098
children 643cf1c37723
files src/luan/modules/lucene/LuceneIndex.java
diffstat 1 files changed, 19 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
diff -r 6f8988830098 -r efd1c6380f2c src/luan/modules/lucene/LuceneIndex.java
--- a/src/luan/modules/lucene/LuceneIndex.java	Mon Feb 25 11:00:10 2019 -0700
+++ b/src/luan/modules/lucene/LuceneIndex.java	Mon Feb 25 12:29:33 2019 -0700
@@ -213,8 +213,8 @@
 		return new Term(key,br);
 	}
 
-	public void delete(Luan luan,String queryStr)
-		throws LuanException, IOException, ParseException
+	public void delete(String queryStr)
+		throws IOException, ParseException
 	{
 		Query query = SaneQueryParser.parseQuery(mfp,queryStr);
 
@@ -233,7 +233,7 @@
 		indexOnly.addAll(fields);
 	}
 
-	public void save(Luan luan,LuanTable doc,LuanTable boosts)
+	public void save(LuanTable doc,LuanTable boosts)
 		throws LuanException, IOException
 	{
 		Object obj = doc.get("id");
@@ -248,7 +248,7 @@
 		writeLock.lock();
 		try {
 			if( id == null ) {
-				id = nextId(luan);
+				id = nextId();
 				doc.put("id",id);
 				writer.addDocument(toLucene(doc,boosts));
 			} else {
@@ -308,13 +308,13 @@
 		}
 	}
 
-	public synchronized long nextId(Luan luan) throws LuanException, IOException {
+	public synchronized long nextId() throws LuanException, IOException {
 		if( ++id > idLim ) {
 			idLim += idBatch;
-			LuanTable doc = new LuanTable(luan);
-			doc.rawPut( "type", "next_id" );
-			doc.rawPut( FLD_NEXT_ID, idLim );
-			writer.updateDocument(new Term("type","next_id"),toLucene(doc,null));
+			Map doc = new HashMap();
+			doc.put( "type", "next_id" );
+			doc.put( FLD_NEXT_ID, idLim );
+			writer.updateDocument(new Term("type","next_id"),toLucene(doc.entrySet(),null));
 			wrote();
 		}
 		return id;
@@ -344,11 +344,11 @@
 		return snapshotDeletionPolicy;
 	}
 
-	public Object snapshot(Luan luan,LuanFunction fn) throws LuanException, IOException {
+	public Object snapshot(LuanFunction fn) throws LuanException, IOException {
 		IndexCommit ic = snapshotDeletionPolicy.snapshot();
 		try {
 			String dir = fileDir.toString();
-			LuanTable fileNames = new LuanTable(luan,new ArrayList(ic.getFileNames()));
+			LuanTable fileNames = new LuanTable(fn.luan(),new ArrayList(ic.getFileNames()));
 			return fn.call(dir,fileNames);
 		} finally {
 			snapshotDeletionPolicy.release(ic);
@@ -441,7 +441,7 @@
 		close(openSearcher());
 	}
 
-	public int advanced_search( final Luan luan, String queryStr, LuanFunction fn, Integer n, String sortStr )
+	public int advanced_search( String queryStr, LuanFunction fn, Integer n, String sortStr )
 		throws LuanException, IOException, ParseException
 	{
 		Utils.checkNotNull(queryStr);
@@ -454,7 +454,7 @@
 			if( fn!=null && n==null ) {
 				if( sortStr != null )
 					throw new LuanException("sort must be nil when n is nil");
-				final DocFn docFn = new DocFn(luan,searcher,query);
+				final DocFn docFn = new DocFn(fn.luan(),searcher,query);
 				MyCollector col = new MyCollector() {
 					@Override public void collect(int doc) {
 						try {
@@ -480,7 +480,7 @@
 			Sort sort = sortStr==null ? null : SaneQueryParser.parseSort(mfp,sortStr);
 			TopDocs td = sort==null ? searcher.search(query,n) : searcher.search(query,n,sort);
 			final ScoreDoc[] scoreDocs = td.scoreDocs;
-			DocFn docFn = new DocFn(luan,searcher,query);
+			DocFn docFn = new DocFn(fn.luan(),searcher,query);
 			for( int i=0; i<scoreDocs.length; i++ ) {
 				ScoreDoc scoreDoc = scoreDocs[i];
 				docFn.docID = scoreDoc.doc;
@@ -578,9 +578,13 @@
 	}
 
 	private Document toLucene(LuanTable table,LuanTable boosts) throws LuanException {
+		return toLucene(table,boosts);
+	}
+
+	private Document toLucene(Iterable<Map.Entry> iterable,LuanTable boosts) throws LuanException {
 		Set<String> indexed = mfp.fields.keySet();
 		Document doc = new Document();
-		for( Map.Entry<Object,Object> entry : table.iterable() ) {
+		for( Map.Entry<Object,Object> entry : iterable ) {
 			Object key = entry.getKey();
 			if( !(key instanceof String) )
 				throw new LuanException("key must be string");