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


Java Directory.listAll方法代码示例

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


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

示例1: removeCorruptionMarker

import org.apache.lucene.store.Directory; //导入方法依赖的package包/类
/**
 * Deletes all corruption markers from this store.
 */
public void removeCorruptionMarker() throws IOException {
    ensureOpen();
    final Directory directory = directory();
    IOException firstException = null;
    final String[] files = directory.listAll();
    for (String file : files) {
        if (file.startsWith(CORRUPTED)) {
            try {
                directory.deleteFile(file);
            } catch (IOException ex) {
                if (firstException == null) {
                    firstException = ex;
                } else {
                    firstException.addSuppressed(ex);
                }
            }
        }
    }
    if (firstException != null) {
        throw firstException;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:Store.java

示例2: cleanLuceneIndex

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

示例3: fitsIntoMem

import org.apache.lucene.store.Directory; //导入方法依赖的package包/类
private static boolean fitsIntoMem(@NonNull final Directory dir) {
    try {
        long size = 0;
        for (String path : dir.listAll()) {
            size+=dir.fileLength(path);
        }
        return IndexCacheFactory.getDefault().getRAMController().shouldLoad(size);
    } catch (IOException ioe) {
        return false;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:LuceneIndex.java

示例4: estimateSize

import org.apache.lucene.store.Directory; //导入方法依赖的package包/类
private static long estimateSize(Directory directory) throws IOException {
    long estimatedSize = 0;
    String[] files = directory.listAll();
    for (String file : files) {
        try {
            estimatedSize += directory.fileLength(file);
        } catch (NoSuchFileException | FileNotFoundException | AccessDeniedException e) {
            // ignore, the file is not there no more; on Windows, if one thread concurrently deletes a file while
            // calling Files.size, you can also sometimes hit AccessDeniedException
        }
    }
    return estimatedSize;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:Store.java

示例5: main

import org.apache.lucene.store.Directory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception{
    File samplesFilesDir = new File("build/classes/ensemble/");
    File indexDir = new File("build/classes/ensemble/search/index");
    File docDir = new File("../../../artifacts/sdk/docs/api");
    File samplesDir = new File("src/ensemble/samples");
    // create index
    ///System.out.println("Indexing to directory '" + indexDir + "'...");
    long start = System.currentTimeMillis();
    Directory dir = FSDirectory.open(indexDir);
    Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_31);
    IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_31, analyzer);
    iwc.setOpenMode(OpenMode.CREATE);
    // generate and write index of all java doc and samples
    IndexWriter writer = new IndexWriter(dir, iwc);

    List<String> samplesFileList = new ArrayList<String>();

    indexSamples(writer, samplesDir, samplesFileList);
    try {
        indexJavaDocAllClasses(writer, docDir);
    } catch (Exception e) {
        System.out.println("\nWarning: We were not able to locate the JavaFX API documentation for your build environment.\n"
                + "Ensemble search will not include the API documentation.\n"); 
    }
    writer.close();
    // create a listAll.txt file that is used
    FileWriter listAllOut = new FileWriter(new File(indexDir,"listAll.txt"));
    for (String fileName: dir.listAll()) {
        if (!"listAll.txt".equals(fileName)) { // don't include the "listAll.txt" file
            Long length = dir.fileLength(fileName);
            listAllOut.write(fileName);
            listAllOut.write(':');
            listAllOut.write(length.toString());
            listAllOut.write('\n');
        }
    }
    listAllOut.flush();
    listAllOut.close();

    FileWriter sampleFilesCache = new FileWriter(new File(samplesFilesDir,"samplesAll.txt"));
    for (String oneSample: samplesFileList) {
            sampleFilesCache.write(oneSample);
            sampleFilesCache.write('\n');
    }
    sampleFilesCache.flush();
    sampleFilesCache.close();

    // print time taken
    ///System.out.println(System.currentTimeMillis() - start + " total milliseconds");
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:51,代码来源:BuildEnsembleSearchIndex.java

示例6: listCommits

import org.apache.lucene.store.Directory; //导入方法依赖的package包/类
/** Returns all commit points that exist in the Directory.
 *  Normally, because the default is {@link
 *  KeepOnlyLastCommitDeletionPolicy}, there would be only
 *  one commit point.  But if you're using a custom {@link
 *  IndexDeletionPolicy} then there could be many commits.
 *  Once you have a given commit, you can open a reader on
 *  it by calling {@link DirectoryReader#open(IndexCommit)}
 *  There must be at least one commit in
 *  the Directory, else this method throws {@link
 *  IndexNotFoundException}.  Note that if a commit is in
 *  progress while this method is running, that commit
 *  may or may not be returned.
 *  
 *  @return a sorted list of {@link IndexCommit}s, from oldest 
 *  to latest. */
public static List<IndexCommit> listCommits(Directory dir) throws IOException {
  final String[] files = dir.listAll();

  List<IndexCommit> commits = new ArrayList<>();

  SegmentInfos latest = new SegmentInfos();
  latest.read(dir);
  final long currentGen = latest.getGeneration();

  commits.add(new StandardDirectoryReader.ReaderCommit(latest, dir));

  for(int i=0;i<files.length;i++) {

    final String fileName = files[i];

    if (fileName.startsWith(IndexFileNames.SEGMENTS) &&
        !fileName.equals(IndexFileNames.SEGMENTS_GEN) &&
        SegmentInfos.generationFromSegmentsFileName(fileName) < currentGen) {

      SegmentInfos sis = new SegmentInfos();
      try {
        // IOException allowed to throw there, in case
        // segments_N is corrupt
        sis.read(dir, fileName);
      } catch (FileNotFoundException | NoSuchFileException fnfe) {
        // LUCENE-948: on NFS (and maybe others), if
        // you have writers switching back and forth
        // between machines, it's very likely that the
        // dir listing will be stale and will claim a
        // file segments_X exists when in fact it
        // doesn't.  So, we catch this and handle it
        // as if the file does not exist
        sis = null;
      }

      if (sis != null)
        commits.add(new StandardDirectoryReader.ReaderCommit(sis, dir));
    }
  }

  // Ensure that the commit points are sorted in ascending order.
  Collections.sort(commits);

  return commits;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:61,代码来源:DirectoryReader.java

示例7: indexExists

import org.apache.lucene.store.Directory; //导入方法依赖的package包/类
/**
 * Returns <code>true</code> if an index likely exists at
 * the specified directory.  Note that if a corrupt index
 * exists, or if an index in the process of committing 
 * @param  directory the directory to check for an index
 * @return <code>true</code> if an index exists; <code>false</code> otherwise
 */
public static boolean indexExists(Directory directory) throws IOException {
  // LUCENE-2812, LUCENE-2727, LUCENE-4738: this logic will
  // return true in cases that should arguably be false,
  // such as only IW.prepareCommit has been called, or a
  // corrupt first commit, but it's too deadly to make
  // this logic "smarter" and risk accidentally returning
  // false due to various cases like file description
  // exhaustion, access denied, etc., because in that
  // case IndexWriter may delete the entire index.  It's
  // safer to err towards "index exists" than try to be
  // smart about detecting not-yet-fully-committed or
  // corrupt indices.  This means that IndexWriter will
  // throw an exception on such indices and the app must
  // resolve the situation manually:
  String[] files;
  try {
    files = directory.listAll();
  } catch (NoSuchDirectoryException nsde) {
    // Directory does not exist --> no index exists
    return false;
  }

  // Defensive: maybe a Directory impl returns null
  // instead of throwing NoSuchDirectoryException:
  if (files != null) {
    String prefix = IndexFileNames.SEGMENTS + "_";
    for(String file : files) {
      if (file.startsWith(prefix) || file.equals(IndexFileNames.SEGMENTS_GEN)) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:42,代码来源:DirectoryReader.java


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