lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject cvs commit: jakarta-lucene/src/java/org/apache/lucene/index IndexReader.java
Date Tue, 25 Dec 2001 19:14:40 GMT
otis        01/12/25 11:14:40

  Modified:    src/java/org/apache/lucene/index IndexReader.java
  Log:
  - Added methods:
    public static boolean indexExists(String directory);
    public static boolean indexExists(File directory);
    public static boolean indexExists(Directory directory);
    public static boolean isLocked(Directory directory);
    public static void unlock(Directory directory);
  
  Revision  Changes    Path
  1.3       +64 -6     jakarta-lucene/src/java/org/apache/lucene/index/IndexReader.java
  
  Index: IndexReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/index/IndexReader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IndexReader.java	2001/09/27 16:27:01	1.2
  +++ IndexReader.java	2001/12/25 19:14:40	1.3
  @@ -123,13 +123,47 @@
       return directory.fileModified("segments");
     }
   
  +  /**
  +   * Returns <code>true</code> if an index exists at the specified directory.
  +   * If the directory does not exist or if there is no index in it.
  +   * <code>false</code> is returned.
  +   * @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(String directory) {
  +    return (new File(directory, "segments")).exists();
  +  }
  +
  +  /**
  +   * Returns <code>true</code> if an index exists at the specified directory.
  +   * If the directory does not exist or if there is no index in it.
  +   * @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(File directory) {
  +    return (new File(directory, "segments")).exists();
  +  }
  +
  +  /**
  +   * Returns <code>true</code> if an index exists at the specified directory.
  +   * If the directory does not exist or if there is no index in it.
  +   * @param  directory the directory to check for an index
  +   * @return <code>true</code> if an index exists; <code>false</code>
otherwise
  +   * @throws IOException if there is a problem with accessing the index
  +   */
  +  public static boolean indexExists(Directory directory) throws IOException {
  +    return directory.fileExists("segments");
  +  }
  +
     /** Returns the number of documents in this index. */
     abstract public int numDocs();
  +
     /** Returns one greater than the largest possible document number.
       This may be used to, e.g., determine how big to allocate an array which
       will have an element for every document number in an index.
      */
     abstract public int maxDoc();
  +
     /** Returns the stored fields of the <code>n</code><sup>th</sup>
         <code>Document</code> in this index. */
     abstract public Document document(int n) throws IOException;
  @@ -145,12 +179,13 @@
   
     /** Returns an enumeration of all the terms in the index.
       The enumeration is ordered by Term.compareTo().  Each term
  -    is greater than all that precede it in the enumeration. 
  +    is greater than all that precede it in the enumeration.
      */
     abstract public TermEnum terms() throws IOException;
  +
     /** Returns an enumeration of all terms after a given term.
       The enumeration is ordered by Term.compareTo().  Each term
  -    is greater than all that precede it in the enumeration. 
  +    is greater than all that precede it in the enumeration.
      */
     abstract public TermEnum terms(Term t) throws IOException;
   
  @@ -213,8 +248,31 @@
       return n;
     }
   
  -  /** Closes files associated with this index.
  -    Also saves any new deletions to disk.
  -    No other methods should be called after this has been called. */
  -  abstract public void close() throws IOException;
  +  /**
  +   * Closes files associated with this index.
  +   * Also saves any new deletions to disk.
  +   * No other methods should be called after this has been called.
  +   */
  +    abstract public void close() throws IOException;
  +
  +  /**
  +   * Returns <code>true</code> iff the index in the named directory is
  +   * currently locked.
  +   * @param directory the directory to check for a lock
  +   * @throws IOException if there is a problem with accessing the index
  +   */
  +    public static boolean isLocked(Directory directory) throws IOException {
  +	return directory.fileExists("write.lock");
  +    }
  +
  +   /**
  +    * Forcibly unlocks the index in the named directory.
  +    * <P>
  +    * Caution: this should only be used by failure recovery code,
  +    * when it is known that no other process nor thread is in fact
  +    * currently accessing this index.
  +    */
  +    public static void unlock(Directory directory) throws IOException {
  +	directory.deleteFile("write.lock");
  +    }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>


Mime
View raw message