Exemple #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();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Outputs the directory of index files to read.
        /// </summary>
        /// <param name="index">The index to find the read directory for.</param>
        /// <param name="info">out of the discovered index directory.</param>
        /// <returns><c>true</c> if there are index files; otherwise, <c>false</c>.</returns>
        private static bool GetIndexReadDirectory(IIndex index, 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.GetReadDirectory();
                return(doubleIndex.HasIndexFiles());

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