Example usage for org.apache.lucene.index IndexWriterConfig getAnalyzer

List of usage examples for org.apache.lucene.index IndexWriterConfig getAnalyzer

Introduction

In this page you can find the example usage for org.apache.lucene.index IndexWriterConfig getAnalyzer.

Prototype

@Override
    public Analyzer getAnalyzer() 

Source Link

Usage

From source file:com.mathworks.xzheng.admin.ThreadedIndexWriter.java

License:Apache License

public ThreadedIndexWriter(Directory dir, IndexWriterConfig config, int numThreads, int maxQueueSize)
        throws CorruptIndexException, IOException {
    super(dir, config);
    defaultAnalyzer = config.getAnalyzer();
    threadPool = new ThreadPoolExecutor( //C
            numThreads, numThreads, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(maxQueueSize, false),
            new ThreadPoolExecutor.CallerRunsPolicy());
}

From source file:io.datalayer.lucene.benchmark.ThreadedIndexWriter.java

License:Apache License

public ThreadedIndexWriter(Directory dir, IndexWriterConfig conf, boolean create, int numThreads,
        int maxQueueSize) throws CorruptIndexException, IOException {
    super(dir, conf);
    defaultAnalyzer = conf.getAnalyzer();
    threadPool = new ThreadPoolExecutor(numThreads, numThreads, 0, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(maxQueueSize, false), new ThreadPoolExecutor.CallerRunsPolicy());
}

From source file:net.sf.lucis.core.impl.DefaultWriter.java

License:Apache License

public <T, P> IndexStatus write(Store<T> store, Batch<T, P> batch) throws InterruptedException {
    Preconditions.checkNotNull(store, "A destination store must be provided.");
    if (batch == null) {
        return null;
    }/*from w  w w.j a v  a2  s . c  o  m*/
    try {
        final IndexWriterConfig config = config();
        final T oldCP = store.getCheckpoint();
        final T newCP = batch.getCheckpoint();
        if (Objects.equal(oldCP, newCP)) {
            return null;
        }
        throwIfInterrupted();
        if (!batch.isEmpty()) {
            final Analyzer analyzer = config.getAnalyzer();
            // Check whether the index must be created
            final Directory directory = store.getDirectory();
            config.setOpenMode(batch.isRecreate() ? OpenMode.CREATE : OpenMode.CREATE_OR_APPEND);
            final IndexWriter writer = new IndexWriter(directory, config);
            boolean ok = false;
            try {
                // Deletions
                if (!batch.isRecreate()) {
                    for (Term term : batch.getDeletions()) {
                        throwIfInterrupted();
                        writer.deleteDocuments(term);
                    }
                }
                // Additions
                for (Addition addition : batch.getAdditions()) {
                    throwIfInterrupted();
                    final Analyzer aa = addition.getAnalyzer();
                    writer.addDocument(addition.getDocument(), aa != null ? aa : analyzer);
                }
                // Commit
                throwIfInterrupted();
                writer.commit();
                ok = true;
                // No optimize until policy is defined.
                // writer.optimize();
            } finally {
                if (!ok) {
                    rollback(writer);
                }
                writer.close();
            }
        }
        store.setCheckpoint(newCP);
        return IndexStatus.OK;
    } catch (InterruptedException ie) {
        throw ie;
    } catch (LockObtainFailedException le) {
        log().error(le, "Unable to lock index");
        return IndexStatus.LOCKED;
    } catch (CorruptIndexException ce) {
        log().error(ce, "Corrupt index");
        return IndexStatus.CORRUPT;
    } catch (IOException ioe) {
        log().error(ioe, "I/O Error while writing");
        return IndexStatus.IOERROR;
    } catch (Exception e) {
        log().error(e, "Exception while writing");
        return IndexStatus.ERROR;
    }
}

From source file:org.elasticsearch.index.engine.EngineTestCase.java

License:Apache License

public EngineConfig config(IndexSettings indexSettings, Store store, Path translogPath, MergePolicy mergePolicy,
        ReferenceManager.RefreshListener refreshListener, Sort indexSort,
        LongSupplier globalCheckpointSupplier) {
    IndexWriterConfig iwc = newIndexWriterConfig();
    TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, indexSettings,
            BigArrays.NON_RECYCLING_INSTANCE);
    Engine.EventListener listener = new Engine.EventListener() {
        @Override/*from  w ww .  j  a v a2 s  . co  m*/
        public void onFailedEngine(String reason, @Nullable Exception e) {
            // we don't need to notify anybody in this test
        }
    };
    final TranslogHandler handler = new TranslogHandler(xContentRegistry(),
            IndexSettingsModule.newIndexSettings(shardId.getIndexName(), indexSettings.getSettings()));
    final List<ReferenceManager.RefreshListener> refreshListenerList = refreshListener == null ? emptyList()
            : Collections.singletonList(refreshListener);
    EngineConfig config = new EngineConfig(shardId, allocationId.getId(), threadPool, indexSettings, null,
            store, mergePolicy, iwc.getAnalyzer(), iwc.getSimilarity(), new CodecService(null, logger),
            listener, IndexSearcher.getDefaultQueryCache(), IndexSearcher.getDefaultQueryCachingPolicy(),
            translogConfig, TimeValue.timeValueMinutes(5), refreshListenerList, Collections.emptyList(),
            indexSort, handler, new NoneCircuitBreakerService(),
            globalCheckpointSupplier == null
                    ? new ReplicationTracker(shardId, allocationId.getId(), indexSettings,
                            SequenceNumbers.NO_OPS_PERFORMED)
                    : globalCheckpointSupplier);
    return config;
}

From source file:org.elasticsearch.index.engine.InternalEngineTests.java

License:Apache License

public EngineConfig config(Settings indexSettings, Store store, Path translogPath,
        MergeSchedulerConfig mergeSchedulerConfig, MergePolicy mergePolicy, IndexSearcherWrapper... wrappers) {
    IndexWriterConfig iwc = newIndexWriterConfig();
    TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, indexSettings,
            Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool);

    EngineConfig config = new EngineConfig(shardId, threadPool,
            new ShardIndexingService(shardId, indexSettings), indexSettings, null, store,
            createSnapshotDeletionPolicy(), mergePolicy, mergeSchedulerConfig, iwc.getAnalyzer(),
            iwc.getSimilarity(), new CodecService(shardId.index()), new Engine.FailedEngineListener() {
                @Override/* w w w . j a  va 2s .  c o  m*/
                public void onFailedEngine(ShardId shardId, String reason, @Nullable Throwable t) {
                    // we don't need to notify anybody in this test
                }
            }, new TranslogHandler(shardId.index().getName(), logger), IndexSearcher.getDefaultQueryCache(),
            IndexSearcher.getDefaultQueryCachingPolicy(),
            new IndexSearcherWrappingService(new HashSet<>(Arrays.asList(wrappers))), translogConfig);
    try {
        config.setCreate(Lucene.indexExists(store.directory()) == false);
    } catch (IOException e) {
        throw new ElasticsearchException("can't find index?", e);
    }
    return config;
}

From source file:org.elasticsearch.index.engine.ShadowEngineTests.java

License:Apache License

public EngineConfig config(IndexSettingsService indexSettingsService, Store store, Translog translog,
        MergeSchedulerProvider mergeSchedulerProvider) {
    IndexWriterConfig iwc = newIndexWriterConfig(Lucene.STANDARD_ANALYZER);
    EngineConfig config = new EngineConfig(shardId,
            false/*per default optimization for auto generated ids is disabled*/, threadPool,
            new ShardIndexingService(shardId, EMPTY_SETTINGS,
                    new ShardSlowLogIndexingService(shardId, EMPTY_SETTINGS, indexSettingsService)),
            indexSettingsService, null, store, createSnapshotDeletionPolicy(), translog, createMergePolicy(),
            mergeSchedulerProvider, iwc.getAnalyzer(), iwc.getSimilarity(), new CodecService(shardId.index()),
            new Engine.FailedEngineListener() {
                @Override//from w ww.  j  ava 2 s . c o m
                public void onFailedEngine(ShardId shardId, String reason, @Nullable Throwable t) {
                    // we don't need to notify anybody in this test
                }
            });

    return config;
}

From source file:org.elasticsearch.index.shard.RefreshListenersTests.java

License:Apache License

@Before
public void setupListeners() throws Exception {
    // Setup dependencies of the listeners
    maxListeners = randomIntBetween(1, 1000);
    listeners = new RefreshListeners(() -> maxListeners, () -> engine.refresh("too-many-listeners"),
            // Immediately run listeners rather than adding them to the listener thread pool like IndexShard does to simplify the test.
            Runnable::run, logger);

    // Now setup the InternalEngine which is much more complicated because we aren't mocking anything
    threadPool = new TestThreadPool(getTestName());
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("index", Settings.EMPTY);
    ShardId shardId = new ShardId(new Index("index", "_na_"), 1);
    Directory directory = newDirectory();
    DirectoryService directoryService = new DirectoryService(shardId, indexSettings) {
        @Override/*from   w ww.  j a  v  a2 s  .co  m*/
        public Directory newDirectory() throws IOException {
            return directory;
        }

        @Override
        public long throttleTimeInNanos() {
            return 0;
        }
    };
    store = new Store(shardId, indexSettings, directoryService, new DummyShardLock(shardId));
    IndexWriterConfig iwc = newIndexWriterConfig();
    TranslogConfig translogConfig = new TranslogConfig(shardId, createTempDir("translog"), indexSettings,
            BigArrays.NON_RECYCLING_INSTANCE);
    Engine.EventListener eventListener = new Engine.EventListener() {
        @Override
        public void onFailedEngine(String reason, @Nullable Exception e) {
            // we don't need to notify anybody in this test
        }
    };
    EngineConfig config = new EngineConfig(EngineConfig.OpenMode.CREATE_INDEX_AND_TRANSLOG, shardId, threadPool,
            indexSettings, null, store, new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy()),
            newMergePolicy(), iwc.getAnalyzer(), iwc.getSimilarity(), new CodecService(null, logger),
            eventListener, new TranslogHandler(shardId.getIndexName(), logger),
            IndexSearcher.getDefaultQueryCache(), IndexSearcher.getDefaultQueryCachingPolicy(), translogConfig,
            TimeValue.timeValueMinutes(5), listeners);
    engine = new InternalEngine(config);
}

From source file:org.musicbrainz.search.index.ThreadedIndexWriter.java

License:Open Source License

public ThreadedIndexWriter(Directory dir, IndexWriterConfig config, int numThreads, int maxQueueSize)

        throws IOException

{
    super(dir, config);
    defaultAnalyzer = config.getAnalyzer();
    threadPool = new ThreadPoolExecutor(numThreads, numThreads, 0, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(maxQueueSize, false), new ThreadPoolExecutor.CallerRunsPolicy());
}