Search in sources :

Example 71 with Directory

use of org.apache.lucene.store.Directory in project neo4j by neo4j.

the class LuceneSchemaIndex method isOnline.

/**
     * Check if this index is marked as online.
     *
     * @return <code>true</code> if index is online, <code>false</code> otherwise
     * @throws IOException
     */
public boolean isOnline() throws IOException {
    ensureOpen();
    AbstractIndexPartition partition = getFirstPartition(getPartitions());
    Directory directory = partition.getDirectory();
    try (DirectoryReader reader = DirectoryReader.open(directory)) {
        Map<String, String> userData = reader.getIndexCommit().getUserData();
        return ONLINE.equals(userData.get(KEY_STATUS));
    }
}
Also used : DirectoryReader(org.apache.lucene.index.DirectoryReader) AbstractIndexPartition(org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition) Directory(org.apache.lucene.store.Directory)

Example 72 with Directory

use of org.apache.lucene.store.Directory in project neo4j by neo4j.

the class AbstractLuceneIndex method addNewPartition.

/**
     * Add new partition to the index.
     *
     * @return newly created partition
     * @throws IOException
     */
AbstractIndexPartition addNewPartition() throws IOException {
    ensureOpen();
    File partitionFolder = createNewPartitionFolder();
    Directory directory = indexStorage.openDirectory(partitionFolder);
    AbstractIndexPartition indexPartition = partitionFactory.createPartition(partitionFolder, directory);
    partitions.add(indexPartition);
    return indexPartition;
}
Also used : File(java.io.File) Directory(org.apache.lucene.store.Directory) AbstractIndexPartition(org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition)

Example 73 with Directory

use of org.apache.lucene.store.Directory in project crate by crate.

the class LuceneOrderedDocCollectorTest method createLuceneIndex.

private Directory createLuceneIndex() throws IOException {
    Path tmpDir = newTempDir();
    Directory index = FSDirectory.open(tmpDir);
    StandardAnalyzer analyzer = new StandardAnalyzer();
    IndexWriterConfig cfg = new IndexWriterConfig(analyzer);
    IndexWriter w = new IndexWriter(index, cfg);
    for (Long i = 0L; i < 4; i++) {
        if (i < 2) {
            addDocToLucene(w, i + 1);
        } else {
            addDocToLucene(w, null);
        }
        w.commit();
    }
    w.close();
    return index;
}
Also used : Path(java.nio.file.Path) IndexWriter(org.apache.lucene.index.IndexWriter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 74 with Directory

use of org.apache.lucene.store.Directory in project crate by crate.

the class LuceneOrderedDocCollectorTest method testSearchAfterQueriesNullsLast.

// search after queries
@Test
public void testSearchAfterQueriesNullsLast() throws Exception {
    Directory index = createLuceneIndex();
    IndexReader reader = DirectoryReader.open(index);
    // reverseOrdering = false, nulls First = false
    // 1  2  null null
    //    ^  (lastCollected = 2)
    FieldDoc afterDoc = new FieldDoc(0, 0, new Object[] { 2L });
    Long[] result = nextPageQuery(reader, afterDoc, false, null);
    assertThat(result, is(new Long[] { 2L, null, null }));
    // reverseOrdering = false, nulls First = false
    // 1  2  null null
    //       ^
    afterDoc = new FieldDoc(0, 0, new Object[] { LuceneMissingValue.missingValue(false, null, SortField.Type.LONG) });
    result = nextPageQuery(reader, afterDoc, false, null);
    assertThat(result, is(new Long[] { null, null }));
    // reverseOrdering = true, nulls First = false
    // 2  1  null null
    //    ^
    afterDoc = new FieldDoc(0, 0, new Object[] { 1L });
    result = nextPageQuery(reader, afterDoc, true, false);
    assertThat(result, is(new Long[] { 1L, null, null }));
    // reverseOrdering = true, nulls First = false
    // 2  1  null null
    //       ^
    afterDoc = new FieldDoc(0, 0, new Object[] { LuceneMissingValue.missingValue(true, false, SortField.Type.LONG) });
    result = nextPageQuery(reader, afterDoc, true, false);
    assertThat(result, is(new Long[] { null, null }));
    reader.close();
}
Also used : IndexReader(org.apache.lucene.index.IndexReader) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 75 with Directory

use of org.apache.lucene.store.Directory in project crate by crate.

the class LuceneOrderedDocCollectorTest method testSearchAfterQueriesNullsFirst.

@Test
public void testSearchAfterQueriesNullsFirst() throws Exception {
    Directory index = createLuceneIndex();
    IndexReader reader = DirectoryReader.open(index);
    // reverseOrdering = false, nulls First = true
    // null, null, 1, 2
    //                ^  (lastCollected = 2L)
    FieldDoc afterDoc = new FieldDoc(0, 0, new Object[] { 2L });
    Long[] result = nextPageQuery(reader, afterDoc, false, true);
    assertThat(result, is(new Long[] { 2L }));
    // reverseOrdering = false, nulls First = true
    // null, null, 1, 2
    //       ^
    afterDoc = new FieldDoc(0, 0, new Object[] { LuceneMissingValue.missingValue(false, true, SortField.Type.LONG) });
    result = nextPageQuery(reader, afterDoc, false, true);
    assertThat(result, is(new Long[] { null, null, 1L, 2L }));
    // reverseOrdering = true, nulls First = true
    // null, null, 2, 1
    //                ^
    afterDoc = new FieldDoc(0, 0, new Object[] { 1L });
    result = nextPageQuery(reader, afterDoc, true, true);
    assertThat(result, is(new Long[] { 1L }));
    // reverseOrdering = true, nulls First = true
    // null, null, 2, 1
    //       ^
    afterDoc = new FieldDoc(0, 0, new Object[] { LuceneMissingValue.missingValue(true, true, SortField.Type.LONG) });
    result = nextPageQuery(reader, afterDoc, true, true);
    assertThat(result, is(new Long[] { null, null, 2L, 1L }));
    reader.close();
}
Also used : IndexReader(org.apache.lucene.index.IndexReader) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Aggregations

Directory (org.apache.lucene.store.Directory)2194 Document (org.apache.lucene.document.Document)1374 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)816 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)669 IndexReader (org.apache.lucene.index.IndexReader)590 IndexSearcher (org.apache.lucene.search.IndexSearcher)383 BytesRef (org.apache.lucene.util.BytesRef)376 RAMDirectory (org.apache.lucene.store.RAMDirectory)360 Term (org.apache.lucene.index.Term)325 StringField (org.apache.lucene.document.StringField)313 IndexWriter (org.apache.lucene.index.IndexWriter)312 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)274 TextField (org.apache.lucene.document.TextField)259 Field (org.apache.lucene.document.Field)257 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)257 Test (org.junit.Test)237 FSDirectory (org.apache.lucene.store.FSDirectory)221 Analyzer (org.apache.lucene.analysis.Analyzer)193 DirectoryReader (org.apache.lucene.index.DirectoryReader)193 TopDocs (org.apache.lucene.search.TopDocs)174