Search in sources :

Example 81 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project jforum2 by rafaelsteil.

the class LuceneSettings method useRAMDirectory.

public void useRAMDirectory() throws Exception {
    this.directory = new RAMDirectory();
    IndexWriter writer = new IndexWriter(this.directory, this.analyzer, true);
    writer.close();
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) RAMDirectory(org.apache.lucene.store.RAMDirectory)

Example 82 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project jforum2 by rafaelsteil.

the class LuceneSettings method createIndexDirectory.

public void createIndexDirectory(String directoryPath) throws IOException {
    FSDirectory fsDir = FSDirectory.getDirectory(directoryPath);
    IndexWriter writer = new IndexWriter(fsDir, this.analyzer, true);
    writer.close();
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 83 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project languagetool by languagetool-org.

the class LuceneSimpleIndexCreator method main.

public static void main(String[] args) throws IOException {
    IndexWriterConfig conf = new IndexWriterConfig(new KeywordAnalyzer());
    try (IndexWriter iw1 = new IndexWriter(FSDirectory.open(new File("/tmp/1grams").toPath()), conf)) {
        addDoc(iw1, "the", 55);
        addDoc(iw1, "nice", 10);
        addDoc(iw1, "building", 1);
        Document document = new Document();
        document.add(new TextField("totalTokenCount", String.valueOf(3), Field.Store.YES));
        iw1.addDocument(document);
    }
    IndexWriterConfig conf2 = new IndexWriterConfig(new KeywordAnalyzer());
    try (IndexWriter iw2 = new IndexWriter(FSDirectory.open(new File("/tmp/2grams").toPath()), conf2)) {
        addDoc(iw2, "the nice", 3);
        addDoc(iw2, "nice building", 2);
    }
    IndexWriterConfig conf3 = new IndexWriterConfig(new KeywordAnalyzer());
    try (IndexWriter iw3 = new IndexWriter(FSDirectory.open(new File("/tmp/3grams").toPath()), conf3)) {
        addDoc(iw3, "the nice building", 1);
    }
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) IndexWriter(org.apache.lucene.index.IndexWriter) TextField(org.apache.lucene.document.TextField) Document(org.apache.lucene.document.Document) File(java.io.File) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 84 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project lucene-skos by behas.

the class SKOSLabelFilterTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    skosAnalyzer = new SKOSAnalyzer(skosEngine, SKOSAnalyzer.ExpansionType.LABEL);
    writer = new IndexWriter(directory, new IndexWriterConfig(skosAnalyzer));
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) SKOSAnalyzer(at.ac.univie.mminf.luceneSKOS.analysis.SKOSAnalyzer) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 85 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project lucene-skos by behas.

the class SKOSURIFilterTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    skosAnalyzer = new SKOSAnalyzer(skosEngine, ExpansionType.URI);
    writer = new IndexWriter(directory, new IndexWriterConfig(skosAnalyzer));
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) SKOSAnalyzer(at.ac.univie.mminf.luceneSKOS.analysis.SKOSAnalyzer) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

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