use of org.apache.lucene.index.IndexWriter in project neo4j by neo4j.
the class LuceneDataSourceTest method testClosesOldestIndexWriterWhenCacheSizeIsExceeded.
@Test
public void testClosesOldestIndexWriterWhenCacheSizeIsExceeded() throws Throwable {
addIndex("bar");
addIndex("baz");
Config config = Config.embeddedDefaults(cacheSizeConfig());
dataSource = life.add(new LuceneDataSource(directory.graphDbDir(), config, indexStore, fileSystemRule.get()));
IndexIdentifier fooIdentifier = identifier("foo");
IndexIdentifier barIdentifier = identifier("bar");
IndexIdentifier bazIdentifier = identifier("baz");
IndexWriter fooIndexWriter = dataSource.getIndexSearcher(fooIdentifier).getWriter();
dataSource.getIndexSearcher(barIdentifier);
assertTrue(fooIndexWriter.isOpen());
dataSource.getIndexSearcher(bazIdentifier);
assertFalse(fooIndexWriter.isOpen());
}
use of org.apache.lucene.index.IndexWriter in project neo4j-mobile-android by neo4j-contrib.
the class LuceneBatchInserterIndex method instantiateWriter.
private IndexWriter instantiateWriter(String directory) {
try {
IndexWriterConfig writerConfig = new IndexWriterConfig(LUCENE_VERSION, type.analyzer);
writerConfig.setRAMBufferSizeMB(determineGoodBufferSize(writerConfig.getRAMBufferSizeMB()));
IndexWriter writer = new IndexWriter(getDirectory(directory, identifier), writerConfig);
return writer;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.apache.lucene.index.IndexWriter in project neo4j-mobile-android by neo4j-contrib.
the class FullTxData method ensureLuceneDataInstantiated.
private void ensureLuceneDataInstantiated() {
if (this.directory == null) {
try {
this.directory = new RAMDirectory();
IndexWriterConfig writerConfig = new IndexWriterConfig(LUCENE_VERSION, index.type.analyzer);
this.writer = new IndexWriter(directory, writerConfig);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
use of org.apache.lucene.index.IndexWriter in project neo4j by neo4j.
the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldUpdateDocumentsForReLabeledNodes.
@Test
public void shouldUpdateDocumentsForReLabeledNodes() throws Exception {
// given
Document givenDoc = new Document();
format.addRangeValuesField(givenDoc, 0);
format.addLabelFields(givenDoc, "7", 0x70L);
WritableDatabaseLabelScanIndex index = mock(WritableDatabaseLabelScanIndex.class);
IndexWriter indexWriter = mock(IndexWriter.class);
WritableIndexPartition partition = newIndexPartitionMock(indexWriter, givenDoc);
when(index.getPartitions()).thenReturn(Collections.singletonList(partition));
LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
// when
writer.write(labelChanges(0, labels(), labels(7, 8)));
writer.close();
// then
Document thenDoc = new Document();
format.addRangeValuesField(thenDoc, 0);
format.addLabelFields(thenDoc, "7", 0x71L);
format.addLabelAndSearchFields(thenDoc, 8, new Bitmap(0x01L));
verify(indexWriter).updateDocument(eq(format.rangeTerm(0)), match(thenDoc));
}
use of org.apache.lucene.index.IndexWriter in project neo4j by neo4j.
the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldUpdateDocumentToReflectLabelsAfterRegardlessOfPreviousContent.
@Test
public void shouldUpdateDocumentToReflectLabelsAfterRegardlessOfPreviousContent() throws Exception {
// given
IndexWriter indexWriter = mock(IndexWriter.class);
Document doc = document(format.rangeField(0), format.labelField(6, 0x1), format.labelField(7, 0x1));
WritableIndexPartition partition = newIndexPartitionMock(indexWriter, doc);
WritableDatabaseLabelScanIndex index = buildLuceneIndex(partition);
LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
// when
writer.write(labelChanges(0, labels(7), labels(7, 8)));
writer.close();
// then
verify(indexWriter).updateDocument(eq(format.rangeTerm(0)), match(document(format.rangeField(0), format.labelField(7, 0x01), format.labelField(8, 0x01), format.labelSearchField(7), format.labelSearchField(8))));
}
Aggregations