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));
}
}
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;
}
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;
}
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();
}
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();
}
Aggregations