diff src/goodjava/lucene/api/LuceneIndexWriter.java @ 1528:3bd4d7963456

use goodjava/lucene/api
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 26 Jul 2020 23:11:53 -0600
parents f848d40b3b07
children c27dc6af87ca
line wrap: on
line diff
--- a/src/goodjava/lucene/api/LuceneIndexWriter.java	Sun Jul 26 15:06:15 2020 -0600
+++ b/src/goodjava/lucene/api/LuceneIndexWriter.java	Sun Jul 26 23:11:53 2020 -0600
@@ -16,6 +16,7 @@
 import org.apache.lucene.document.FloatField;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.LiveIndexWriterConfig;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexReader;
@@ -23,28 +24,36 @@
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.Version;
 import goodjava.logging.Logger;
 import goodjava.logging.LoggerFactory;
 
 
 public final class LuceneIndexWriter implements GoodIndexWriter {
 	private static final Logger logger = LoggerFactory.getLogger(LuceneIndexWriter.class);
-	private final FieldAnalyzer fieldAnalyzer = new FieldAnalyzer();
-	public final Version luceneVersion;
-	public final IndexWriterConfig luceneConfig;
+	private final FieldAnalyzer fieldAnalyzer;
 	public final IndexWriter luceneWriter;
 	public final GoodIndexWriterConfig goodConfig;
 	private final Map<String,Boolean> indexedMap = new HashMap<String,Boolean>();
 
-	public LuceneIndexWriter(Version luceneVersion,Directory dir,GoodIndexWriterConfig goodConfig) throws IOException {
-		this.luceneVersion = luceneVersion;
-		this.luceneConfig = new IndexWriterConfig(luceneVersion,fieldAnalyzer);
+	public LuceneIndexWriter(Directory dir,GoodIndexWriterConfig goodConfig) throws IOException {
+		IndexWriterConfig luceneConfig = goodConfig.newLuceneConfig();
+		Analyzer analyzer = luceneConfig.getAnalyzer();
+		if( !(analyzer instanceof FieldAnalyzer) )
+			throw new RuntimeException("analyzer must be FieldAnalyzer");
+		this.fieldAnalyzer = (FieldAnalyzer)analyzer;
 		this.luceneWriter = new IndexWriter(dir,luceneConfig);
 		this.goodConfig = goodConfig;
 		luceneWriter.commit();  // commit index creation
 	}
 
+	public Directory getDirectory() {
+		return luceneWriter.getDirectory();
+	}
+
+	public LiveIndexWriterConfig getLuceneConfig() {
+		return luceneWriter.getConfig();
+	}
+
 	public void close() throws IOException {
 		luceneWriter.close();
 	}
@@ -74,7 +83,7 @@
 		if( !isIndexed(keyFieldName) )
 			throw new RuntimeException("can't update using unindexed field "+keyFieldName);
 		if( fieldAnalyzer.isAdded(keyFieldName) )
-			throw new RuntimeException("can't update using analyzeed field "+keyFieldName);
+			throw new RuntimeException("can't update using analyzed field "+keyFieldName);
 		Document doc = newDocument(storedFields);
 		Object keyValue = storedFields.get(keyFieldName);
 		if( keyValue==null )