protected void change(long nodeId, Object value) throws IOException, IndexCapacityExceededException { Fieldable encodedValue = documentStructure.encodeAsFieldable(value); writer.updateDocument( documentStructure.newQueryForChangeOrRemove(nodeId), documentStructure.newDocumentRepresentingProperty(nodeId, encodedValue)); }
LuceneIndexAccessor( LuceneDocumentStructure documentStructure, IndexWriterFactory<ReservingLuceneIndexWriter> indexWriterFactory, IndexWriterStatus writerStatus, DirectoryFactory dirFactory, File dirFile, int bufferSizeLimit) throws IOException { this.documentStructure = documentStructure; this.dirFile = dirFile; this.bufferSizeLimit = bufferSizeLimit; this.dir = dirFactory.open(dirFile); this.writer = indexWriterFactory.create(dir); this.writerStatus = writerStatus; this.searcherManager = writer.createSearcherManager(); }
private void addRecovered(long nodeId, Object value) throws IOException, IndexCapacityExceededException { IndexSearcher searcher = searcherManager.acquire(); try { TopDocs hits = searcher.search(new TermQuery(documentStructure.newQueryForChangeOrRemove(nodeId)), 1); if (hits.totalHits > 0) { Fieldable encodedValue = documentStructure.encodeAsFieldable(value); writer.updateDocument( documentStructure.newQueryForChangeOrRemove(nodeId), documentStructure.newDocumentRepresentingProperty(nodeId, encodedValue)); } else { add(nodeId, value); } } finally { searcherManager.release(searcher); } }
protected void remove(long nodeId) throws IOException { writer.deleteDocuments(documentStructure.newQueryForChangeOrRemove(nodeId)); }
protected void add(long nodeId, Object value) throws IOException, IndexCapacityExceededException { Fieldable encodedValue = documentStructure.encodeAsFieldable(value); writer.addDocument(documentStructure.newDocumentRepresentingProperty(nodeId, encodedValue)); }