use of org.apache.lucene.index.IndexWriter in project languagetool by languagetool-org.
the class PatternRuleQueryBuilderTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
language = new English();
directory = new RAMDirectory();
/*File indexPath = new File("/tmp/lucene");
if (indexPath.exists()) {
FileUtils.deleteDirectory(indexPath);
}
directory = FSDirectory.open(indexPath);*/
Analyzer analyzer = Indexer.getAnalyzer(language);
IndexWriterConfig config = Indexer.getIndexWriterConfig(analyzer);
try (IndexWriter writer = new IndexWriter(directory, config)) {
addDocument(writer, "How do you thin about this wonderful idea?");
addDocument(writer, "The are several grammar checkers for English, E.G. LanguageTool 123.");
}
reader = DirectoryReader.open(directory);
searcher = newSearcher(reader);
}
use of org.apache.lucene.index.IndexWriter in project neo4j by neo4j.
the class LuceneSchemaIndex method markAsOnline.
/**
* Marks index as online by including "status" -> "online" map into commit metadata of the first partition.
*
* @throws IOException
*/
public void markAsOnline() throws IOException {
ensureOpen();
AbstractIndexPartition partition = getFirstPartition(getPartitions());
IndexWriter indexWriter = partition.getIndexWriter();
indexWriter.setCommitData(ONLINE_COMMIT_USER_DATA);
flush(false);
}
use of org.apache.lucene.index.IndexWriter in project neo4j by neo4j.
the class WritableIndexReferenceFactory method refresh.
/**
* If nothing has changed underneath (since the searcher was last created
* or refreshed) {@code searcher} is returned. But if something has changed a
* refreshed searcher is returned. It makes use if the
* {@link DirectoryReader#openIfChanged(DirectoryReader, IndexWriter, boolean)} which faster than opening an index
* from
* scratch.
*
* @param indexReference the {@link IndexReference} to refresh.
* @return a refreshed version of the searcher or, if nothing has changed,
* {@code null}.
* @throws RuntimeException if there's a problem with the index.
*/
@Override
IndexReference refresh(IndexReference indexReference) {
try {
DirectoryReader reader = (DirectoryReader) indexReference.getSearcher().getIndexReader();
IndexWriter writer = indexReference.getWriter();
IndexReader reopened = DirectoryReader.openIfChanged(reader, writer);
if (reopened != null) {
IndexSearcher newSearcher = newIndexSearcher(indexReference.getIdentifier(), reopened);
indexReference.detachOrClose();
return new WritableIndexReference(indexReference.getIdentifier(), newSearcher, writer);
}
return indexReference;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.apache.lucene.index.IndexWriter in project neo4j by neo4j.
the class AbstractLuceneIndex method flush.
/**
* Commits all index partitions.
*
* @param merge also merge all segments together. This should be done before reading term frequencies.
* @throws IOException on Lucene I/O error.
*/
public void flush(boolean merge) throws IOException {
List<AbstractIndexPartition> partitions = getPartitions();
for (AbstractIndexPartition partition : partitions) {
IndexWriter writer = partition.getIndexWriter();
writer.commit();
if (merge) {
writer.forceMerge(1);
}
}
}
use of org.apache.lucene.index.IndexWriter in project neo4j by neo4j.
the class LuceneDataSourceTest method testShouldReturnIndexWriterFromLRUCache.
@Test
public void testShouldReturnIndexWriterFromLRUCache() throws Throwable {
Config config = Config.embeddedDefaults();
dataSource = life.add(new LuceneDataSource(directory.graphDbDir(), config, indexStore, fileSystemRule.get()));
IndexIdentifier identifier = identifier("foo");
IndexWriter writer = dataSource.getIndexSearcher(identifier).getWriter();
assertSame(writer, dataSource.getIndexSearcher(identifier).getWriter());
}
Aggregations