Search in sources :

Example 96 with IndexWriter

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;
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) StringField(org.apache.lucene.document.StringField) Document(org.apache.lucene.document.Document) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 97 with IndexWriter

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);
}
Also used : LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) IndexWriter(org.apache.lucene.index.IndexWriter) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) NRTCachingDirectory(org.apache.lucene.store.NRTCachingDirectory) NRTCachingDirectory(org.apache.lucene.store.NRTCachingDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 98 with 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);
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 99 with IndexWriter

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);
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 100 with IndexWriter

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();
    }
}
Also used : MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) IndexWriter(org.apache.lucene.index.IndexWriter) IndexReader(org.apache.lucene.index.IndexReader) Term(org.apache.lucene.index.Term) Analyzer(org.apache.lucene.analysis.Analyzer) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) Document(org.apache.lucene.document.Document) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

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