Directory() public method

Returns the directory associated with this index. The Default implementation returns the directory specified by subclasses when delegating to the IndexReader(Directory) constructor, or throws an UnsupportedOperationException if one was not specified.
public Directory ( ) : Directory
return System.IO.Directory
Exemplo n.º 1
0
        /// <summary>Merges the named range of segments, replacing them in the stack with a
        /// single segment.
        /// </summary>
        private void  MergeSegments(int minSegment, int end)
        {
            System.String mergedName = NewSegmentName();
            if (infoStream != null)
            {
                infoStream.Write("merging segments");
            }
            SegmentMerger merger = new SegmentMerger(this, mergedName);

            System.Collections.ArrayList segmentsToDelete = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            for (int i = minSegment; i < end; i++)
            {
                SegmentInfo si = segmentInfos.Info(i);
                if (infoStream != null)
                {
                    infoStream.Write(" " + si.name + " (" + si.docCount + " docs)");
                }
                IndexReader reader = SegmentReader.Get(si);
                merger.Add(reader);
                if ((reader.Directory() == this.directory) || (reader.Directory() == this.ramDirectory))
                {
                    segmentsToDelete.Add(reader);                     // queue segment for deletion
                }
            }

            int mergedDocCount = merger.Merge();

            if (infoStream != null)
            {
                infoStream.WriteLine(" into " + mergedName + " (" + mergedDocCount + " docs)");
            }

            for (int i = end - 1; i >= minSegment; i--)
            {
                // remove old infos & add new
                segmentInfos.RemoveAt(i);
            }
            segmentInfos.Add(new SegmentInfo(mergedName, mergedDocCount, directory));

            // close readers before we attempt to delete now-obsolete segments
            merger.CloseReaders();

            lock (directory)
            {
                // in- & inter-process sync
                new AnonymousClassWith3(segmentsToDelete, this, directory.MakeLock(COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT).Run();
            }

            if (useCompoundFile)
            {
                System.Collections.ArrayList filesToDelete = merger.CreateCompoundFile(mergedName + ".tmp");
                lock (directory)
                {
                    // in- & inter-process sync
                    new AnonymousClassWith4(mergedName, filesToDelete, this, directory.MakeLock(COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT).Run();
                }
            }
        }
		public SuggestionQueryIndexExtension(
			string key,
			IndexReader reader,
			StringDistance distance, 
			string field, 
			float accuracy)
		{
			this.key = key;
			this.field = field;
			
			if(reader.Directory() is RAMDirectory)
			{
				directory = new RAMDirectory();
			}
			else
			{
				directory = FSDirectory.Open(new DirectoryInfo(key));
			}

			this.spellChecker = new SpellChecker.Net.Search.Spell.SpellChecker(directory, distance);
			this.spellChecker.SetAccuracy(accuracy);
		}
        private void CloseInternalReader(bool trace, IndexReader subReader, bool finalClose)
        {
            ReaderData readerData;
            // TODO: can we avoid the lock?
            lock (semaphoreIndexReaderLock)
            {
                readerData = searchIndexReaderSemaphores[subReader];
            }

            if (readerData == null)
            {
                log.Error("Trying to close a Lucene IndexReader not present: " + subReader.Directory());
                // TODO: Should we try to close?
                return;
            }

            // Acquire the locks in the same order as everywhere else
            object directoryProviderLock = perDirectoryProviderManipulationLocks[readerData.Provider];
            bool closeReader = false;
            lock (directoryProviderLock)
            {
                IndexReader reader;
                bool isActive = activeSearchIndexReaders.TryGetValue(readerData.Provider, out reader)
                    && reader == subReader;
                if (trace) log.Info("IndexReader not active: " + subReader);
                lock (semaphoreIndexReaderLock)
                {
                    readerData = searchIndexReaderSemaphores[subReader];
                    if (readerData == null)
                    {
                        log.Error("Trying to close a Lucene IndexReader not present: " + subReader.Directory());
                        // TODO: Should we try to close?
                        return;
                    }

                    //final close, the semaphore should be at 0 already
                    if (!finalClose)
                    {
                        readerData.Semaphore--;
                        if (trace)
                            log.Info("Semaphore decreased to: " + readerData.Semaphore + " for " + subReader);
                    }

                    if (readerData.Semaphore < 0)
                        log.Error("Semaphore negative: " + subReader.Directory());

                    if (!isActive && readerData.Semaphore == 0)
                    {
                        searchIndexReaderSemaphores.Remove(subReader);
                        closeReader = true;
                    }
                    else
                        closeReader = false;
                }
            }

            if (closeReader)
            {
                if (trace) log.Info("Closing IndexReader: " + subReader);
                try
                {
                    subReader.Close();
                }
                catch (IOException e)
                {
                    log.Warn("Unable to close Lucene IndexReader", e);
                }
            }
        }
Exemplo n.º 4
0
 public override Directory Directory()
 {
     return(in_Renamed.Directory());
 }
 /// <summary> <p>Construct a FilterIndexReader based on the specified base reader.
 /// Directory locking for delete, undeleteAll, and setNorm operations is
 /// left to the base reader.</p>
 /// <p>Note that base reader is closed if this FilterIndexReader is closed.</p>
 /// </summary>
 /// <param name="in">specified base reader.
 /// </param>
 public FilterIndexReader(IndexReader in_Renamed)
     : base(in_Renamed.Directory())
 {
     this.in_Renamed = in_Renamed;
 }
Exemplo n.º 6
0
 /// <summary> <p>Construct a FilterIndexReader based on the specified base reader.
 /// Directory locking for delete, undeleteAll, and setNorm operations is
 /// left to the base reader.</p>
 /// <p>Note that base reader is closed if this FilterIndexReader is closed.</p>
 /// </summary>
 /// <param name="in">specified base reader.
 /// </param>
 public FilterIndexReader(IndexReader in_Renamed) : base(in_Renamed.Directory())
 {
     this.in_Renamed = in_Renamed;
 }
        /// <summary>
        /// Gets the similar words.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="word">The word.</param>
        /// <returns></returns>
        private static string[] SuggestSimilar(IndexReader reader, string fieldName, string word)
        {
            var spell = new SpellChecker.Net.Search.Spell.SpellChecker(reader.Directory());
            spell.IndexDictionary(new LuceneDictionary(reader, fieldName));
            var similarWords = spell.SuggestSimilar(word, 2);

            // now make sure to close the spell checker
            spell.Close();

            return similarWords;
        }
Exemplo n.º 8
0
        public override DocIdSet GetDocIdSet(IndexReader reader)
        {
            DocIdSet docs = null;

            // TODO: override by SinSay
            var cache = IdSetCache.GetCache(reader.Directory().ToString(), this.fieldName);
            if (cache != null)
            {
                return cache.Cache;
            }

            if (processingMode == PM_FAST_INVALIDATION)
            {
                docs = FastBits(reader);
            }
            else
            {
                docs = CorrectBits(reader);
            }

            return docs;
        }