public FileSwitchDirectory(System.Collections.Hashtable primaryExtensions, Directory primaryDir, Directory secondaryDir, bool doClose) { this.primaryExtensions = primaryExtensions; this.primaryDir = primaryDir; this.secondaryDir = secondaryDir; this.doClose = doClose; this.lockFactory = primaryDir.GetLockFactory(); }
/// <summary> Reads version number from segments files. The version number is /// initialized with a timestamp and then increased by one for each change of /// the index. /// /// </summary> /// <param name="directory">where the index resides. /// </param> /// <returns> version number. /// </returns> /// <throws> CorruptIndexException if the index is corrupt </throws> /// <throws> IOException if there is a low-level IO error </throws> public static long GetCurrentVersion(Directory directory) { return SegmentInfos.ReadCurrentVersion(directory); }
/// <summary> Reads commitUserData, previously passed to {@link /// IndexWriter#Commit(Map)}, from current index /// segments file. This will return null if {@link /// IndexWriter#Commit(Map)} has never been called for /// this index. /// /// </summary> /// <param name="directory">where the index resides. /// </param> /// <returns> commit userData. /// </returns> /// <throws> CorruptIndexException if the index is corrupt </throws> /// <throws> IOException if there is a low-level IO error </throws> /// <summary> /// </summary> /// <seealso cref="GetCommitUserData()"> /// </seealso> public static System.Collections.Generic.IDictionary<string, string> GetCommitUserData(Directory directory) { return SegmentInfos.ReadCurrentUserData(directory); }
private static IndexReader Open(Directory directory, IndexDeletionPolicy deletionPolicy, IndexCommit commit, bool readOnly, int termInfosIndexDivisor) { return DirectoryReader.Open(directory, deletionPolicy, commit, readOnly, termInfosIndexDivisor); }
/// <summary> Returns the time the index in the named directory was last modified. /// Do not use this to check whether the reader is still up-to-date, use /// {@link #IsCurrent()} instead. /// </summary> /// <throws> CorruptIndexException if the index is corrupt </throws> /// <throws> IOException if there is a low-level IO error </throws> public static long LastModified(Directory directory2) { return (long) ((System.Int64) new AnonymousClassFindSegmentsFile(directory2, directory2).Run()); }
/// <summary>Expert: returns an IndexReader reading the index in /// the given Directory, with a custom {@link /// IndexDeletionPolicy}. You should pass readOnly=true, /// since it gives much better concurrent performance, /// unless you intend to do write operations (delete /// documents or change norms) with the reader. /// </summary> /// <param name="directory">the index directory /// </param> /// <param name="deletionPolicy">a custom deletion policy (only used /// if you use this reader to perform deletes or to set /// norms); see {@link IndexWriter} for details. /// </param> /// <param name="readOnly">true if no changes (deletions, norms) will be made with this IndexReader /// </param> /// <throws> CorruptIndexException if the index is corrupt </throws> /// <throws> IOException if there is a low-level IO error </throws> public static IndexReader Open(Directory directory, IndexDeletionPolicy deletionPolicy, bool readOnly) { return Open(directory, deletionPolicy, null, readOnly, DEFAULT_TERMS_INDEX_DIVISOR); }
/// <summary>Expert: returns an IndexReader reading the index in /// the given Directory, with a custom {@link /// IndexDeletionPolicy}. You should pass readOnly=true, /// since it gives much better concurrent performance, /// unless you intend to do write operations (delete /// documents or change norms) with the reader. /// </summary> /// <param name="directory">the index directory /// </param> /// <param name="deletionPolicy">a custom deletion policy (only used /// if you use this reader to perform deletes or to set /// norms); see {@link IndexWriter} for details. /// </param> /// <param name="readOnly">true if no changes (deletions, norms) will be made with this IndexReader /// </param> /// <param name="termInfosIndexDivisor">Subsamples which indexed /// terms are loaded into RAM. This has the same effect as {@link /// IndexWriter#setTermIndexInterval} except that setting /// must be done at indexing time while this setting can be /// set per reader. When set to N, then one in every /// N*termIndexInterval terms in the index is loaded into /// memory. By setting this to a value > 1 you can reduce /// memory usage, at the expense of higher latency when /// loading a TermInfo. The default value is 1. Set this /// to -1 to skip loading the terms index entirely. /// </param> /// <throws> CorruptIndexException if the index is corrupt </throws> /// <throws> IOException if there is a low-level IO error </throws> public static IndexReader Open(Directory directory, IndexDeletionPolicy deletionPolicy, bool readOnly, int termInfosIndexDivisor) { return Open(directory, deletionPolicy, null, readOnly, termInfosIndexDivisor); }
protected internal IndexReader(Directory directory):this() { this.directory = directory; }
public static IndexReader Open(Directory directory) { return Open(directory, null, null, false, DEFAULT_TERMS_INDEX_DIVISOR); }
public static void Unlock(Directory directory) { directory.MakeLock(IndexWriter.WRITE_LOCK_NAME).Release(); }
/// <summary>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 IndexReader#Open(IndexCommit)} /// There must be at least one commit in /// the Directory, else this method throws {@link /// java.io.IOException}. Note that if a commit is in /// progress while this method is running, that commit /// may or may not be returned array. /// </summary> public static System.Collections.ICollection ListCommits(Directory dir) { return DirectoryReader.ListCommits(dir); }
public static bool IsLocked(Directory directory) { return directory.MakeLock(IndexWriter.WRITE_LOCK_NAME).IsLocked(); }
/// <summary> 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. /// </summary> /// <param name="directory">the directory to check for an index /// </param> /// <returns> <code>true</code> if an index exists; <code>false</code> otherwise /// </returns> /// <throws> IOException if there is a problem with accessing the index </throws> public static bool IndexExists(Directory directory) { return SegmentInfos.GetCurrentSegmentGeneration(directory) != - 1; }
/// <summary> Copy contents of a directory src to a directory dest. /// If a file in src already exists in dest then the /// one in dest will be blindly overwritten. /// /// <p/><b>NOTE:</b> the source directory cannot change /// while this method is running. Otherwise the results /// are undefined and you could easily hit a /// FileNotFoundException. /// /// <p/><b>NOTE:</b> this method only copies files that look /// like index files (ie, have extensions matching the /// known extensions of index files). /// /// </summary> /// <param name="src">source directory /// </param> /// <param name="dest">destination directory /// </param> /// <param name="closeDirSrc">if <code>true</code>, call {@link #Close()} method on source directory /// </param> /// <throws> IOException </throws> public static void Copy(Directory src, Directory dest, bool closeDirSrc) { System.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_Renamed = null; try { // create file in dest directory os = dest.CreateOutput(files[i]); // read current file is_Renamed = src.OpenInput(files[i]); // and copy to dest directory long len = is_Renamed.Length(); long readCount = 0; while (readCount < len) { int toRead = readCount + BufferedIndexOutput.BUFFER_SIZE > len?(int) (len - readCount):BufferedIndexOutput.BUFFER_SIZE; is_Renamed.ReadBytes(buf, 0, toRead); os.WriteBytes(buf, toRead); readCount += toRead; } } finally { // graceful cleanup try { if (os != null) os.Close(); } finally { if (is_Renamed != null) is_Renamed.Close(); } } } if (closeDirSrc) src.Close(); }
private RAMDirectory(Directory dir, bool closeDir):this() { Directory.Copy(dir, this, closeDir); }
/// <summary> Creates a new <code>RAMDirectory</code> instance from a different /// <code>Directory</code> implementation. This can be used to load /// a disk-based index into memory. /// <p/> /// This should be used only with indices that can fit into memory. /// <p/> /// Note that the resulting <code>RAMDirectory</code> instance is fully /// independent from the original <code>Directory</code> (it is a /// complete copy). Any subsequent changes to the /// original <code>Directory</code> will not be visible in the /// <code>RAMDirectory</code> instance. /// /// </summary> /// <param name="dir">a <code>Directory</code> value /// </param> /// <exception cref="IOException">if an error occurs /// </exception> public RAMDirectory(Directory dir):this(dir, false) { }