use of org.apache.lucene.index.IndexWriter in project jackrabbit-oak by apache.
the class IndexPlannerTest method createSampleDirectory.
private static Directory createSampleDirectory(long numOfDocs) throws IOException {
Directory dir = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(VERSION, LuceneIndexConstants.ANALYZER);
IndexWriter writer = new IndexWriter(dir, config);
for (int i = 0; i < numOfDocs; i++) {
Document doc = new Document();
doc.add(new StringField("foo", "bar" + i, Field.Store.NO));
writer.addDocument(doc);
}
writer.close();
return dir;
}
use of org.apache.lucene.index.IndexWriter in project jackrabbit-oak by apache.
the class NRTIndex method createWriter.
private synchronized NRTIndexWriter createWriter() throws IOException {
String dirName = generateDirName();
indexDir = indexCopier.getIndexDir(definition, definition.getIndexPath(), dirName);
Directory fsdir = FSDirectory.open(indexDir);
//TODO make these configurable
directory = new NRTCachingDirectory(fsdir, 1, 1);
IndexWriterConfig config = IndexWriterUtils.getIndexWriterConfig(definition, false);
//TODO Explore following for optimizing indexing speed
//config.setUseCompoundFile(false);
//config.setRAMBufferSizeMB(1024*1024*25);
indexWriter = new IndexWriter(directory, config);
return new NRTIndexWriter(indexWriter);
}
use of org.apache.lucene.index.IndexWriter in project jena by apache.
the class TextSearchUtil method createEmptyIndex.
public static void createEmptyIndex(File indexDir) {
try {
Directory directory = FSDirectory.open(indexDir.toPath());
IndexWriterConfig wConfig = new IndexWriterConfig(analyzer);
// force creation of the index files
try (IndexWriter indexWriter = new IndexWriter(directory, wConfig)) {
}
} catch (IOException ex) {
IO.exception(ex);
}
}
use of org.apache.lucene.index.IndexWriter in project jena by apache.
the class SpatialSearchUtil method createEmptyIndex.
public static void createEmptyIndex(File indexDir) {
try {
Directory directory = FSDirectory.open(indexDir.toPath());
IndexWriterConfig wConfig = new IndexWriterConfig(analyzer);
// force creation of the index files
try (IndexWriter indexWriter = new IndexWriter(directory, wConfig)) {
}
} catch (IOException ex) {
IO.exception(ex);
}
}
use of org.apache.lucene.index.IndexWriter in project lucene-solr by apache.
the class TestLimitTokenCountAnalyzer method testLimitTokenCountIndexWriter.
public void testLimitTokenCountIndexWriter() throws IOException {
for (boolean consumeAll : new boolean[] { true, false }) {
Directory dir = newDirectory();
int limit = TestUtil.nextInt(random(), 50, 101000);
MockAnalyzer mock = new MockAnalyzer(random());
// if we are consuming all tokens, we can use the checks,
// otherwise we can't
mock.setEnableChecks(consumeAll);
Analyzer a = new LimitTokenCountAnalyzer(mock, limit, consumeAll);
IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(a));
Document doc = new Document();
StringBuilder b = new StringBuilder();
for (int i = 1; i < limit; i++) b.append(" a");
b.append(" x");
b.append(" z");
doc.add(newTextField("field", b.toString(), Field.Store.NO));
writer.addDocument(doc);
writer.close();
IndexReader reader = DirectoryReader.open(dir);
Term t = new Term("field", "x");
assertEquals(1, reader.docFreq(t));
t = new Term("field", "z");
assertEquals(0, reader.docFreq(t));
reader.close();
dir.close();
a.close();
}
}
Aggregations