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


Java IndexWriterConfig.setOpenMode方法代码示例

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


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

示例1: getIndexWriterConfig

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
private IndexWriterConfig getIndexWriterConfig(boolean create) {
    final IndexWriterConfig iwc = new IndexWriterConfig(engineConfig.getAnalyzer());
    iwc.setCommitOnClose(false); // we by default don't commit on close
    iwc.setOpenMode(create ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND);
    iwc.setIndexDeletionPolicy(deletionPolicy);
    // with tests.verbose, lucene sets this up: plumb to align with filesystem stream
    boolean verbose = false;
    try {
        verbose = Boolean.parseBoolean(System.getProperty("tests.verbose"));
    } catch (Exception ignore) {
    }
    iwc.setInfoStream(verbose ? InfoStream.getDefault() : new LoggerInfoStream(logger));
    iwc.setMergeScheduler(mergeScheduler);
    MergePolicy mergePolicy = config().getMergePolicy();
    // Give us the opportunity to upgrade old segments while performing
    // background merges
    mergePolicy = new ElasticsearchMergePolicy(mergePolicy);
    iwc.setMergePolicy(mergePolicy);
    iwc.setSimilarity(engineConfig.getSimilarity());
    iwc.setRAMBufferSizeMB(engineConfig.getIndexingBufferSize().getMbFrac());
    iwc.setCodec(engineConfig.getCodec());
    iwc.setUseCompoundFile(true); // always use compound on flush - reduces # of file-handles on refresh
    return iwc;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:InternalEngine.java

示例2: process

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的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: LuceneIndex

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的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

示例4: InMemoryIndex

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
public InMemoryIndex(Map<String,String> id2Text){
    Analyzer analyzer = new EnglishAnalyzer();
    IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
    iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    try {
        IndexWriter writer = new IndexWriter(directory, iwc);
        for (String id:id2Text.keySet()) {
            Document doc=new Document();
            doc.add(new StringField("id", id, Field.Store.YES));
            doc.add(new TextField("content", id2Text.get(id), Field.Store.YES));
            writer.addDocument(doc);
        }
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:linzeqipku,项目名称:SnowGraph,代码行数:18,代码来源:InMemoryIndex.java

示例5: index

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
/**
 * Indexing documents using provided Analyzer
 *
 * @param create to decide create new or append to previous one
 * @throws IOException
 */
public void index(final Boolean create, List<Document> documents, Analyzer analyzer) throws IOException {
    final Directory dir = FSDirectory.open(Paths.get(pathToIndexFolder));
    final IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
    if (create) {
        // Create a new index in the directory, removing any
        // previously indexed documents:
        iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    }
    else {
        // Add new documents to an existing index:
        iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
    }

    final IndexWriter w = new IndexWriter(dir, iwc);
    w.addDocuments(documents);
    w.close();
}
 
开发者ID:c0rp-aubakirov,项目名称:lucene-tutorial,代码行数:24,代码来源:MessageIndexer.java

示例6: createIndexQ

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
public static void createIndexQ(List<CQAResult> QASetList, Directory dir) {
    System.out.println("Creating Questions Index");
    IndexWriterConfig iwc = new IndexWriterConfig(ANALYZER.getVersion(), ANALYZER);
    iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    try {
        IndexWriter writer = new IndexWriter(dir, iwc);
        int id = 0; //XXX seq_id
        for (CQAResult qaSet : QASetList) {
            Document doc = new Document();
            if (qaSet.subject == null) {
                id++;
                continue;
            }
            doc.add(new IntField(QID, id++, Field.Store.YES));
            doc.add(new TextField(BEST_ANSWER_FIELD, qaSet.subject, Field.Store.NO));
            doc.add(new TextField(Q_DESCRIPTION, qaSet.content, Field.Store.NO));
            writer.addDocument(doc);
        }
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:oaqa,项目名称:LiveQA,代码行数:24,代码来源:QaPairIndex.java

示例7: getIndexWriter

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的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

示例8: createWriter

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
public void createWriter(String indexPath){
    /*
    The indexPath specifies where to create the index
     */

    // I am can imagine that there are lots of ways to create indexers -
    // We could add in some parameters to customize its creation

    try {
        Directory dir = FSDirectory.open(Paths.get(indexPath));
        System.out.println("Indexing to directory '" + indexPath + "'...");

        IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
        iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
        writer = new IndexWriter(dir, iwc);

    } catch (IOException e){
        e.printStackTrace();
        System.exit(1);
    }
}
 
开发者ID:lucene4ir,项目名称:lucene4ir,代码行数:22,代码来源:DocumentIndexer.java

示例9: initializeIndexBuilder

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的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

示例10: Indexer

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
/**
 * Create or open a document index
 *
 * @param indexRoot The parent directory inside which the index lives.
 * @param appendIfExists If true, the index will be opened for appending new documents.
 * @throws IOException
 */
public Indexer(String indexRoot, boolean appendIfExists) throws IOException {
  Path indexRootPath = Paths.get(indexRoot);
  Analyzer analyzer = getAnalyzer();

  Directory mainIndexDir = FSDirectory.open(getMainIndexPath(indexRootPath));
  IndexWriterConfig mainIndexWriterConfig = new IndexWriterConfig(analyzer);

  if (appendIfExists) {
    mainIndexWriterConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
  } else {
    mainIndexWriterConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
  }

  indexWriter = new IndexWriter(mainIndexDir, mainIndexWriterConfig);
}
 
开发者ID:lukhnos,项目名称:lucenestudy,代码行数:23,代码来源:Indexer.java

示例11: main

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的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

示例12: main

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的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

示例13: openWriter

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
private IndexWriter openWriter(Conf conf, boolean create) throws IOException {
    File indexDir = new File(conf.getEsaIndexDir());
    indexDir.mkdirs();
    System.out.println("Create index on " + indexDir.getAbsolutePath());
    Directory fsDirectory = FSDirectory.open(indexDir);

    IndexWriterConfig config = new IndexWriterConfig(Conf.LUCENE_VERSION, new ESAAnalyzer(conf));
    config.setSimilarity(new ESASimilarity());
    if (create) {
        // Create a new index in the directory, removing any
        // previously indexed documents:
        config.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    } else {
        // Add new documents to an existing index:
        config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
    }
    return new IndexWriter(fsDirectory, config);
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:19,代码来源:IndexConceptVisitor.java

示例14: prepareIndex

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的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: create

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的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


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