List of usage examples for org.apache.lucene.index IndexWriter flush
public final void flush() throws IOException
From source file:org.sonatype.nexus.index.updater.DefaultIndexUpdater.java
License:Open Source License
private static void filterDirectory(final Directory directory, final DocumentFilter filter) throws IOException { IndexReader r = null;//from w w w. j a v a2 s . c o m try { r = IndexReader.open(directory); int numDocs = r.numDocs(); for (int i = 0; i < numDocs; i++) { if (r.isDeleted(i)) { continue; } Document d = r.document(i); if (!filter.accept(d)) { r.deleteDocument(i); } } } finally { IndexUtils.close(r); } IndexWriter w = null; try { // analyzer is unimportant, since we are not adding/searching to/on index, only reading/deleting w = new IndexWriter(directory, new NexusAnalyzer()); w.optimize(); w.flush(); } finally { IndexUtils.close(w); } }
From source file:org.sonatype.nexus.index.updater.IndexDataReader.java
License:Open Source License
public IndexDataReadResult readIndex(IndexWriter w, IndexingContext context) throws IOException { dis.readByte(); // data format version long timestamp = dis.readLong(); Date date = null;/* w w w . j a v a 2s . c o m*/ if (timestamp != -1) { date = new Date(timestamp); IndexUtils.updateTimestamp(w.getDirectory(), date); } int n = 0; Document doc; while ((doc = readDocument()) != null) { w.addDocument(IndexUtils.updateDocument(doc, context, false)); n++; } w.flush(); w.optimize(); IndexDataReadResult result = new IndexDataReadResult(); result.setDocumentCount(n); result.setTimestamp(date); return result; }