Tabnine Logo
IndexWriterConfig.setOpenMode
Code IndexAdd Tabnine to your IDE (free)

How to use
setOpenMode
method
in
org.apache.lucene.index.IndexWriterConfig

Best Java code snippets using org.apache.lucene.index.IndexWriterConfig.setOpenMode (Showing top 20 results out of 954)

origin: soabase/exhibitor

public void open() throws Exception
{
  if ( !directory.exists() && !directory.mkdirs() )
  {
    throw new IOException("Could not make: " + directory);
  }
  IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, new KeywordAnalyzer()).setOpenMode(IndexWriterConfig.OpenMode.CREATE);
  niofsDirectory = new NIOFSDirectory(directory, new SingleInstanceLockFactory());
  writer = new IndexWriter(niofsDirectory, conf);
}
origin: com.h2database/h2

/**
 * Get the index writer/searcher wrapper for the given connection.
 *
 * @param conn the connection
 * @return the index access wrapper
 */
protected static IndexAccess getIndexAccess(Connection conn)
    throws SQLException {
  String path = getIndexPath(conn);
  synchronized (INDEX_ACCESS) {
    IndexAccess access = INDEX_ACCESS.get(path);
    if (access == null) {
      try {
        Directory indexDir = path.startsWith(IN_MEMORY_PREFIX) ?
            new RAMDirectory() : FSDirectory.open(new File(path));
        Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);
        IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_30, analyzer);
        conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
        IndexWriter writer = new IndexWriter(indexDir, conf);
        //see http://wiki.apache.org/lucene-java/NearRealtimeSearch
        access = new IndexAccess(writer);
      } catch (IOException e) {
        throw convertException(e);
      }
      INDEX_ACCESS.put(path, access);
    }
    return access;
  }
}
origin: opentripplanner/OpenTripPlanner

IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_47, analyzer).setOpenMode(OpenMode.CREATE);
final IndexWriter writer = new IndexWriter(directory, config);
for (Stop stop : graphIndex.stopForId.values()) {
origin: oracle/opengrok

Analyzer analyzer = new StandardAnalyzer();
IndexWriterConfig conf = new IndexWriterConfig(analyzer);
conf.setOpenMode(OpenMode.CREATE_OR_APPEND);
origin: FudanNLP/fnlp

Analyzer analyzer = new FNLPAnalyzer(Version.LUCENE_47);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_47, analyzer);
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
IndexWriter writer = new IndexWriter(dir, iwc);
origin: oracle/opengrok

Analyzer analyzer = AnalyzerGuru.getAnalyzer();
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
iwc.setRAMBufferSizeMB(env.getRamBufferSize());
origin: dermotte/LIRE

public static IndexWriter createIndexWriter(Directory directory, boolean create, AnalyzerType analyzer, double RAMBufferSize) throws IOException {
  // set the analyzer according to the method params
  Analyzer tmpAnalyzer = null;
  if (analyzer == AnalyzerType.SimpleAnalyzer) tmpAnalyzer = new SimpleAnalyzer();
  else if (analyzer == AnalyzerType.WhitespaceAnalyzer) tmpAnalyzer = new WhitespaceAnalyzer();
  // The config
  IndexWriterConfig config = new IndexWriterConfig(tmpAnalyzer);
  if (create)
    config.setOpenMode(IndexWriterConfig.OpenMode.CREATE); // overwrite if it exists.
  else
    config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); // create new if none is there, append otherwise.
  config.setRAMBufferSizeMB(RAMBufferSize);
  config.setCodec(new LireCustomCodec());
  return new IndexWriter(directory, config);
}
origin: dermotte/LIRE

public static IndexWriter createIndexWriter(Directory directory, boolean create, AnalyzerType analyzer, double RAMBufferSize) throws IOException {
  // set the analyzer according to the method params
  Analyzer tmpAnalyzer = null;
  if (analyzer == AnalyzerType.SimpleAnalyzer) tmpAnalyzer = new SimpleAnalyzer();
  else if (analyzer == AnalyzerType.WhitespaceAnalyzer) tmpAnalyzer = new WhitespaceAnalyzer();
  // The config
  IndexWriterConfig config = new IndexWriterConfig(tmpAnalyzer);
  if (create)
    config.setOpenMode(IndexWriterConfig.OpenMode.CREATE); // overwrite if it exists.
  else
    config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); // create new if none is there, append otherwise.
  config.setRAMBufferSizeMB(RAMBufferSize);
  config.setCodec(new LireCustomCodec());
  return new IndexWriter(directory, config);
}
origin: apache/pdfbox

iwc.setOpenMode(OpenMode.CREATE);
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
origin: org.elasticsearch/elasticsearch

private static IndexWriter newIndexWriter(final IndexWriterConfig.OpenMode openMode, final Directory dir, final IndexCommit commit)
  throws IOException {
  assert openMode == IndexWriterConfig.OpenMode.APPEND || commit == null : "can't specify create flag with a commit";
  IndexWriterConfig iwc = new IndexWriterConfig(null)
    .setSoftDeletesField(Lucene.SOFT_DELETES_FIELD)
    .setCommitOnClose(false)
    .setIndexCommit(commit)
    // we don't want merges to happen here - we call maybe merge on the engine
    // later once we stared it up otherwise we would need to wait for it here
    // we also don't specify a codec here and merges should use the engines for this index
    .setMergePolicy(NoMergePolicy.INSTANCE)
    .setOpenMode(openMode);
  return new IndexWriter(dir, iwc);
}
origin: org.elasticsearch/elasticsearch

protected void addNewHistoryCommit(Directory indexDirectory, Terminal terminal, boolean updateLocalCheckpoint) throws IOException {
  final String historyUUID = UUIDs.randomBase64UUID();
  terminal.println("Marking index with the new history uuid : " + historyUUID);
  // commit the new history id
  final IndexWriterConfig iwc = new IndexWriterConfig(null)
    // we don't want merges to happen here - we call maybe merge on the engine
    // later once we stared it up otherwise we would need to wait for it here
    // we also don't specify a codec here and merges should use the engines for this index
    .setCommitOnClose(false)
    .setSoftDeletesField(Lucene.SOFT_DELETES_FIELD)
    .setMergePolicy(NoMergePolicy.INSTANCE)
    .setOpenMode(IndexWriterConfig.OpenMode.APPEND);
  // IndexWriter acquires directory lock by its own
  try (IndexWriter indexWriter = new IndexWriter(indexDirectory, iwc)) {
    final Map<String, String> userData = new HashMap<>();
    indexWriter.getLiveCommitData().forEach(e -> userData.put(e.getKey(), e.getValue()));
    if (updateLocalCheckpoint) {
      // In order to have a safe commit invariant, we have to assign the global checkpoint to the max_seqno of the last commit.
      // We can only safely do it because we will generate a new history uuid this shard.
      final SequenceNumbers.CommitInfo commitInfo = SequenceNumbers.loadSeqNoInfoFromLuceneCommit(userData.entrySet());
      // Also advances the local checkpoint of the last commit to its max_seqno.
      userData.put(SequenceNumbers.LOCAL_CHECKPOINT_KEY, Long.toString(commitInfo.maxSeqNo));
    }
    // commit the new history id
    userData.put(Engine.HISTORY_UUID_KEY, historyUUID);
    indexWriter.setLiveCommitData(userData.entrySet());
    indexWriter.commit();
  }
}
origin: org.elasticsearch/elasticsearch

/**
 * This method removes all lucene files from the given directory. It will first try to delete all commit points / segments
 * files to ensure broken commits or corrupted indices will not be opened in the future. If any of the segment files can't be deleted
 * this operation fails.
 */
public static void cleanLuceneIndex(Directory directory) throws IOException {
  try (Lock writeLock = directory.obtainLock(IndexWriter.WRITE_LOCK_NAME)) {
    for (final String file : directory.listAll()) {
      if (file.startsWith(IndexFileNames.SEGMENTS) || file.equals(IndexFileNames.OLD_SEGMENTS_GEN)) {
        directory.deleteFile(file); // remove all segment_N files
      }
    }
  }
  try (IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(Lucene.STANDARD_ANALYZER)
      .setSoftDeletesField(Lucene.SOFT_DELETES_FIELD)
      .setMergePolicy(NoMergePolicy.INSTANCE) // no merges
      .setCommitOnClose(false) // no commits
      .setOpenMode(IndexWriterConfig.OpenMode.CREATE))) // force creation - don't append...
  {
    // do nothing and close this will kick of IndexFileDeleter which will remove all pending files
  }
}
origin: larsga/Duke

private void openIndexes(boolean overwrite) throws IOException {
 if (directory == null) {
  try {
   if (path == null)
    directory = new RAMDirectory();
   else {
    //directory = new MMapDirectory(new File(config.getPath()));
    // as per http://wiki.apache.org/lucene-java/ImproveSearchingSpeed
    // we use NIOFSDirectory, provided we're not on Windows
    if (Utils.isWindowsOS())
     directory = FSDirectory.open(new File(path));
    else
     directory = NIOFSDirectory.open(new File(path));
   }
   IndexWriterConfig cfg =
    new IndexWriterConfig(Version.LUCENE_CURRENT, analyzer);
   cfg.setOpenMode(overwrite ? IndexWriterConfig.OpenMode.CREATE :
                 IndexWriterConfig.OpenMode.APPEND);
   iwriter = new IndexWriter(directory, cfg);
   iwriter.commit(); // so that the searcher doesn't fail
  } catch (IndexNotFoundException e) {
   if (!overwrite) {
    // the index was not there, so make a new one
    directory = null; // ensure we really do try again
    openIndexes(true);
   } else
    throw new DukeException(e);
  }
 }
}
origin: ahmetaa/zemberek-nlp

public void addCorpora(List<Path> corpora, double ramBufferInMb) throws IOException {
 Directory dir = FSDirectory.open(indexPath);
 Analyzer analyzer = CustomAnalyzer.builder()
   .withTokenizer("standard")
   .addTokenFilter(LuceneLemmaFilter.Factory.class)
   .build();
 IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
 iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
 iwc.setRAMBufferSizeMB(ramBufferInMb);
 IndexWriter writer = new IndexWriter(dir, iwc);
 for (Path path : corpora) {
  Log.info("Adding %s", path);
  addDocs(writer, path);
 }
 writer.close();
}
origin: dermotte/LIRE

config.setCommitOnClose(true);
if (create)
  config.setOpenMode(IndexWriterConfig.OpenMode.CREATE); // overwrite if it exists.
else
  config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); // create new if none is there, append otherwise.
origin: dermotte/LIRE

config.setCommitOnClose(true);
if (create)
  config.setOpenMode(IndexWriterConfig.OpenMode.CREATE); // overwrite if it exists.
else
  config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); // create new if none is there, append otherwise.
origin: org.elasticsearch/elasticsearch

  .setOpenMode(IndexWriterConfig.OpenMode.APPEND);
if (indexSort != null) {
  iwc.setIndexSort(indexSort);
origin: org.elasticsearch/elasticsearch

.setCommitOnClose(false)
.setMergePolicy(NoMergePolicy.INSTANCE)
.setOpenMode(IndexWriterConfig.OpenMode.APPEND))) {
origin: org.elasticsearch/elasticsearch

  .setOpenMode(IndexWriterConfig.OpenMode.CREATE)
  .setCommitOnClose(true));
writer.close();
origin: org.elasticsearch/elasticsearch

private IndexWriterConfig getIndexWriterConfig() {
  final IndexWriterConfig iwc = new IndexWriterConfig(engineConfig.getAnalyzer());
  iwc.setCommitOnClose(false); // we by default don't commit on close
  iwc.setOpenMode(IndexWriterConfig.OpenMode.APPEND);
  iwc.setIndexDeletionPolicy(combinedDeletionPolicy);
org.apache.lucene.indexIndexWriterConfigsetOpenMode

Javadoc

Specifies OpenMode of the index.

Only takes effect when IndexWriter is first created.

Popular methods of IndexWriterConfig

  • <init>
  • setRAMBufferSizeMB
  • setMergePolicy
  • setMergeScheduler
    Expert: sets the merge scheduler used by this writer. The default is ConcurrentMergeScheduler.NOTE:
  • setCodec
    Set the Codec. Only takes effect when IndexWriter is first created.
  • setIndexDeletionPolicy
    Expert: allows an optional IndexDeletionPolicy implementation to be specified. You can use this to c
  • setSimilarity
    Expert: set the Similarity implementation used by this IndexWriter.NOTE: the similarity must not be
  • setUseCompoundFile
  • setInfoStream
    Information about merges, deletes and a message when maxFieldLength is reached will be printed to th
  • getMergePolicy
  • setCommitOnClose
    Sets if calls IndexWriter#close() should first commit before closing. Use true to match behavior of
  • setMaxBufferedDocs
  • setCommitOnClose,
  • setMaxBufferedDocs,
  • setIndexCommit,
  • getInfoStream,
  • setIndexWriter,
  • setWriteLockTimeout,
  • getRAMBufferSizeMB,
  • setMaxBufferedDeleteTerms,
  • setMergedSegmentWarmer

Popular in Java

  • Start an intent from android
  • onCreateOptionsMenu (Activity)
  • getSharedPreferences (Context)
  • findViewById (Activity)
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • Notification (javax.management)
  • JTable (javax.swing)
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now