Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
1464:465b4a0dae4a | 1465:5e3870618377 |
---|---|
24 import org.apache.lucene.store.Directory; | 24 import org.apache.lucene.store.Directory; |
25 import org.apache.lucene.util.Version; | 25 import org.apache.lucene.util.Version; |
26 | 26 |
27 | 27 |
28 public final class LuceneIndexWriter implements GoodIndexWriter { | 28 public final class LuceneIndexWriter implements GoodIndexWriter { |
29 final FieldAnalyzer fieldAnalyzer = new FieldAnalyzer(); | 29 private final FieldAnalyzer fieldAnalyzer = new FieldAnalyzer(); |
30 public final Version luceneVersion; | |
30 public final IndexWriterConfig luceneConfig; | 31 public final IndexWriterConfig luceneConfig; |
32 public final IndexWriter luceneWriter; | |
31 public final GoodIndexWriterConfig goodConfig; | 33 public final GoodIndexWriterConfig goodConfig; |
32 public final IndexWriter luceneWriter; | |
33 private final Map<String,Boolean> indexedMap = new HashMap<String,Boolean>(); | 34 private final Map<String,Boolean> indexedMap = new HashMap<String,Boolean>(); |
34 | 35 |
35 public LuceneIndexWriter(Version matchVersion,Directory dir,GoodIndexWriterConfig goodConfig) throws IOException { | 36 public LuceneIndexWriter(Version luceneVersion,Directory dir,GoodIndexWriterConfig goodConfig) throws IOException { |
36 luceneConfig = new IndexWriterConfig(matchVersion,fieldAnalyzer); | 37 this.luceneVersion = luceneVersion; |
37 luceneWriter = new IndexWriter(dir,luceneConfig); | 38 this.luceneConfig = new IndexWriterConfig(luceneVersion,fieldAnalyzer); |
39 this.luceneWriter = new IndexWriter(dir,luceneConfig); | |
38 this.goodConfig = goodConfig; | 40 this.goodConfig = goodConfig; |
41 luceneWriter.commit(); // commit index creation | |
39 } | 42 } |
40 | 43 |
41 public void close() throws IOException { | 44 public void close() throws IOException { |
42 luceneWriter.close(); | 45 luceneWriter.close(); |
43 } | 46 } |
160 return b; | 163 return b; |
161 } | 164 } |
162 | 165 |
163 | 166 |
164 public void reindexDocuments(final String keyFieldName,Query query) throws IOException { | 167 public void reindexDocuments(final String keyFieldName,Query query) throws IOException { |
165 IndexReader reader = DirectoryReader.open(luceneWriter.getDirectory()); | 168 IndexReader reader = openReader(); |
166 final IndexSearcher searcher = new IndexSearcher(reader); | 169 final IndexSearcher searcher = new IndexSearcher(reader); |
167 searcher.search( query, new GoodCollector(){ | 170 searcher.search( query, new GoodCollector(){ |
168 public void collectDoc(int iDoc) throws IOException { | 171 public void collectDoc(int iDoc) throws IOException { |
169 Document doc = searcher.doc(iDoc); | 172 Document doc = searcher.doc(iDoc); |
170 Map<String,Object> storedFields = LuceneUtils.toMap(doc); | 173 Map<String,Object> storedFields = LuceneUtils.toMap(doc); |
171 updateDocument(keyFieldName,storedFields); | 174 updateDocument(keyFieldName,storedFields); |
172 } | 175 } |
173 }); | 176 }); |
174 reader.close(); | 177 reader.close(); |
175 } | 178 } |
179 | |
180 public IndexReader openReader() throws IOException { | |
181 return DirectoryReader.open(luceneWriter.getDirectory()); | |
182 } | |
176 } | 183 } |