private void  DeleteFiles(System.Collections.ArrayList files, Directory directory)
 {
     for (int i = 0; i < files.Count; i++)
     {
         directory.DeleteFile((System.String)files[i]);
     }
 }
예제 #2
0
		/// <summary> </summary>
		/// <param name="directory">The directory to write the document information to
		/// </param>
		/// <param name="analyzer">The analyzer to use for the document
		/// </param>
		/// <param name="similarity">The Similarity function
		/// </param>
		/// <param name="maxFieldLength">The maximum number of tokens a Field may have
		/// </param>
		public /*internal*/ DocumentWriter(Directory directory, Analyzer analyzer, Similarity similarity, int maxFieldLength)
		{
			this.directory = directory;
			this.analyzer = analyzer;
			this.similarity = similarity;
			this.maxFieldLength = maxFieldLength;
		}
예제 #3
0
 /// <summary> </summary>
 /// <param name="directory">The directory to write the document information to
 /// </param>
 /// <param name="analyzer">The analyzer to use for the document
 /// </param>
 /// <param name="similarity">The Similarity function
 /// </param>
 /// <param name="maxFieldLength">The maximum number of tokens a Field may have
 /// </param>
 public /*internal*/ DocumentWriter(Directory directory, Analyzer analyzer, Similarity similarity, int maxFieldLength)
 {
     this.directory      = directory;
     this.analyzer       = analyzer;
     this.similarity     = similarity;
     this.maxFieldLength = maxFieldLength;
 }
        public void  Write(Directory directory)
        {
            OutputStream output = directory.CreateFile("segments.new");

            try
            {
                output.WriteInt(FORMAT);     // write FORMAT
                output.WriteLong(++version); // every write changes the index
                output.WriteInt(counter);    // write counter
                output.WriteInt(Count);      // write infos
                for (int i = 0; i < Count; i++)
                {
                    SegmentInfo si = Info(i);
                    output.WriteString(si.name);
                    output.WriteInt(si.docCount);
                }
            }
            finally
            {
                output.Close();
            }

            // install new segment info
            directory.RenameFile("segments.new", "segments");
        }
예제 #5
0
        /// <summary> Returns <code>true</code> iff the index in the named directory is
        /// currently locked.
        /// </summary>
        /// <param name="directory">the directory to check for a lock
        /// </param>
        /// <throws>  IOException if there is a problem with accessing the index </throws>
        public static bool IsLocked(System.String directory)
        {
            Directory dir    = FSDirectory.GetDirectory(directory, false);
            bool      result = IsLocked(dir);

            dir.Close();
            return(result);
        }
예제 #6
0
 private static Monodoc.Lucene.Net.Index.IndexReader Open(Directory directory, bool closeDirectory)
 {
     lock (directory)
     {
         // in- & inter-process sync
         return((Monodoc.Lucene.Net.Index.IndexReader) new AnonymousClassWith(directory, closeDirectory, directory.MakeLock(IndexWriter.COMMIT_LOCK_NAME), IndexWriter.COMMIT_LOCK_TIMEOUT).Run());
     }
 }
예제 #7
0
        /// <summary> Reads version number from segments files. The version number counts the
        /// number of changes of the index.
        ///
        /// </summary>
        /// <param name="directory">where the index resides.
        /// </param>
        /// <returns> version number.
        /// </returns>
        /// <throws>  IOException if segments file cannot be read </throws>
        public static long GetCurrentVersion(System.IO.FileInfo directory)
        {
            Directory dir     = FSDirectory.GetDirectory(directory, false);
            long      version = GetCurrentVersion(dir);

            dir.Close();
            return(version);
        }
예제 #8
0
        public /*internal*/ FieldsReader(Directory d, System.String segment, FieldInfos fn)
        {
            fieldInfos = fn;

            fieldsStream = d.OpenFile(segment + ".fdt");
            indexStream  = d.OpenFile(segment + ".fdx");

            size = (int)(indexStream.Length() / 8);
        }
		public /*internal*/ FieldsReader(Directory d, System.String segment, FieldInfos fn)
		{
			fieldInfos = fn;
			
			fieldsStream = d.OpenFile(segment + ".fdt");
			indexStream = d.OpenFile(segment + ".fdx");
			
			size = (int) (indexStream.Length() / 8);
		}
        public /*internal*/ TermInfosReader(Directory dir, System.String seg, FieldInfos fis)
        {
            directory  = dir;
            segment    = seg;
            fieldInfos = fis;

            origEnum = new SegmentTermEnum(directory.OpenFile(segment + ".tis"), fieldInfos, false);
            size     = origEnum.size;
            ReadIndex();
        }
예제 #11
0
		public /*internal*/ TermInfosReader(Directory dir, System.String seg, FieldInfos fis)
		{
			directory = dir;
			segment = seg;
			fieldInfos = fis;
			
			origEnum = new SegmentTermEnum(directory.OpenFile(segment + ".tis"), fieldInfos, false);
			size = origEnum.size;
			ReadIndex();
		}
예제 #12
0
		private void  Initialize(Directory directory, System.String segment, FieldInfos fis, bool isi)
		{
			fieldInfos = fis;
			isIndex = isi;
			output = directory.CreateFile(segment + (isIndex?".tii":".tis"));
			output.WriteInt(FORMAT); // write format
			output.WriteLong(0); // leave space for size
			output.WriteInt(indexInterval); // write indexInterval
			output.WriteInt(skipInterval); // write skipInterval
		}
예제 #13
0
 private void  Initialize(Directory directory, System.String segment, FieldInfos fis, bool isi)
 {
     fieldInfos = fis;
     isIndex    = isi;
     output     = directory.CreateFile(segment + (isIndex?".tii":".tis"));
     output.WriteInt(FORMAT);         // write format
     output.WriteLong(0);             // leave space for size
     output.WriteInt(indexInterval);  // write indexInterval
     output.WriteInt(skipInterval);   // write skipInterval
 }
예제 #14
0
 /// <summary> Constructor used if IndexReader is not owner of its directory.
 /// This is used for IndexReaders that are used within other IndexReaders that take care or locking directories.
 ///
 /// </summary>
 /// <param name="directory">Directory where IndexReader files reside.
 /// </param>
 protected internal IndexReader(Directory directory)
 {
     this.directory = directory;
     segmentInfos   = null;
     directoryOwner = false;
     closeDirectory = false;
     stale          = false;
     hasChanges     = false;
     writeLock      = null;
 }
예제 #15
0
 /// <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;
 }
예제 #16
0
		/// <summary> Construct a FieldInfos object using the directory and the name of the file
		/// InputStream
		/// </summary>
		/// <param name="d">The directory to open the InputStream from
		/// </param>
		/// <param name="name">The name of the file to open the InputStream from in the Directory
		/// </param>
		/// <throws>  IOException </throws>
		/// <summary> 
		/// </summary>
		/// <seealso cref="#read">
		/// </seealso>
		public /*internal*/ FieldInfos(Directory d, System.String name)
		{
			InputStream input = d.OpenFile(name);
			try
			{
				Read(input);
			}
			finally
			{
				input.Close();
			}
		}
예제 #17
0
		/// <summary>Create the compound stream in the specified file. The file name is the
		/// entire name (no extensions are added).
		/// </summary>
		public CompoundFileWriter(Directory dir, System.String name)
		{
			if (dir == null)
				throw new System.ArgumentException("Missing directory");
			if (name == null)
				throw new System.ArgumentException("Missing name");
			
			directory = dir;
			fileName = name;
			ids = new System.Collections.Hashtable();
			entries = new System.Collections.ArrayList();
		}
예제 #18
0
        public CompoundFileReader(Directory dir, System.String name)
        {
            directory = dir;
            fileName  = name;

            bool success = false;

            try
            {
                stream = dir.OpenFile(name);

                // read the directory and init files
                int       count = stream.ReadVInt();
                FileEntry entry = null;
                for (int i = 0; i < count; i++)
                {
                    long          offset = stream.ReadLong();
                    System.String id     = stream.ReadString();

                    if (entry != null)
                    {
                        // set length of the previous entry
                        entry.length = offset - entry.offset;
                    }

                    entry        = new FileEntry();
                    entry.offset = offset;
                    entries[id]  = entry;
                }

                // set the length of the final entry
                if (entry != null)
                {
                    entry.length = stream.Length() - entry.offset;
                }

                success = true;
            }
            finally
            {
                if (!success && (stream != null))
                {
                    try
                    {
                        stream.Close();
                    }
                    catch (System.IO.IOException e)
                    {
                    }
                }
            }
        }
		public CompoundFileReader(Directory dir, System.String name)
		{
			directory = dir;
			fileName = name;
			
			bool success = false;
			
			try
			{
				stream = dir.OpenFile(name);
				
				// read the directory and init files
				int count = stream.ReadVInt();
				FileEntry entry = null;
				for (int i = 0; i < count; i++)
				{
					long offset = stream.ReadLong();
					System.String id = stream.ReadString();
					
					if (entry != null)
					{
						// set length of the previous entry
						entry.length = offset - entry.offset;
					}
					
					entry = new FileEntry();
					entry.offset = offset;
					entries[id] = entry;
				}
				
				// set the length of the final entry
				if (entry != null)
				{
					entry.length = stream.Length() - entry.offset;
				}
				
				success = true;
			}
			finally
			{
				if (!success && (stream != null))
				{
					try
					{
						stream.Close();
					}
					catch (System.IO.IOException e)
					{
					}
				}
			}
		}
예제 #20
0
        /// <summary> Construct a FieldInfos object using the directory and the name of the file
        /// InputStream
        /// </summary>
        /// <param name="d">The directory to open the InputStream from
        /// </param>
        /// <param name="name">The name of the file to open the InputStream from in the Directory
        /// </param>
        /// <throws>  IOException </throws>
        /// <summary>
        /// </summary>
        /// <seealso cref="#read">
        /// </seealso>
        public /*internal*/ FieldInfos(Directory d, System.String name)
        {
            InputStream input = d.OpenFile(name);

            try
            {
                Read(input);
            }
            finally
            {
                input.Close();
            }
        }
예제 #21
0
        public void  Write(Directory d, System.String name)
        {
            OutputStream output = d.CreateFile(name);

            try
            {
                Write(output);
            }
            finally
            {
                output.Close();
            }
        }
예제 #22
0
		/// <summary>Create term vectors writer for the specified segment in specified
		/// directory.  A new TermVectorsWriter should be created for each
		/// segment. The parameter <code>maxFields</code> indicates how many total
		/// fields are found in this document. Not all of these fields may require
		/// termvectors to be stored, so the number of calls to
		/// <code>openField</code> is less or equal to this number.
		/// </summary>
		public TermVectorsWriter(Directory directory, System.String segment, FieldInfos fieldInfos)
		{
			// Open files for TermVector storage
			tvx = directory.CreateFile(segment + TVX_EXTENSION);
			tvx.WriteInt(FORMAT_VERSION);
			tvd = directory.CreateFile(segment + TVD_EXTENSION);
			tvd.WriteInt(FORMAT_VERSION);
			tvf = directory.CreateFile(segment + TVF_EXTENSION);
			tvf.WriteInt(FORMAT_VERSION);
			
			this.fieldInfos = fieldInfos;
			fields = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(fieldInfos.Size()));
			terms = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
		}
        /// <summary>Create term vectors writer for the specified segment in specified
        /// directory.  A new TermVectorsWriter should be created for each
        /// segment. The parameter <code>maxFields</code> indicates how many total
        /// fields are found in this document. Not all of these fields may require
        /// termvectors to be stored, so the number of calls to
        /// <code>openField</code> is less or equal to this number.
        /// </summary>
        public TermVectorsWriter(Directory directory, System.String segment, FieldInfos fieldInfos)
        {
            // Open files for TermVector storage
            tvx = directory.CreateFile(segment + TVX_EXTENSION);
            tvx.WriteInt(FORMAT_VERSION);
            tvd = directory.CreateFile(segment + TVD_EXTENSION);
            tvd.WriteInt(FORMAT_VERSION);
            tvf = directory.CreateFile(segment + TVF_EXTENSION);
            tvf.WriteInt(FORMAT_VERSION);

            this.fieldInfos = fieldInfos;
            fields          = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(fieldInfos.Size()));
            terms           = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
        }
 private void  OpenNorms(Directory cfsDir)
 {
     for (int i = 0; i < fieldInfos.Size(); i++)
     {
         FieldInfo fi = fieldInfos.FieldInfo(i);
         if (fi.isIndexed)
         {
             System.String fileName = segment + ".f" + fi.number;
             // look first for re-written file, then in compound format
             Directory d = Directory().FileExists(fileName)?Directory():cfsDir;
             norms[fi.name] = new Norm(this, d.OpenFile(fileName), fi.number);
         }
     }
 }
        public void  Read(Directory directory)
        {
            InputStream input = directory.OpenFile("segments");

            try
            {
                int format = input.ReadInt();
                if (format < 0)
                {
                    // file contains explicit format info
                    // check that it is a format we can understand
                    if (format < FORMAT)
                    {
                        throw new System.IO.IOException("Unknown format version: " + format);
                    }
                    version = input.ReadLong(); // read version
                    counter = input.ReadInt();  // read counter
                }
                else
                {
                    // file is in old format without explicit format info
                    counter = format;
                }

                for (int i = input.ReadInt(); i > 0; i--)
                {
                    // read segmentInfos
                    SegmentInfo si = new SegmentInfo(input.ReadString(), input.ReadInt(), directory);
                    Add(si);
                }

                if (format >= 0)
                {
                    // in old format the version number may be at the end of the file
                    if (input.GetFilePointer() >= input.Length())
                    {
                        version = 0;
                    }
                    // old file format without version number
                    else
                    {
                        version = input.ReadLong(); // read version
                    }
                }
            }
            finally
            {
                input.Close();
            }
        }
		public /*internal*/ TermVectorsReader(Directory d, System.String segment, FieldInfos fieldInfos)
		{
			if (d.FileExists(segment + TermVectorsWriter.TVX_EXTENSION))
			{
				tvx = d.OpenFile(segment + TermVectorsWriter.TVX_EXTENSION);
				CheckValidFormat(tvx);
				tvd = d.OpenFile(segment + TermVectorsWriter.TVD_EXTENSION);
				CheckValidFormat(tvd);
				tvf = d.OpenFile(segment + TermVectorsWriter.TVF_EXTENSION);
				CheckValidFormat(tvf);
				size = (int) tvx.Length() / 8;
			}
			
			this.fieldInfos = fieldInfos;
		}
        /// <summary>Writes this vector to the file <code>name</code> in Directory
        /// <code>d</code>, in a format that can be read by the constructor {@link
        /// #BitVector(Directory, String)}.
        /// </summary>
        public void  Write(Directory d, System.String name)
        {
            OutputStream output = d.CreateFile(name);

            try
            {
                output.WriteInt(Size());              // write size
                output.WriteInt(Count());             // write count
                output.WriteBytes(bits, bits.Length); // write bits
            }
            finally
            {
                output.Close();
            }
        }
예제 #28
0
        public /*internal*/ TermVectorsReader(Directory d, System.String segment, FieldInfos fieldInfos)
        {
            if (d.FileExists(segment + TermVectorsWriter.TVX_EXTENSION))
            {
                tvx = d.OpenFile(segment + TermVectorsWriter.TVX_EXTENSION);
                CheckValidFormat(tvx);
                tvd = d.OpenFile(segment + TermVectorsWriter.TVD_EXTENSION);
                CheckValidFormat(tvd);
                tvf = d.OpenFile(segment + TermVectorsWriter.TVF_EXTENSION);
                CheckValidFormat(tvf);
                size = (int)tvx.Length() / 8;
            }

            this.fieldInfos = fieldInfos;
        }
        /// <summary>Constructs a bit vector from the file <code>name</code> in Directory
        /// <code>d</code>, as written by the {@link #write} method.
        /// </summary>
        public BitVector(Directory d, System.String name)
        {
            InputStream input = d.OpenFile(name);

            try
            {
                size  = input.ReadInt();               // read size
                count = input.ReadInt();               // read count
                bits  = new byte[(size >> 3) + 1];     // allocate bits
                input.ReadBytes(bits, 0, bits.Length); // read bits
            }
            finally
            {
                input.Close();
            }
        }
예제 #30
0
        /// <summary>Create the compound stream in the specified file. The file name is the
        /// entire name (no extensions are added).
        /// </summary>
        public CompoundFileWriter(Directory dir, System.String name)
        {
            if (dir == null)
            {
                throw new System.ArgumentException("Missing directory");
            }
            if (name == null)
            {
                throw new System.ArgumentException("Missing name");
            }

            directory = dir;
            fileName  = name;
            ids       = new System.Collections.Hashtable();
            entries   = new System.Collections.ArrayList();
        }
예제 #31
0
		public void  Read(Directory directory)
		{
			
			InputStream input = directory.OpenFile("segments");
			try
			{
				int format = input.ReadInt();
				if (format < 0)
				{
					// file contains explicit format info
					// check that it is a format we can understand
					if (format < FORMAT)
						throw new System.IO.IOException("Unknown format version: " + format);
					version = input.ReadLong(); // read version
					counter = input.ReadInt(); // read counter
				}
				else
				{
					// file is in old format without explicit format info
					counter = format;
				}
				
				for (int i = input.ReadInt(); i > 0; i--)
				{
					// read segmentInfos
					SegmentInfo si = new SegmentInfo(input.ReadString(), input.ReadInt(), directory);
					Add(si);
				}
				
				if (format >= 0)
				{
					// in old format the version number may be at the end of the file
					if (input.GetFilePointer() >= input.Length())
						version = 0;
					// old file format without version number
					else
						version = input.ReadLong(); // read version
				}
			}
			finally
			{
				input.Close();
			}
		}
        private IndexWriter(Directory d, Analyzer a, bool create, bool closeDir)
        {
            InitBlock();
            this.closeDir = closeDir;
            directory     = d;
            analyzer      = a;

            Lock writeLock = directory.MakeLock(IndexWriter.WRITE_LOCK_NAME);

            if (!writeLock.Obtain(WRITE_LOCK_TIMEOUT))
            // obtain write lock
            {
                throw new System.IO.IOException("Index locked for write: " + writeLock);
            }
            this.writeLock = writeLock; // save it

            lock (directory)
            {
                // in- & inter-process sync
                new AnonymousClassWith(create, this, directory.MakeLock(IndexWriter.COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT).Run();
            }
        }
        private void  Initialize(SegmentInfo si)
        {
            segment = si.name;

            // Use compound file directory for some files, if it exists
            Directory cfsDir = Directory();

            if (Directory().FileExists(segment + ".cfs"))
            {
                cfsReader = new CompoundFileReader(Directory(), segment + ".cfs");
                cfsDir    = cfsReader;
            }

            // No compound file exists - use the multi-file format
            fieldInfos   = new FieldInfos(cfsDir, segment + ".fnm");
            fieldsReader = new FieldsReader(cfsDir, segment, fieldInfos);

            tis = new TermInfosReader(cfsDir, segment, fieldInfos);

            // NOTE: the bitvector is stored using the regular directory, not cfs
            if (HasDeletions(si))
            {
                deletedDocs = new BitVector(Directory(), segment + ".del");
            }

            // make sure that all index files have been read or are kept open
            // so that if an index update removes them we'll still have them
            freqStream = cfsDir.OpenFile(segment + ".frq");
            proxStream = cfsDir.OpenFile(segment + ".prx");
            OpenNorms(cfsDir);

            if (fieldInfos.HasVectors())
            {
                // open term vector files only as needed
                termVectorsReader = new TermVectorsReader(cfsDir, segment, fieldInfos);
            }
        }
예제 #34
0
		public void  Write(Directory directory)
		{
			OutputStream output = directory.CreateFile("segments.new");
			try
			{
				output.WriteInt(FORMAT); // write FORMAT
				output.WriteLong(++version); // every write changes the index
				output.WriteInt(counter); // write counter
				output.WriteInt(Count); // write infos
				for (int i = 0; i < Count; i++)
				{
					SegmentInfo si = Info(i);
					output.WriteString(si.name);
					output.WriteInt(si.docCount);
				}
			}
			finally
			{
				output.Close();
			}
			
			// install new segment info
			directory.RenameFile("segments.new", "segments");
		}
        /// <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());
        }
예제 #36
0
		/// <summary>Returns an IndexReader reading the index in the given Directory. </summary>
		public static Monodoc.Lucene.Net.Index.IndexReader Open(Directory directory)
		{
			return Open(directory, false);
		}
예제 #37
0
		private static Monodoc.Lucene.Net.Index.IndexReader Open(Directory directory, bool closeDirectory)
		{
			lock (directory)
			{
				// in- & inter-process sync
				return (Monodoc.Lucene.Net.Index.IndexReader) new AnonymousClassWith(directory, closeDirectory, directory.MakeLock(IndexWriter.COMMIT_LOCK_NAME), IndexWriter.COMMIT_LOCK_TIMEOUT).Run();
			}
		}
예제 #38
0
		internal FieldsWriter(Directory d, System.String segment, FieldInfos fn)
		{
			fieldInfos = fn;
			fieldsStream = d.CreateFile(segment + ".fdt");
			indexStream = d.CreateFile(segment + ".fdx");
		}
예제 #39
0
		/// <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;
		}
예제 #40
0
		/// <summary> 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.
		/// </summary>
		public static void  Unlock(Directory directory)
		{
			directory.MakeLock(IndexWriter.WRITE_LOCK_NAME).Release();
			directory.MakeLock(IndexWriter.COMMIT_LOCK_NAME).Release();
		}
예제 #41
0
 /// <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(directory.FileExists("segments"));
 }
		/// <summary>Creates a searcher searching the index in the provided directory. </summary>
		public IndexSearcher(Directory directory) : this(Monodoc.Lucene.Net.Index.IndexReader.Open(directory), true)
		{
		}
예제 #43
0
		/// <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 directory.FileExists("segments");
		}
예제 #44
0
		public Directory dir; // where segment resides
		
		public SegmentInfo(System.String name, int docCount, Directory dir)
		{
			this.name = name;
			this.docCount = docCount;
			this.dir = dir;
		}
예제 #45
0
		public /*internal*/ TermInfosWriter(Directory directory, System.String segment, FieldInfos fis)
		{
			Initialize(directory, segment, fis, false);
			other = new TermInfosWriter(directory, segment, fis, true);
			other.other = this;
		}
예제 #46
0
		/// <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);
		}
예제 #47
0
		private TermInfosWriter(Directory directory, System.String segment, FieldInfos fis, bool isIndex)
		{
			Initialize(directory, segment, fis, isIndex);
		}
예제 #48
0
 /// <summary> Returns <code>true</code> iff the index in the named directory is
 /// currently locked.
 /// </summary>
 /// <param name="directory">the directory to check for a lock
 /// </param>
 /// <throws>  IOException if there is a problem with accessing the index </throws>
 public static bool IsLocked(Directory directory)
 {
     return(directory.MakeLock(IndexWriter.WRITE_LOCK_NAME).IsLocked() || directory.MakeLock(IndexWriter.COMMIT_LOCK_NAME).IsLocked());
 }
예제 #49
0
		/// <summary> Returns the time the index in the named directory was last modified. 
		/// 
		/// <p>Synchronization of IndexReader and IndexWriter instances is 
		/// no longer done via time stamps of the segments file since the time resolution 
		/// depends on the hardware platform. Instead, a version number is maintained
		/// within the segments file, which is incremented everytime when the index is
		/// changed.</p>
		/// 
		/// </summary>
		/// <deprecated>  Replaced by {@link #GetCurrentVersion(Directory)}
		/// 
		/// </deprecated>
		public static long LastModified(Directory directory)
		{
			return directory.FileModified("segments");
		}
예제 #50
0
		/// <summary> </summary>
		/// <param name="dir">The Directory to merge the other segments into
		/// </param>
		/// <param name="name">The name of the new segment
		/// </param>
		/// <param name="compoundFile">true if the new segment should use a compoundFile
		/// </param>
		public /*internal*/ SegmentMerger(Directory dir, System.String name, bool compoundFile)
		{
			directory = dir;
			segment = name;
			useCompoundFile = compoundFile;
		}
예제 #51
0
		/// <summary> Reads version number from segments files. The version number counts the
		/// number of changes of the index.
		/// 
		/// </summary>
		/// <param name="directory">where the index resides.
		/// </param>
		/// <returns> version number.
		/// </returns>
		/// <throws>  IOException if segments file cannot be read. </throws>
		public static long GetCurrentVersion(Directory directory)
		{
			return SegmentInfos.ReadCurrentVersion(directory);
		}
		private void  OpenNorms(Directory cfsDir)
		{
			for (int i = 0; i < fieldInfos.Size(); i++)
			{
				FieldInfo fi = fieldInfos.FieldInfo(i);
				if (fi.isIndexed)
				{
					System.String fileName = segment + ".f" + fi.number;
					// look first for re-written file, then in compound format
					Directory d = Directory().FileExists(fileName)?Directory():cfsDir;
					norms[fi.name] = new Norm(this, d.OpenFile(fileName), fi.number);
				}
			}
		}
예제 #53
0
		/// <summary> Returns <code>true</code> iff the index in the named directory is
		/// currently locked.
		/// </summary>
		/// <param name="directory">the directory to check for a lock
		/// </param>
		/// <throws>  IOException if there is a problem with accessing the index </throws>
		public static bool IsLocked(Directory directory)
		{
			return directory.MakeLock(IndexWriter.WRITE_LOCK_NAME).IsLocked() || directory.MakeLock(IndexWriter.COMMIT_LOCK_NAME).IsLocked();
		}
예제 #54
0
 /// <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);
 }
예제 #55
0
		/// <summary>Constructs a bit vector from the file <code>name</code> in Directory
		/// <code>d</code>, as written by the {@link #write} method.
		/// </summary>
		public BitVector(Directory d, System.String name)
		{
			InputStream input = d.OpenFile(name);
			try
			{
				size = input.ReadInt(); // read size
				count = input.ReadInt(); // read count
				bits = new byte[(size >> 3) + 1]; // allocate bits
				input.ReadBytes(bits, 0, bits.Length); // read bits
			}
			finally
			{
				input.Close();
			}
		}
예제 #56
0
 /// <summary> Reads version number from segments files. The version number counts the
 /// number of changes of the index.
 ///
 /// </summary>
 /// <param name="directory">where the index resides.
 /// </param>
 /// <returns> version number.
 /// </returns>
 /// <throws>  IOException if segments file cannot be read. </throws>
 public static long GetCurrentVersion(Directory directory)
 {
     return(SegmentInfos.ReadCurrentVersion(directory));
 }
예제 #57
0
		/// <summary>Writes this vector to the file <code>name</code> in Directory
		/// <code>d</code>, in a format that can be read by the constructor {@link
		/// #BitVector(Directory, String)}.  
		/// </summary>
		public void  Write(Directory d, System.String name)
		{
			OutputStream output = d.CreateFile(name);
			try
			{
				output.WriteInt(Size()); // write size
				output.WriteInt(Count()); // write count
				output.WriteBytes(bits, bits.Length); // write bits
			}
			finally
			{
				output.Close();
			}
		}
예제 #58
0
 internal FieldsWriter(Directory d, System.String segment, FieldInfos fn)
 {
     fieldInfos   = fn;
     fieldsStream = d.CreateFile(segment + ".fdt");
     indexStream  = d.CreateFile(segment + ".fdx");
 }
예제 #59
0
 /// <summary> 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.
 /// </summary>
 public static void  Unlock(Directory directory)
 {
     directory.MakeLock(IndexWriter.WRITE_LOCK_NAME).Release();
     directory.MakeLock(IndexWriter.COMMIT_LOCK_NAME).Release();
 }
예제 #60
0
		/// <summary> Constructor used if IndexReader is not owner of its directory. 
		/// This is used for IndexReaders that are used within other IndexReaders that take care or locking directories.
		/// 
		/// </summary>
		/// <param name="directory">Directory where IndexReader files reside.
		/// </param>
		protected internal IndexReader(Directory directory)
		{
			this.directory = directory;
			segmentInfos = null;
			directoryOwner = false;
			closeDirectory = false;
			stale = false;
			hasChanges = false;
			writeLock = null;
		}