Mercurial Hosting > luan
diff src/goodjava/lucene/api/LuceneIndexWriter.java @ 1465:5e3870618377
lucene.logging dir
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 12 Apr 2020 15:59:57 -0600 |
parents | 3ab0d043370f |
children | 7d145095cc0b |
line wrap: on
line diff
--- a/src/goodjava/lucene/api/LuceneIndexWriter.java Fri Apr 03 10:04:52 2020 -0600 +++ b/src/goodjava/lucene/api/LuceneIndexWriter.java Sun Apr 12 15:59:57 2020 -0600 @@ -26,16 +26,19 @@ public final class LuceneIndexWriter implements GoodIndexWriter { - final FieldAnalyzer fieldAnalyzer = new FieldAnalyzer(); + private final FieldAnalyzer fieldAnalyzer = new FieldAnalyzer(); + public final Version luceneVersion; public final IndexWriterConfig luceneConfig; + public final IndexWriter luceneWriter; public final GoodIndexWriterConfig goodConfig; - public final IndexWriter luceneWriter; private final Map<String,Boolean> indexedMap = new HashMap<String,Boolean>(); - public LuceneIndexWriter(Version matchVersion,Directory dir,GoodIndexWriterConfig goodConfig) throws IOException { - luceneConfig = new IndexWriterConfig(matchVersion,fieldAnalyzer); - luceneWriter = new IndexWriter(dir,luceneConfig); + public LuceneIndexWriter(Version luceneVersion,Directory dir,GoodIndexWriterConfig goodConfig) throws IOException { + this.luceneVersion = luceneVersion; + this.luceneConfig = new IndexWriterConfig(luceneVersion,fieldAnalyzer); + this.luceneWriter = new IndexWriter(dir,luceneConfig); this.goodConfig = goodConfig; + luceneWriter.commit(); // commit index creation } public void close() throws IOException { @@ -162,7 +165,7 @@ public void reindexDocuments(final String keyFieldName,Query query) throws IOException { - IndexReader reader = DirectoryReader.open(luceneWriter.getDirectory()); + IndexReader reader = openReader(); final IndexSearcher searcher = new IndexSearcher(reader); searcher.search( query, new GoodCollector(){ public void collectDoc(int iDoc) throws IOException { @@ -173,4 +176,8 @@ }); reader.close(); } + + public IndexReader openReader() throws IOException { + return DirectoryReader.open(luceneWriter.getDirectory()); + } }