public override System.Object DoBody() { SegmentInfos infos = new SegmentInfos(); infos.Read(directory); if (infos.Count == 1) { // index is optimized return new SegmentReader(infos, infos.Info(0), closeDirectory); } else { Monodoc.Lucene.Net.Index.IndexReader[] readers = new Monodoc.Lucene.Net.Index.IndexReader[infos.Count]; for (int i = 0; i < infos.Count; i++) readers[i] = new SegmentReader(infos.Info(i)); return new MultiReader(directory, infos, closeDirectory, readers); } }
public /*internal*/ SegmentReader(SegmentInfos sis, SegmentInfo si, bool closeDir) : base(si.dir, sis, closeDir) { Initialize(si); }
/// <summary> Constructor used if IndexReader is owner of its directory. /// If IndexReader is owner of its directory, it locks its directory in case of write operations. /// /// </summary> /// <param name="directory">Directory where IndexReader files reside. /// </param> /// <param name="segmentInfos">Used for write-l /// </param> /// <param name="">closeDirectory /// </param> internal IndexReader(Directory directory, SegmentInfos segmentInfos, bool closeDirectory) { this.directory = directory; this.segmentInfos = segmentInfos; directoryOwner = true; this.closeDirectory = closeDirectory; stale = false; hasChanges = false; writeLock = null; }
/// <summary>Construct reading the named set of readers. </summary> public /*internal*/ MultiReader(Directory directory, SegmentInfos sis, bool closeDirectory, Monodoc.Lucene.Net.Index.IndexReader[] subReaders):base(directory, sis, closeDirectory) { Initialize(subReaders); }
/// <summary>Merges all segments from an array of indexes into this index. /// /// <p>This may be used to parallelize batch indexing. A large document /// collection can be broken into sub-collections. Each sub-collection can be /// indexed in parallel, on a different thread, process or machine. The /// complete index can then be created by merging sub-collection indexes /// with this method. /// /// <p>After this completes, the index is optimized. /// </summary> public virtual void AddIndexes(Directory[] dirs) { lock (this) { Optimize(); // start with zero or 1 seg for (int i = 0; i < dirs.Length; i++) { SegmentInfos sis = new SegmentInfos(); // read infos from dir sis.Read(dirs[i]); for (int j = 0; j < sis.Count; j++) { segmentInfos.Add(sis.Info(j)); // add each info } } Optimize(); // final cleanup } }
/// <summary> Current version number from segments file.</summary> public static long ReadCurrentVersion(Directory directory) { InputStream input = directory.OpenFile("segments"); int format = 0; long version = 0; try { format = input.ReadInt(); if (format < 0) { if (format < FORMAT) throw new System.IO.IOException("Unknown format version: " + format); version = input.ReadLong(); // read version } } finally { input.Close(); } if (format < 0) return version; // We cannot be sure about the format of the file. // Therefore we have to read the whole file and cannot simply seek to the version entry. SegmentInfos sis = new SegmentInfos(); sis.Read(directory); return sis.GetVersion(); }