当前位置: 首页>>代码示例>>Java>>正文


Java OpenMode类代码示例

本文整理汇总了Java中org.apache.lucene.index.IndexWriterConfig.OpenMode的典型用法代码示例。如果您正苦于以下问题:Java OpenMode类的具体用法?Java OpenMode怎么用?Java OpenMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OpenMode类属于org.apache.lucene.index.IndexWriterConfig包,在下文中一共展示了OpenMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: indexDoc

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
static void indexDoc(IndexWriter writer, Path file, long lastModified) throws IOException {
	try (InputStream stream = Files.newInputStream(file)) {
		Document doc = new Document();
		Field pathField = new StringField("path", file.toString(), Field.Store.YES);
		doc.add(pathField);
		doc.add(new LongPoint("modified", lastModified));
		doc.add(new TextField("contents", new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))));

		if (writer.getConfig().getOpenMode() == OpenMode.CREATE) {
			System.out.println("adding " + file);
			writer.addDocument(doc);
		} else {
			System.out.println("updating " + file);
			writer.updateDocument(new Term("path", file.toString()), doc);
		}
	}
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:18,代码来源:IndexFiles.java

示例2: process

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
@Override
public void process(ProcessingContext<Corpus> ctx, Corpus corpus) throws ModuleException {
	try (KeywordAnalyzer kwa = new KeywordAnalyzer()) {
		IndexWriterConfig writerConfig = new IndexWriterConfig(Version.LUCENE_36, kwa);
		writerConfig.setOpenMode(append ? OpenMode.CREATE_OR_APPEND : OpenMode.CREATE);
		try (Directory dir = FSDirectory.open(indexDir)) {
			try (IndexWriter writer = new IndexWriter(dir, writerConfig)) {
				AlvisDBIndexerResolvedObjects resObj = getResolvedObjects();
				Logger logger = getLogger(ctx);
				EvaluationContext evalCtx = new EvaluationContext(logger);
				for (ADBElements.Resolved ent : resObj.elements) {
					ent.indexElements(logger, writer, evalCtx, corpus);
				}
			}
		}
		catch (IOException e) {
			rethrow(e);
		}
	}
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:21,代码来源:AlvisDBIndexer.java

示例3: PersistentSnapshotDeletionPolicy

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
/**
 * {@link PersistentSnapshotDeletionPolicy} wraps another
 * {@link IndexDeletionPolicy} to enable flexible snapshotting.
 * 
 * @param primary
 *          the {@link IndexDeletionPolicy} that is used on non-snapshotted
 *          commits. Snapshotted commits, by definition, are not deleted until
 *          explicitly released via {@link #release}.
 * @param dir
 *          the {@link Directory} which will be used to persist the snapshots
 *          information.
 * @param mode
 *          specifies whether a new index should be created, deleting all
 *          existing snapshots information (immediately), or open an existing
 *          index, initializing the class with the snapshots information.
 */
public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary,
    Directory dir, OpenMode mode) throws IOException {
  super(primary);

  this.dir = dir;

  if (mode == OpenMode.CREATE) {
    clearPriorSnapshots();
  }

  loadPriorSnapshots();

  if (mode == OpenMode.APPEND && nextWriteGen == 0) {
    throw new IllegalStateException("no snapshots stored in this directory");
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:PersistentSnapshotDeletionPolicy.java

示例4: LuceneIndex

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
/**
 * Constructor for LuceneIndex
 * 
 * @param dataDirectory   Path to the directory to create an index directory within.
 * @throws IndexException
 */
public LuceneIndex(Path dataDirectory) throws IndexException {
	
	//TODO: Check to make sure directory is read/writable
	path = dataDirectory.resolve(INDEXDIR);
	
	try {
		dir = FSDirectory.open(path);
		analyzer = new StandardAnalyzer();
		IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
		iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
		writer = new IndexWriter(dir, iwc);

		reader = DirectoryReader.open(writer, false);
		searcher = new IndexSearcher(reader);
		parser = new QueryParser(IndexDocumentAdapter.FIELD_SEARCH, analyzer);
	} catch (IOException e) {
		LOG.error(e.getLocalizedMessage());
		throw new IndexException(e);
	}
}
 
开发者ID:abuchanan920,项目名称:historybook,代码行数:27,代码来源:LuceneIndex.java

示例5: getIndexWriter

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
/**
 * 获取writer
 *
 * @return
 * @throws IOException
 */
protected static IndexWriter getIndexWriter() throws IOException {

    if (null != indexWriter) {
        return indexWriter;
    } else {
        // 防止并发
        synchronized (IndexUtil.class) {
            //  初始化writer
            IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_35,
                new StandardAnalyzer(Version.LUCENE_35));
            
            // 每次都重新创建
            config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
            indexWriter = new IndexWriter(directory, config);
        }
        return indexWriter;
    }
}
 
开发者ID:cycman,项目名称:libooc,代码行数:25,代码来源:BaseUtil.java

示例6: initializeIndexBuilder

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
public void initializeIndexBuilder() throws Exception {
    // Create a new index directory and writer to index a triples file.
    // Raise an error if an index already exists, so we don't accidentally overwrite it.
    String indexDir = getIndexDirectoryName();
    if ((new File(indexDir)).isDirectory())
        throw new IOException("Index directory already exists, remove it before indexing");

    indexDirectory = FSDirectory.open(Paths.get(indexDir));
    IndexWriterConfig iwc = new IndexWriterConfig(getIndexAnalyzer());

    // we always create a new index from scratch:
    iwc.setOpenMode(OpenMode.CREATE);
    iwc.setCodec(new Lucene54Codec(Mode.BEST_SPEED));          // the default
    //iwc.setCodec(new Lucene54Codec(Mode.BEST_COMPRESSION));  // slower, but better compression

    indexWriter = new IndexWriter(indexDirectory, iwc);
    indexAnalyzer = getIndexAnalyzer();

    if (INDEX_PREDICATES) printlnProg("Indexing individual predicates");
    if (INDEX_TEXT) printlnProg("Indexing combined predicate text values");
    if (INDEX_LANGUAGE) printlnProg("Indexing predicates for language(s): " + supportedLanguages);
}
 
开发者ID:isoboroff,项目名称:basekb-search,代码行数:23,代码来源:FreebaseIndexer.java

示例7: initializeIndexBuilder

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
public void initializeIndexBuilder() throws Exception {
    // Create a new index directory and writer to index a triples file.
    // Raise an error if an index already exists, so we don't accidentally overwrite it.
    String indexDir = getIndexDirectoryName();
    if ((new java.io.File(indexDir)).isDirectory())
        throw new IOException("Index directory already exists, remove it before indexing");

    indexDirectory = FSDirectory.open(Paths.get(indexDir));
    IndexWriterConfig iwc = new IndexWriterConfig(getIndexAnalyzer());

    // we always create a new index from scratch:
    iwc.setOpenMode(OpenMode.CREATE);
    iwc.setCodec(new Lucene54Codec(Mode.BEST_SPEED));          // the default
    //iwc.setCodec(new Lucene54Codec(Mode.BEST_COMPRESSION));  // slower, but better compression

    indexWriter = new IndexWriter(indexDirectory, iwc);
    indexAnalyzer = getIndexAnalyzer();

    if (INDEX_PREDICATES) printlnProg("Indexing individual predicates");
    if (INDEX_TEXT) printlnProg("Indexing combined predicate text values");
    if (INDEX_LANGUAGE) printlnProg("Indexing predicates for language(s): " + supportedLanguages);
}
 
开发者ID:isoboroff,项目名称:basekb-search,代码行数:23,代码来源:FreebaseTools.java

示例8: main

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
    initLoggers(Level.ERROR);
    RedisDirectory DIR = new RedisDirectory(REDIS_HOST, REDIS_PORT, REDIS_PASSWORD);
    DIR.init();

    long t1 = System.currentTimeMillis();
    try {
        Analyzer analyzer = new StandardAnalyzer();
        IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
        iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
        IndexWriter iw = new IndexWriter(DIR, iwc);

        Path docDir = Paths
                .get("/Users/btnguyen/Workspace/Apps/Apache-Cassandra-2.1.8/javadoc/");
        indexDocs(iw, docDir);

        iw.commit();
        iw.close();
    } finally {
        DIR.destroy();
    }
    long t2 = System.currentTimeMillis();
    System.out.println("Finished in " + (t2 - t1) / 1000.0 + " sec");
}
 
开发者ID:DDTH,项目名称:redir,代码行数:25,代码来源:QndRedisDirIndexDemo.java

示例9: main

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
    initLoggers(Level.INFO);
    RedisDirectory DIR = new RedisDirectory(REDIS_HOST, REDIS_PORT, REDIS_PASSWORD);
    DIR.init();

    long t1 = System.currentTimeMillis();
    try {
        Analyzer analyzer = new StandardAnalyzer();
        IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
        iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);

        IndexWriter iw = new IndexWriter(DIR, iwc);
        Document doc = new Document();
        doc.add(new StringField("id", "thanhnb", Field.Store.YES));
        doc.add(new TextField("name", "Nguyen Ba Thanh", Field.Store.NO));
        iw.updateDocument(new Term("id", "thanhnb"), doc);

        iw.commit();

        iw.close();
    } finally {
        DIR.destroy();
    }
    long t2 = System.currentTimeMillis();
    System.out.println("Finished in " + (t2 - t1) / 1000.0 + " sec");
}
 
开发者ID:DDTH,项目名称:redir,代码行数:27,代码来源:QndRedisDirIndex.java

示例10: testNoMergeAfterCopy

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
public void testNoMergeAfterCopy() throws IOException {
  // main directory
  Directory dir = newDirectory();
  // auxiliary directory
  Directory aux = newDirectory();

  setUpDirs(dir, aux);

  IndexWriter writer = newWriter(
      dir,
      newIndexWriterConfig(new MockAnalyzer(random())).
          setOpenMode(OpenMode.APPEND).
          setMaxBufferedDocs(10).
          setMergePolicy(newLogMergePolicy(4))
  );

  writer.addIndexes(aux, new MockDirectoryWrapper(random(), new RAMDirectory(aux, newIOContext(random()))));
  assertEquals(1060, writer.maxDoc());
  assertEquals(1000, writer.getDocCount(0));
  writer.close();

  // make sure the index is correct
  verifyNumDocs(dir, 1060);
  dir.close();
  aux.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:TestAddIndexes.java

示例11: PDLucene

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
public PDLucene () throws IOException
{
  // Where to store the index files
  final Path aPath = getLuceneIndexDir ().toPath ();
  m_aDir = FSDirectory.open (aPath);

  // Analyzer to use
  m_aAnalyzer = createAnalyzer ();

  // Create the index writer
  final IndexWriterConfig aWriterConfig = new IndexWriterConfig (m_aAnalyzer);
  aWriterConfig.setOpenMode (OpenMode.CREATE_OR_APPEND);
  m_aIndexWriter = new IndexWriter (m_aDir, aWriterConfig);

  // Reader and searcher are opened on demand

  s_aLogger.info ("Lucene index operating on " + aPath);
}
 
开发者ID:phax,项目名称:peppol-directory,代码行数:19,代码来源:PDLucene.java

示例12: create

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
/**
 * Creates an empty collection to get it up and running
 */
public synchronized void create() throws IOException {
	setDirectory();
	
	if ( directory.listAll().length > 2 )
		throw new IOException( "directory not empty; possible collection already present" );

	IndexWriterConfig iwc = new IndexWriterConfig( AnalyzerFactory.get(language) );
	iwc.setOpenMode( OpenMode.CREATE );
	
	indexwriter = new IndexWriter(directory, iwc);
	indexwriter.commit();
	indexwriter.close();
	indexwriter = null;
	
	// throw an openbd.create file in there so we know when it was created
	created	= System.currentTimeMillis();
	File touchFile	= new File( collectionpath, "openbd.created" );
	Writer	fw	= new FileWriter( touchFile );
	fw.close();
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:24,代码来源:Collection.java

示例13: GerritIndexWriterConfig

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
GerritIndexWriterConfig(Config cfg, String name) {
  analyzer =
      new CustomMappingAnalyzer(
          new StandardAnalyzer(CharArraySet.EMPTY_SET), CUSTOM_CHAR_MAPPING);
  luceneConfig =
      new IndexWriterConfig(analyzer)
          .setOpenMode(OpenMode.CREATE_OR_APPEND)
          .setCommitOnClose(true);
  double m = 1 << 20;
  luceneConfig.setRAMBufferSizeMB(
      cfg.getLong(
              "index",
              name,
              "ramBufferSize",
              (long) (IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB * m))
          / m);
  luceneConfig.setMaxBufferedDocs(
      cfg.getInt("index", name, "maxBufferedDocs", IndexWriterConfig.DEFAULT_MAX_BUFFERED_DOCS));
  try {
    commitWithinMs =
        ConfigUtil.getTimeUnit(
            cfg, "index", name, "commitWithin", MILLISECONDS.convert(5, MINUTES), MILLISECONDS);
  } catch (IllegalArgumentException e) {
    commitWithinMs = cfg.getLong("index", name, "commitWithin", 0);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:27,代码来源:GerritIndexWriterConfig.java

示例14: prepareIndex

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
public void prepareIndex() throws IOException {
    File globalWFMDIr = new File(Util.GTPM_INDEX_DIR);
    if (!globalWFMDIr.exists()) {
        Util.createDirs(Util.GTPM_INDEX_DIR);
    }
    KeywordAnalyzer keywordAnalyzer = new KeywordAnalyzer();
    IndexWriterConfig wfmIndexWriterConfig = new IndexWriterConfig(Version.LUCENE_46, keywordAnalyzer);
    wfmIndexWriterConfig.setOpenMode(OpenMode.CREATE_OR_APPEND);
    wfmIndexWriterConfig.setRAMBufferSizeMB(1024);

    logger.info("PREPARE INDEX");
    try {
        wfmIndexWriter = new IndexWriter(FSDirectory.open(new File(Util.GTPM_INDEX_DIR)), wfmIndexWriterConfig);
        wfmIndexWriter.commit();
        wfmIndexer = new DocumentMaker(wfmIndexWriter);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Mondego,项目名称:SourcererCC,代码行数:20,代码来源:WordFrequencyStore.java

示例15: getIndexWriterConfig

import org.apache.lucene.index.IndexWriterConfig.OpenMode; //导入依赖的package包/类
private static IndexWriterConfig getIndexWriterConfig() {

		final Analyzer analyzer = getAnalyzer();

		final IndexWriterConfig writerConfig = new IndexWriterConfig(LUCENE_VERSION, analyzer);

		final boolean IS_DELETE_INDEX = true;

		if (IS_DELETE_INDEX) {
			// delete old index and create a new
			writerConfig.setOpenMode(OpenMode.CREATE);
		} else {
			writerConfig.setOpenMode(OpenMode.CREATE_OR_APPEND);
		}

		return writerConfig;
	}
 
开发者ID:wolfgang-ch,项目名称:mytourbook,代码行数:18,代码来源:FTSearchManager.java


注:本文中的org.apache.lucene.index.IndexWriterConfig.OpenMode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。