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


Java NIOFSDirectory.open方法代码示例

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


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

示例1: getIndexWriter

import org.apache.lucene.store.NIOFSDirectory; //导入方法依赖的package包/类
public static IndexWriter getIndexWriter(String indexdirectory, double buffersize)
        throws IOException {
  Directory dir;
  if (OSUtil.isWindows())
    dir = FSDirectory.open(new File(indexdirectory));
  else
    dir = NIOFSDirectory.open(new File(indexdirectory));

  Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_45);
  IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_45, analyzer);

  config.setOpenMode(OpenMode.CREATE_OR_APPEND);
  config.setRAMBufferSizeMB(buffersize);
  LogDocMergePolicy mergePolicy = new LogDocMergePolicy();
  mergePolicy.setMergeFactor(3);
  config.setMergePolicy(mergePolicy);

  IndexWriter writer = new IndexWriter(dir, config);
  return writer;
}
 
开发者ID:weizh,项目名称:geolocator-3.0,代码行数:21,代码来源:GetWriter.java

示例2: openIndexes

import org.apache.lucene.store.NIOFSDirectory; //导入方法依赖的package包/类
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);
    }
  }
}
 
开发者ID:larsga,项目名称:Duke,代码行数:32,代码来源:LuceneDatabase.java

示例3: getTaxDirectory

import org.apache.lucene.store.NIOFSDirectory; //导入方法依赖的package包/类
private Directory getTaxDirectory(ODatabaseDocumentInternal database) throws IOException {
  Directory dir = null;
  final OAbstractPaginatedStorage storageLocalAbstract = (OAbstractPaginatedStorage) database.getStorage().getUnderlying();
  if (storageLocalAbstract instanceof OLocalPaginatedStorage) {
    String pathname = getIndexFacetPath((OLocalPaginatedStorage) storageLocalAbstract);
    dir = NIOFSDirectory.open(new File(pathname));
  } else {
    dir = new RAMDirectory();
  }
  return dir;
}
 
开发者ID:orientechnologies,项目名称:orientdb-lucene,代码行数:12,代码来源:OLuceneFacetManager.java

示例4: reOpen

import org.apache.lucene.store.NIOFSDirectory; //导入方法依赖的package包/类
private void reOpen(final ODocument metadata) throws IOException {
  ODatabaseDocumentInternal database = getDatabase();

  final OAbstractPaginatedStorage storageLocalAbstract = (OAbstractPaginatedStorage) database.getStorage().getUnderlying();
  Directory dir = null;
  if (storageLocalAbstract instanceof OLocalPaginatedStorage) {
    String pathname = getIndexPath((OLocalPaginatedStorage) storageLocalAbstract);

    OLogManager.instance().debug(this, "Opening NIOFS Lucene db=%s, path=%s", database.getName(), pathname);

    dir = NIOFSDirectory.open(new File(pathname));
  } else {

    OLogManager.instance().debug(this, "Opening RAM Lucene index db=%s", database.getName());
    dir = new RAMDirectory();

  }

  final IndexWriter indexWriter = createIndexWriter(dir, metadata);
  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();
}
 
开发者ID:orientechnologies,项目名称:orientdb-lucene,代码行数:31,代码来源:OLuceneIndexManagerAbstract.java

示例5: LuceneIndexer

import org.apache.lucene.store.NIOFSDirectory; //导入方法依赖的package包/类
public LuceneIndexer(AppContext appContext) throws IOException {
    this.appContext = appContext;
    Date start = new Date();
    Directory dir = NIOFSDirectory.open(new File(appContext.getIndexLocation(), AppConstants.DLI_INDEX));
    Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_46);
    IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_46, analyzer);
    iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
    iwc.setMergePolicy(new TieredMergePolicy());
    iwc.setIndexDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
    iwc.setRAMBufferSizeMB(32);
    writer = new IndexWriter(dir, iwc);
    Date end = new Date();
    System.out.println(end.getTime() - start.getTime() + " total milliseconds");
}
 
开发者ID:cancerian0684,项目名称:dli-downloader,代码行数:15,代码来源:LuceneIndexer.java

示例6: LuceneSearcher

import org.apache.lucene.store.NIOFSDirectory; //导入方法依赖的package包/类
public LuceneSearcher(AppContext appContext) throws IOException, ParseException {
    directory = NIOFSDirectory.open(new File(appContext.getIndexLocation(), AppConstants.DLI_INDEX));
    searcherManager = new SearcherManager(directory, null);
    analyzer = new StandardAnalyzer(Version.LUCENE_46, StopAnalyzer.ENGLISH_STOP_WORDS_SET);
    parser = new QueryParser(Version.LUCENE_46, field, analyzer);
    parser.setAllowLeadingWildcard(true);
    parser.setAnalyzeRangeTerms(true);
}
 
开发者ID:cancerian0684,项目名称:dli-downloader,代码行数:9,代码来源:LuceneSearcher.java

示例7: execute

import org.apache.lucene.store.NIOFSDirectory; //导入方法依赖的package包/类
@Override
  public void execute() throws IOException {
      String indexPath;
      if (null != getExecution().getIndexDirectory() && !getExecution().getIndexDirectory().isEmpty()) {
          indexPath = getExecution().getIndexDirectory();
      } else {
          indexPath = Files.createTempDirectory(InfolisConfig.getTmpFilePath().toAbsolutePath(), INDEX_DIR_PREFIX).toString();
          FileUtils.forceDeleteOnExit(new File(indexPath));
      }
      log.debug("Indexing to: " + indexPath);
      getExecution().setOutputDirectory(indexPath);

      IndexWriterConfig indexWriterConfig = new IndexWriterConfig(createAnalyzer());
      indexWriterConfig.setOpenMode(OpenMode.CREATE);
      // An FSDirectory implementation that uses java.nio's FileChannel's positional read, which allows multiple threads to read from the same file without synchronizing. 
      // NIOFSDirectory is not recommended on Windows because of a bug in how FileChannel.read is implemented in Sun's JRE. Inside of the implementation the position is apparently synchronized.
      Directory fsIndexDir = NIOFSDirectory.open(Paths.get(indexPath));

      List<InfolisFile> files = new ArrayList<>();
if (null != getExecution().getInfolisFileTags() && !getExecution().getInfolisFileTags().isEmpty()) {
	Execution tagExec = getExecution().createSubExecution(TagSearcher.class);
	tagExec.getInfolisFileTags().addAll(getExecution().getInfolisFileTags());
	tagExec.instantiateAlgorithm(this).run();
	getExecution().getInputFiles().addAll(tagExec.getInputFiles());
}
      for (String fileUri : getExecution().getInputFiles()) {
          try {
              files.add(this.getInputDataStoreClient().get(InfolisFile.class, fileUri));
          } catch (BadRequestException | ProcessingException e) {
              error(log, "Could not retrieve file " + fileUri + ": " + e.getMessage());
              getExecution().setStatus(ExecutionStatus.FAILED);
              fsIndexDir.close();
              return;
          }
      }

      Date start = new Date();
      log.debug("Starting to index");
      IndexWriter writer = new IndexWriter(fsIndexDir, indexWriterConfig);
      try {
          int counter = 0;
          for (InfolisFile file : files) {
              counter++;
              log.trace("Indexing file " + file);
              writer.addDocument(toLuceneDocument(getInputFileResolver(), file));
              updateProgress(counter, files.size());

          }
      } catch (FileNotFoundException fnfe) {
          // NOTE: at least on windows, some temporary files raise this
          // exception with an "access denied" message checking if the
          // file can be read doesn't help
          throw new RuntimeException("Could not write index entry: " + fnfe);
      } finally {
          log.debug("Merging all Lucene segments ...");
          writer.forceMerge(1);
          writer.close();
          fsIndexDir.close();
      }
      long duration = new Date().getTime() - start.getTime();
      getExecution().setStatus(ExecutionStatus.FINISHED);
      log.debug(String.format("Indexing %s documents took %s ms = %s hours (index: %s)", files.size(), duration, ((duration / 1000) / 60) / 60, indexPath));
  }
 
开发者ID:infolis,项目名称:infoLink,代码行数:64,代码来源:Indexer.java

示例8: getDirectory

import org.apache.lucene.store.NIOFSDirectory; //导入方法依赖的package包/类
protected Directory getDirectory() throws IOException {
  return NIOFSDirectory.open(getPath());
}
 
开发者ID:orientechnologies,项目名称:orientdb-lucene,代码行数:4,代码来源:LuceneVsLuceneTest.java

示例9: getDirectoryIndex

import org.apache.lucene.store.NIOFSDirectory; //导入方法依赖的package包/类
/**
 * Gets the current IndexSearcher.
 *
 * @return IndexSearcher
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static Directory getDirectoryIndex( ) throws IOException
{
    return NIOFSDirectory.open( Paths.get( _strIndex ) );
}
 
开发者ID:lutece-platform,项目名称:lutece-core,代码行数:12,代码来源:IndexationService.java


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