Example #1
0
			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);
				}
			}
 /// <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
     }
 }
Example #3
0
            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));
                }
            }
        /// <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());
        }
		/// <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();
		}