Search in sources :

Example 71 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project neo4j by neo4j.

the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldDeleteEmptyDocuments.

@Test
public void shouldDeleteEmptyDocuments() throws Exception {
    // given
    IndexWriter indexWriter = mock(IndexWriter.class);
    Document doc = document(format.rangeField(0), 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()));
    writer.close();
    // then
    verify(indexWriter).deleteDocuments(format.rangeTerm(0));
}
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)

Example 72 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project neo4j by neo4j.

the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldCreateNewDocumentsForNewlyLabeledNodes.

@Test
public void shouldCreateNewDocumentsForNewlyLabeledNodes() throws Exception {
    // given
    WritableIndexPartition partition = mock(WritableIndexPartition.class);
    WritableDatabaseLabelScanIndex index = buildLuceneIndex(partition);
    PartitionSearcher partitionSearcher = mock(PartitionSearcher.class);
    when(partition.acquireSearcher()).thenReturn(partitionSearcher);
    IndexWriter indexWriter = mock(IndexWriter.class);
    when(partition.getIndexWriter()).thenReturn(indexWriter);
    IndexSearcher searcher = mock(IndexSearcher.class);
    when(partitionSearcher.getIndexSearcher()).thenReturn(searcher);
    when(searcher.search(new TermQuery(format.rangeTerm(0)), 1)).thenReturn(emptyTopDocs());
    when(searcher.search(new TermQuery(format.rangeTerm(1)), 1)).thenReturn(null);
    LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
    // when
    writer.write(labelChanges(0, labels(), labels(6, 7)));
    writer.write(labelChanges(1, labels(), labels(6, 8)));
    writer.write(labelChanges(1 << format.bitmapFormat().shift, labels(), labels(7)));
    writer.close();
    // then
    verify(partition, times(2)).acquireSearcher();
    verify(partitionSearcher, times(2)).getIndexSearcher();
    verify(partition, times(2)).getIndexWriter();
    verify(partitionSearcher, times(2)).close();
    verify(indexWriter).updateDocument(eq(format.rangeTerm(0)), match(document(format.rangeField(0), format.labelField(6, 0x3), format.labelField(7, 0x1), format.labelField(8, 0x2), format.labelSearchField(8))));
    verify(indexWriter).updateDocument(eq(format.rangeTerm(1)), match(document(format.rangeField(1), format.labelField(7, 0x1), format.labelSearchField(7))));
    verify(index).maybeRefreshBlocking();
    verifyNoMoreInteractions(partition);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TermQuery(org.apache.lucene.search.TermQuery) WritableDatabaseLabelScanIndex(org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex) PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher) IndexWriter(org.apache.lucene.index.IndexWriter) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) Test(org.junit.Test)

Example 73 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project neo4j by neo4j.

the class SimpleUniquenessVerifierTest method initLuceneResources.

@Before
public void initLuceneResources() throws Exception {
    dirFactory = new DirectoryFactory.InMemoryDirectoryFactory();
    Directory dir = dirFactory.open(testDir.directory("test"));
    writer = new IndexWriter(dir, IndexWriterConfigs.standard());
    searcherManager = new SearcherManager(writer, true, new SearcherFactory());
}
Also used : SearcherFactory(org.apache.lucene.search.SearcherFactory) IndexWriter(org.apache.lucene.index.IndexWriter) DirectoryFactory(org.neo4j.kernel.api.impl.index.storage.DirectoryFactory) SearcherManager(org.apache.lucene.search.SearcherManager) Directory(org.apache.lucene.store.Directory) TestDirectory(org.neo4j.test.rule.TestDirectory) Before(org.junit.Before)

Example 74 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project graphdb by neo4j-attic.

the class FullTxData method ensureLuceneDataInstantiated.

private void ensureLuceneDataInstantiated() {
    if (this.directory == null) {
        try {
            this.directory = new RAMDirectory();
            this.writer = new IndexWriter(directory, index.type.analyzer, MaxFieldLength.UNLIMITED);
        } 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)

Example 75 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project graphdb by neo4j-attic.

the class LuceneBatchInserterIndex method instantiateWriter.

private IndexWriter instantiateWriter(String directory) {
    try {
        IndexWriter writer = new IndexWriter(LuceneDataSource.getDirectory(directory, identifier), type.analyzer, MaxFieldLength.UNLIMITED);
        writer.setRAMBufferSizeMB(determineGoodBufferSize(writer.getRAMBufferSizeMB()));
        return writer;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException)

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