Ejemplo n.º 1
0
        public long GetTotalDocumentsInIndex()
        {
            // okay, open reader or searcher and get max docs
            DirectoryInfo searchDirectory = null;
            bool          hasIndexFiles   = false;

            switch (index.IndexStructure)
            {
            case IndexType.SingleIndex:
                IIndex singleIndex = (IIndex)index;
                searchDirectory = singleIndex.IndexDirectory;
                hasIndexFiles   = singleIndex.HasIndexFiles();
                break;

            case IndexType.DoubleIndex:
            case IndexType.CyclicalIndex:
                IDoubleIndex doubleIndex = (IDoubleIndex)index;
                searchDirectory = doubleIndex.GetReadDirectory();
                hasIndexFiles   = doubleIndex.HasIndexFiles();
                break;

            default:
                throw new NotImplementedException(index.IndexStructure.ToString() + " not supported");
            }

            if (!hasIndexFiles)
            {
                return(-1L);
            }

            Lucene29.Net.Store.Directory      directory = null;
            Lucene29.Net.Search.IndexSearcher searcher  = null;
            try {
                directory = Lucene29.Net.Store.FSDirectory.Open(searchDirectory);
                searcher  = new Lucene29.Net.Search.IndexSearcher(directory, true);
                return(searcher.MaxDoc());
            }
            catch {
                return(-2L);
            }
            finally {
                if (searcher != null)
                {
                    searcher.Close();
                }
                if (directory != null)
                {
                    directory.Close();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Outputs the directory of index files to read
        /// </summary>
        /// <param name="info">out of the discovered index directory</param>
        /// <returns>True if there are index files; false if not</returns>
        private bool GetIndexWriteDirectory(out DirectoryInfo info)
        {
            switch (index.IndexStructure)
            {
            case IndexType.SingleIndex:
                IIndex singleIndex = (IIndex)index;
                info = singleIndex.IndexDirectory;
                return(singleIndex.HasIndexFiles());

            case IndexType.DoubleIndex:
            case IndexType.CyclicalIndex:
                IDoubleIndex doubleIndex = (IDoubleIndex)index;
                info = doubleIndex.GetWriteDirectory();
                return(doubleIndex.HasWriteIndexFiles());

            default:
                throw new NotImplementedException(index.IndexStructure.ToString() + " not supported");
            }
        }