comparison src/goodjava/lucene/logging/LoggingIndexWriter.java @ 1528:3bd4d7963456

use goodjava/lucene/api
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 26 Jul 2020 23:11:53 -0600
parents 31b543826ca9
children 634f6765830e
comparison
equal deleted inserted replaced
1527:fa1e3adbebfb 1528:3bd4d7963456
15 import java.util.Random; 15 import java.util.Random;
16 import org.apache.lucene.document.Document; 16 import org.apache.lucene.document.Document;
17 import org.apache.lucene.index.DirectoryReader; 17 import org.apache.lucene.index.DirectoryReader;
18 import org.apache.lucene.index.IndexReader; 18 import org.apache.lucene.index.IndexReader;
19 import org.apache.lucene.index.Term; 19 import org.apache.lucene.index.Term;
20 import org.apache.lucene.index.LiveIndexWriterConfig;
20 import org.apache.lucene.search.IndexSearcher; 21 import org.apache.lucene.search.IndexSearcher;
21 import org.apache.lucene.search.Query; 22 import org.apache.lucene.search.Query;
22 import org.apache.lucene.search.MatchAllDocsQuery; 23 import org.apache.lucene.search.MatchAllDocsQuery;
23 import org.apache.lucene.search.TopDocs; 24 import org.apache.lucene.search.TopDocs;
24 import org.apache.lucene.search.PrefixQuery; 25 import org.apache.lucene.search.PrefixQuery;
76 } 77 }
77 } 78 }
78 newLogs(); 79 newLogs();
79 } 80 }
80 81
82 public Directory getDirectory() {
83 return indexWriter.getDirectory();
84 }
85
86 public LiveIndexWriterConfig getLuceneConfig() {
87 return indexWriter.getLuceneConfig();
88 }
89
81 private void setLog() throws IOException { 90 private void setLog() throws IOException {
82 if( log != null ) 91 if( log != null )
83 log.close(); 92 log.close();
84 log = logs.get(logs.size()-1).output(); 93 log = logs.get(logs.size()-1).output();
85 } 94 }
178 long lastTime = second.file.lastModified(); 187 long lastTime = second.file.lastModified();
179 File dirFile = new File(logDir,"merge"); 188 File dirFile = new File(logDir,"merge");
180 if( dirFile.exists() ) 189 if( dirFile.exists() )
181 throw new RuntimeException(); 190 throw new RuntimeException();
182 Directory dir = FSDirectory.open(dirFile); 191 Directory dir = FSDirectory.open(dirFile);
183 LuceneIndexWriter mergeWriter = new LuceneIndexWriter( indexWriter.luceneVersion, dir, indexWriter.goodConfig ); 192 LuceneIndexWriter mergeWriter = new LuceneIndexWriter( dir, indexWriter.goodConfig );
184 playLog( first.input(), mergeWriter ); 193 playLog( first.input(), mergeWriter );
185 playLog( second.input(), mergeWriter ); 194 playLog( second.input(), mergeWriter );
186 mergeWriter.commit(); 195 mergeWriter.commit();
187 LogFile merge = newLogFile(); 196 LogFile merge = newLogFile();
188 logLucene( lastTime, merge, mergeWriter ); 197 logLucene( lastTime, merge, mergeWriter );
249 logger.info("check start"); 258 logger.info("check start");
250 indexWriter.check(); 259 indexWriter.check();
251 File dirFile = new File(logDir,"check"); 260 File dirFile = new File(logDir,"check");
252 IoUtils.deleteRecursively(dirFile); 261 IoUtils.deleteRecursively(dirFile);
253 Directory dir = FSDirectory.open(dirFile); 262 Directory dir = FSDirectory.open(dirFile);
254 LuceneIndexWriter checkWriter = new LuceneIndexWriter( indexWriter.luceneVersion, dir, indexWriter.goodConfig ); 263 LuceneIndexWriter checkWriter = new LuceneIndexWriter( dir, indexWriter.goodConfig );
255 playLogs(logReaders,checkWriter); 264 playLogs(logReaders,checkWriter);
256 logger.info("check lucene"); 265 logger.info("check lucene");
257 IndexReader checkReader = checkWriter.openReader(); 266 IndexReader checkReader = checkWriter.openReader();
258 if( sortField == null ) { 267 if( sortField == null ) {
259 int nCheck = checkReader.numDocs(); 268 int nCheck = checkReader.numDocs();