Search in sources :

Example 66 with IndexWriter

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());
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) Config(org.neo4j.kernel.configuration.Config) Test(org.junit.Test)

Example 67 with IndexWriter

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);
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 68 with IndexWriter

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);
        }
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException) RAMDirectory(org.apache.lucene.store.RAMDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 69 with IndexWriter

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));
}
Also used : Bitmap(org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap) WritableDatabaseLabelScanIndex(org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex) IndexWriter(org.apache.lucene.index.IndexWriter) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) Document(org.apache.lucene.document.Document) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) Test(org.junit.Test)

Example 70 with IndexWriter

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))));
}
Also used : WritableDatabaseLabelScanIndex(org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex) IndexWriter(org.apache.lucene.index.IndexWriter) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) Document(org.apache.lucene.document.Document) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) Test(org.junit.Test)

Aggregations

IndexWriter (org.apache.lucene.index.IndexWriter)529 Document (org.apache.lucene.document.Document)311 Directory (org.apache.lucene.store.Directory)306 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)293 IndexReader (org.apache.lucene.index.IndexReader)144 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)136 DirectoryReader (org.apache.lucene.index.DirectoryReader)127 Term (org.apache.lucene.index.Term)125 IndexSearcher (org.apache.lucene.search.IndexSearcher)110 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)107 TextField (org.apache.lucene.document.TextField)104 RAMDirectory (org.apache.lucene.store.RAMDirectory)88 IOException (java.io.IOException)86 Field (org.apache.lucene.document.Field)86 TermQuery (org.apache.lucene.search.TermQuery)56 StringField (org.apache.lucene.document.StringField)52 BytesRef (org.apache.lucene.util.BytesRef)52 FieldType (org.apache.lucene.document.FieldType)50 Test (org.junit.Test)49 Query (org.apache.lucene.search.Query)45