public void optimize() { try { for (IndexWriterContext writer : indexWriters.values()) { writer.writer.optimize(true); writer.modifiedFlag = true; } } catch (IOException e) { throw new RuntimeException(e); } }
public void index(long node, String key, Object value) { try { IndexWriterContext writer = getWriter(key, true); Document document = new Document(); fillDocument(document, node, key, value); writer.writer.addDocument(document); writer.modifiedFlag = true; } catch (IOException e) { throw new RuntimeException(e); } }
private IndexSearcher getSearcher(String key) { try { IndexWriterContext writer = getWriter(key, false); if (writer == null) { return null; } IndexSearcher oldSearcher = indexSearchers.get(key); IndexSearcher result = oldSearcher; if (oldSearcher == null || writer.modifiedFlag) { if (oldSearcher != null) { oldSearcher.getIndexReader().close(); oldSearcher.close(); } IndexReader newReader = writer.writer.getReader(); result = new IndexSearcher(newReader); indexSearchers.put(key, result); writer.modifiedFlag = false; } return result; } catch (IOException e) { throw new RuntimeException(e); } }