Package org.apache.lucene.index

Examples of org.apache.lucene.index.IndexFileNameFilter


    // Then go through all files in the Directory that are
    // Lucene index files, and add to deletable if they are
    // not referenced by the current segments info:

    String segmentsInfosFileName = segmentInfos.getCurrentSegmentFileName();
    IndexFileNameFilter filter = IndexFileNameFilter.getFilter();

    String[] files = directory.list();

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

      if (filter.accept(null, files[i]) && !files[i].equals(segmentsInfosFileName) && !files[i].equals(IndexFileNames.SEGMENTS_GEN)) {

        String segmentName;
        String extension;

        // First remove any extension:
        int loc = files[i].indexOf('.');
        if (loc != -1) {
          extension = files[i].substring(1+loc);
          segmentName = files[i].substring(0, loc);
        } else {
          extension = null;
          segmentName = files[i];
        }

        // Then, remove any generation count:
        loc = segmentName.indexOf('_', 1);
        if (loc != -1) {
          segmentName = segmentName.substring(0, loc);
        }

        // Delete this file if it's not a "current" segment,
        // or, it is a single index file but there is now a
        // corresponding compound file:
        boolean doDelete = false;

        if (!current.containsKey(segmentName)) {
          // Delete if segment is not referenced:
          doDelete = true;
        } else {
          // OK, segment is referenced, but file may still
          // be orphan'd:
          SegmentInfo info = (SegmentInfo) current.get(segmentName);

          if (filter.isCFSFile(files[i]) && info.getUseCompoundFile()) {
            // This file is in fact stored in a CFS file for
            // this segment:
            doDelete = true;
          } else {
           
View Full Code Here


    protected boolean createIndexDirectory(final File file) {
        /*
         * use a lucene filename filter to figure out if there is an existing
         * index in the defined directory
         */
        String[] luceneFiles = file.list(new IndexFileNameFilter());
        return !(luceneFiles.length > 0);

    }
View Full Code Here

        throw new IOException("Cannot create directory: " + directory);

    if (!directory.isDirectory())
      throw new IOException(directory + " not a directory");

    String[] files = directory.list(new IndexFileNameFilter());            // clear old files
    for (int i = 0; i < files.length; i++) {
      File file = new File(directory, files[i]);
      if (!file.delete())
        throw new IOException("Cannot delete " + files[i]);
    }
View Full Code Here

        throw new IOException("Cannot create directory: " + directory);

    if (!directory.isDirectory())
      throw new IOException(directory + " not a directory");

    String[] files = directory.list(new IndexFileNameFilter());            // clear old files
    if (files == null)
      throw new IOException("Cannot read directory " + directory.getAbsolutePath());
    for (int i = 0; i < files.length; i++) {
      File file = new File(directory, files[i]);
      if (!file.delete())
View Full Code Here

   * @throws IOException
   */
  public static void copy(Directory src, Directory dest, boolean closeDirSrc) throws IOException {
    final String[] files = src.listAll();

    IndexFileNameFilter filter = IndexFileNameFilter.getFilter();

    byte[] buf = new byte[BufferedIndexOutput.BUFFER_SIZE];
    for (int i = 0; i < files.length; i++) {

      if (!filter.accept(null, files[i]))
        continue;

      IndexOutput os = null;
      IndexInput is = null;
      try {
View Full Code Here

  }
 
  private RAMDirectory(Directory dir, boolean closeDir) throws IOException {
    this();

    IndexFileNameFilter filter = IndexFileNameFilter.getFilter();
    for (String file : dir.listAll()) {
      if (filter.accept(null, file)) {
        dir.copy(this, file, file);
      }
    }
    if (closeDir) {
      dir.close();
View Full Code Here

   * }
   * </pre>
   */
  @Deprecated
  public static void copy(Directory src, Directory dest, boolean closeDirSrc) throws IOException {
    IndexFileNameFilter filter = IndexFileNameFilter.getFilter();
    for (String file : src.listAll()) {
      if (filter.accept(null, file)) {
        src.copy(dest, file, file);
      }
    }
    if (closeDirSrc) {
      src.close();
View Full Code Here

  private void save(String dir) {
    File folder = new File(dir);
    try {
      Directory dest = FSDirectory.open(folder);
      IndexFileNameFilter filter = IndexFileNameFilter.getFilter();
      for (String file : this.index.listAll()) {
        if (filter.accept(null, file)) {
          this.index.copy(dest, file, file);
        }
      }
    } catch (IOException ioe) {
      jlog.severe("Couldn't copy index:\n\t" + ioe);
View Full Code Here

         * IOExceptions while Lucene was trying to recreate the index. Making sure
         * the index files are deleted will prevent these situations from occuring.
         */
        if (clearIndex) {
          File directory = new File(path);
          File[] indexFiles = directory.listFiles(new IndexFileNameFilter());
          try {
            for (File file : indexFiles) {
              file.delete();
            }
          } catch (Exception e) {
View Full Code Here

  }
 
  private RAMDirectory(Directory dir, boolean closeDir) throws IOException {
    this();

    IndexFileNameFilter filter = IndexFileNameFilter.getFilter();
    for (String file : dir.listAll()) {
      if (filter.accept(null, file)) {
        dir.copy(this, file, file);
      }
    }
    if (closeDir) {
      dir.close();
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.IndexFileNameFilter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.