Search in sources :

Example 76 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project neo4j by neo4j.

the class FullTxData method ensureLuceneDataInstantiated.

private void ensureLuceneDataInstantiated() {
    if (this.directory == null) {
        try {
            this.directory = new RAMDirectory();
            IndexWriterConfig writerConfig = new IndexWriterConfig(index.type.analyzer);
            this.writer = new IndexWriter(directory, writerConfig);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException) RAMDirectory(org.apache.lucene.store.RAMDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 77 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project orientdb by orientechnologies.

the class OLuceneStorage method reOpen.

private void reOpen() throws IOException {
    if (mgrWriter != null) {
        OLogManager.instance().info(this, "index storage is open don't reopen");
        return;
    }
    ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.INSTANCE.get();
    final OAbstractPaginatedStorage storageLocalAbstract = (OAbstractPaginatedStorage) database.getStorage().getUnderlying();
    Directory dir = null;
    if (storageLocalAbstract instanceof OLocalPaginatedStorage) {
        String pathname = getIndexPath((OLocalPaginatedStorage) storageLocalAbstract);
        OLogManager.instance().info(this, "Opening NIOFS Lucene db=%s, path=%s", database.getName(), pathname);
        dir = NIOFSDirectory.open(new File(pathname).toPath());
    } else {
        OLogManager.instance().info(this, "Opening RAM Lucene index db=%s", database.getName());
        dir = new RAMDirectory();
    }
    final IndexWriter indexWriter = createIndexWriter(dir);
    mgrWriter = new TrackingIndexWriter(indexWriter);
    searcherManager = new SearcherManager(indexWriter, true, null);
    if (nrt != null) {
        nrt.close();
    }
    nrt = new ControlledRealTimeReopenThread(mgrWriter, searcherManager, 60.00, 0.1);
    nrt.setDaemon(true);
    nrt.start();
    flush();
    OLogManager.instance().info(this, "REOPEN DONE");
}
Also used : ControlledRealTimeReopenThread(org.apache.lucene.search.ControlledRealTimeReopenThread) TrackingIndexWriter(org.apache.lucene.index.TrackingIndexWriter) IndexWriter(org.apache.lucene.index.IndexWriter) TrackingIndexWriter(org.apache.lucene.index.TrackingIndexWriter) OLocalPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage) SearcherManager(org.apache.lucene.search.SearcherManager) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) File(java.io.File) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) RAMDirectory(org.apache.lucene.store.RAMDirectory) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory)

Example 78 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project querydsl by querydsl.

the class LuceneSerializerNotTokenizedTest method before.

@Before
public void before() throws Exception {
    serializer = new LuceneSerializer(false, false);
    idx = new RAMDirectory();
    IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_30)).setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    writer = new IndexWriter(idx, config);
    writer.addDocument(createDocument(clooney));
    writer.addDocument(createDocument(pitt));
    Document document = new Document();
    for (String movie : Arrays.asList("Interview with the Vampire", "Up in the Air")) {
        document.add(new Field("movie", movie, Store.YES, Index.NOT_ANALYZED));
    }
    writer.addDocument(document);
    writer.close();
    IndexReader reader = IndexReader.open(idx);
    searcher = new IndexSearcher(reader);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Field(org.apache.lucene.document.Field) IndexWriter(org.apache.lucene.index.IndexWriter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) IndexReader(org.apache.lucene.index.IndexReader) Document(org.apache.lucene.document.Document) RAMDirectory(org.apache.lucene.store.RAMDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 79 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project querydsl by querydsl.

the class LuceneSerializerNotTokenizedTest method before.

@Before
public void before() throws Exception {
    serializer = new LuceneSerializer(false, false);
    idx = new RAMDirectory();
    IndexWriterConfig config = new IndexWriterConfig(new StandardAnalyzer()).setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    writer = new IndexWriter(idx, config);
    writer.addDocument(createDocument(clooney));
    writer.addDocument(createDocument(pitt));
    Document document = new Document();
    for (String movie : Arrays.asList("Interview with the Vampire", "Up in the Air")) {
        document.add(new Field("movie", movie, Store.YES, Index.NOT_ANALYZED));
    }
    writer.addDocument(document);
    writer.close();
    IndexReader reader = DirectoryReader.open(idx);
    searcher = new IndexSearcher(reader);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Field(org.apache.lucene.document.Field) IndexWriter(org.apache.lucene.index.IndexWriter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) IndexReader(org.apache.lucene.index.IndexReader) Document(org.apache.lucene.document.Document) RAMDirectory(org.apache.lucene.store.RAMDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 80 with IndexWriter

use of org.apache.lucene.index.IndexWriter in project querydsl by querydsl.

the class LuceneSerializerTest method setUp.

@Before
public void setUp() throws Exception {
    serializer = new LuceneSerializer(true, true);
    entityPath = new PathBuilder<Object>(Object.class, "obj");
    title = entityPath.getString("title");
    author = entityPath.getString("author");
    text = entityPath.getString("text");
    publisher = entityPath.getString("publisher");
    year = entityPath.getNumber("year", Integer.class);
    rating = entityPath.getString("rating");
    gross = entityPath.getNumber("gross", Double.class);
    titles = entityPath.getCollection("title", String.class, StringPath.class);
    longField = entityPath.getNumber("longField", Long.class);
    shortField = entityPath.getNumber("shortField", Short.class);
    byteField = entityPath.getNumber("byteField", Byte.class);
    floatField = entityPath.getNumber("floatField", Float.class);
    idx = new RAMDirectory();
    config = new IndexWriterConfig(Version.LUCENE_42, new StandardAnalyzer(Version.LUCENE_42)).setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    writer = new IndexWriter(idx, config);
    writer.addDocument(createDocument());
    writer.close();
    IndexReader reader = IndexReader.open(idx);
    searcher = new IndexSearcher(reader);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) RAMDirectory(org.apache.lucene.store.RAMDirectory) IndexWriter(org.apache.lucene.index.IndexWriter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) IndexReader(org.apache.lucene.index.IndexReader) 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