/// <summary>
        /// Prevents Unnecessary File Indexing
        /// </summary>
        public static void PreventUnnecessaryFileIndex()
        {
            //ExStart: PreventUnnecessaryFileIndex
            // Create index
            Index index = new Index(Utilities.indexPath);

            // Add documents to index
            index.AddToIndex(Utilities.documentsPath);

            // Try add the same documents to index
            index.AddToIndex(Utilities.documentsPath); // Already indexed files will not be reindexed.
            //ExEnd: PreventUnnecessaryFileIndex
        }
        /// <summary>
        /// Shows how to filter files during indexing
        /// Feature is supported in version 17.9.0 or greater of the API
        /// </summary>
        public static void FilterFilesDuringIndexing()
        {
            //ExStart:FilterFilesDuringIndexing
            // Creating indexing settings object
            IndexingSettings settings = new IndexingSettings();

            // Creating filter that only passes files from 600 KB to 1 MB in length
            DocumentFilter byLength = DocumentFilter.CreateFileLengthRange(614400, 1048576);

            // Creating filter that only passes text files
            DocumentFilter byExtension = DocumentFilter.CreateFileExtension(".txt");

            // Creating composite filter that only passes text files from 600 KB to 1 MB in length
            DocumentFilter compositeFilter = DocumentFilter.CreateConjunction(byLength, byExtension);

            // Setting filter
            settings.DocumentFilter = compositeFilter;

            // Creating index
            Index index = new Index(Utilities.indexPath, settings);

            // Indexing
            index.AddToIndex(Utilities.documentsPath);
            //ExEnd:FilterFilesDuringIndexing
        }
示例#3
0
        public void OpenFoundMessageUsingAsposeEmail(string searchString)
        {
            string myPstFile = Utilities.pathToPstFile;
            // Indexing MS Outlook storage with email messages
            Index index = new Index(Utilities.indexPath);

            index.OperationFinished += Utilities.index_OperationFinished;
            index.AddToIndex(myPstFile);

            // Searching in index
            SearchResults results = index.Search(searchString);

            // User gets all messages that qualify to search query using Aspose.Email API
            MessageInfoCollection messages = new MessageInfoCollection();

            foreach (DocumentResultInfo searchResult in results)
            {
                if (searchResult.DocumentType == DocumentType.OutlookEmailMessage)
                {
                    OutlookEmailMessageResultInfo emailResultInfo = searchResult as OutlookEmailMessageResultInfo;
                    MessageInfo message = GetEmailMessagesById(Utilities.pathToPstFile, emailResultInfo.EntryIdString);
                    if (message != null)
                    {
                        messages.Add(message);
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// Creates index, adds documents to index and do regex search
        /// </summary>
        /// <param name="relevantKey">single keyword</param>
        /// <param name="regexString">regex</param>
        public static void RegexSearch(string relevantKey, string regexString)
        {
            //ExStart:Regexsearch
            // Create index
            Index index = new Index(Utilities.indexPath);

            // Add documents to index
            index.AddToIndex(Utilities.documentsPath);

            // Search for documents where at least one word contain given regex
            SearchResults searchResults1 = index.Search(relevantKey);

            //Search for documents where present term1 or any email adress or term2
            SearchResults searchResults2 = index.Search(regexString);

            // List of found files
            Console.WriteLine("Follwoing document(s) contain provided relevant tag: \n");
            foreach (DocumentResultInfo documentResultInfo in searchResults1)
            {
                Console.WriteLine("Query \"{0}\" has {1} hit count in file: {2}", relevantKey, documentResultInfo.HitCount, documentResultInfo.FileName);
                Console.WriteLine("Query \"{0}\" has {1} hit count in file: {2}", regexString, documentResultInfo.HitCount, documentResultInfo.FileName);
            }

            // List of found files
            Console.WriteLine("Follwoing document(s) contain provided RegEx: \n");
            foreach (DocumentResultInfo documentResultInfo in searchResults2)
            {
                Console.WriteLine("Query \"{0}\" has {1} hit count in file: {2}", relevantKey, documentResultInfo.HitCount, documentResultInfo.FileName);
                Console.WriteLine("Query \"{0}\" has {1} hit count in file: {2}", regexString, documentResultInfo.HitCount, documentResultInfo.FileName);
            }
            //ExEnd:Regexsearch
        }
示例#5
0
        /// <summary>
        /// Shows how to implement own custom extractor for outlook document for the extension .ost and .pst files
        /// </summary>
        /// <param name="searchString">string to search</param>
        public static void DetailedResults(string searchString)
        {
            //ExStart:DetailedResultsPropertyInDocuments
            // Create or load index
            Index index = new Index(Utilities.indexPath);

            index.AddToIndex(Utilities.documentsPath);

            SearchResults results = index.Search(searchString);

            foreach (DocumentResultInfo resultInfo in results)
            {
                if (resultInfo.DocumentType == DocumentType.OutlookEmailMessage)
                {
                    // for email message result info user should cast resultInfo as OutlookEmailMessageResultInfo for acessing EntryIdString property
                    OutlookEmailMessageResultInfo emailResultInfo = resultInfo as OutlookEmailMessageResultInfo;

                    Console.WriteLine("Query \"{0}\" has {1} hit count in message {2} in file {3}", searchString, emailResultInfo.HitCount, emailResultInfo.EntryIdString, emailResultInfo.FileName);
                }
                else
                {
                    Console.WriteLine("Query \"{0}\" has {1} hit count in file {2}", searchString, resultInfo.HitCount, resultInfo.FileName);
                }

                foreach (DetailedResultInfo detailedResult in resultInfo.DetailedResults)
                {
                    Console.WriteLine("{0}In field \"{1}\" there was found {2} hit count", "\t", detailedResult.FieldName, detailedResult.HitCount);
                }
            }
            //ExEnd:DetailedResultsPropertyInDocuments
        }
        /// <summary>
        /// Shows how to detect encoding selectively for some text files
        /// Feature is supported in version 17.9.0 or greater
        /// </summary>
        public static void DetectEncodingSelectively()
        {
            //ExStart:DetectEncodingSelectively
            // Creating index
            Index index = new Index(Utilities.indexPath);

            // Creating default encoding that is used when encoding was not detected
            Encoding defaultEncoding = Encoding.GetEncoding(Encodings.Windows_1252);

            // Subscribing to FileIndexing event
            index.FileIndexing += (sender, args) =>
            {
                // Detecting encoding only for text files located in the 'documentsPath3' folder
                string fileName = args.DocumentFullName;
                if (fileName.EndsWith(".txt", true, CultureInfo.InvariantCulture) &&
                    fileName.StartsWith(Utilities.documentsPath3))
                {
                    args.DetectEncoding(defaultEncoding, true);
                }
            };

            // Indexing
            index.AddToIndex(Utilities.documentsPath);
            //ExEnd:DetectEncodingSelectively
        }
示例#7
0
        /// <summary>
        /// Creates index, adds documents to index and do search on the basis of synonyms by turning synonym search true
        /// </summary>
        /// <param name="searchString">string to search</param>
        public static void SynonymSearch(string searchString)
        {
            //ExStart:SynonymSearch
            // Create or load index
            Index index = new Index(Utilities.indexPath);

            // load synonyms
            index.LoadSynonyms(Utilities.synonymFilePath);

            index.AddToIndex(Utilities.documentsPath);

            // Turning on synonym search feature
            SearchParameters parameters = new SearchParameters();

            parameters.UseSynonymSearch = true;

            // searching for documents with words one of words "remote", "virtual" or "online"
            SearchResults searchResults = index.Search(searchString, parameters);

            // List of found files
            foreach (DocumentResultInfo documentResultInfo in searchResults)
            {
                Console.WriteLine("Query \"{0}\" has {1} hit count in file: {2}", searchString, documentResultInfo.HitCount, documentResultInfo.FileName);
            }
            //ExEnd:SynonymSearch
        }
        /// <summary>
        /// Shows how to perform accent insensitive indexing
        /// Feature is supported in version 17.8.0 of the API
        /// </summary>
        public static void AccentInsensitiveIndexing()
        {
            //ExStart:AccentInsensitiveIndexing
            // Enabling replacements during indexing
            var settings = new IndexingSettings();

            settings.UseCharacterReplacements = true;

            // Creating index
            Index index = new Index(Utilities.indexPath, settings);

            // Clearing dictionary of replacements
            index.Dictionaries.CharacterReplacements.Clear();

            // Adding replacements
            KeyValuePair <char, char>[] replacements = new KeyValuePair <char, char>[]
            {
                new KeyValuePair <char, char>('Ṝ', 'R'),
                new KeyValuePair <char, char>('ṝ', 'r'),
            };
            index.Dictionaries.CharacterReplacements.AddRange(replacements);

            // Import replacements from file. Existing replacements are staying.
            index.Dictionaries.CharacterReplacements.Import(Utilities.replacementsFileName);
            // Export replacements to file
            index.Dictionaries.CharacterReplacements.Export(Utilities.exportedReplacementsFileName);

            // Indexing
            index.AddToIndex(Utilities.documentsPath);
            //ExEnd:AccentInsensitiveIndexing
        }
示例#9
0
        /// <summary>
        /// Adds documents in books index
        /// </summary>
        public static void AddDocumentsInBooksIndex()
        {
            // Loading index
            Index index = new Index(Utilities.booksIndex);

            // Adding to index folder
            index.AddToIndex(Utilities.documentsPath);
        }
        /// <summary>
        /// Indexes separate files
        /// </summary>
        public static void IndexSeparateFiles()
        {
            //ExStart:IndexSeparateFiles
            Index index = new Index(Utilities.indexPath);

            // adding just one file to index
            index.AddToIndex(Utilities.pathToPstFile);
            //ExEnd:IndexSeparateFiles
        }
        /// <summary>
        /// Merges Index with delta indexes Asynchronously to improve search performance
        /// </summary>
        public static void MergingIndexWithDeltaIndexesAsync()
        {
            //ExStart:MergingIndexWithDeltaIndexesAsync
            string myDocumentsFolder1 = Utilities.documentsPath;
            string myDocumentsFolder2 = Utilities.documentsPath2;

            // Creating index
            Index index = new Index(Utilities.indexPath, true);

            // Adding documents to index
            index.AddToIndex(myDocumentsFolder1);

            // Adding one more folder to index. Delta index will be created.
            index.AddToIndex(myDocumentsFolder2);

            // Run merging asynchonously
            index.MergeAsync();
            //ExEnd:MergingIndexWithDeltaIndexesAsync
        }
        /// <summary>
        /// Custom extractor test
        /// </summary>
        public static void CustomExtractor()
        {
            //ExStart:CustomExtractor
            Index index = new Index(Utilities.indexPath);

            index.CustomExtractors.Add(new CustomFieldExtractor());

            index.AddToIndex(Utilities.documentsPath);
            //ExEnd:CustomExtractor
        }
示例#13
0
        public static void TotalHitCount(string searchString)
        {
            Index index = new Index(Utilities.indexPath);

            index.AddToIndex(Utilities.documentsPath);

            SearchResults results = index.Search(searchString);

            Console.WriteLine("Searching with query \"{0}\" returns {1} documents with {2} total hit count", searchString, results.Count, results.TotalHitCount);
        }
        /// <summary>
        /// Add document to index
        /// </summary>
        public static void AddDocumentToIndex()
        {
            //ExStart:AddDocumentToIndex
            // Create index
            Index index = new Index(Utilities.indexPath);

            // all files from folder and its subfolders will be added to the index
            index.AddToIndex(Utilities.documentsPath);
            //ExEnd:AddDocumentToIndex
        }
        /// <summary>
        /// Adds document to index with progress percentage event
        /// </summary>
        public static void GetIndexingProgressPercentage()
        {
            //ExStart:GetIndexingProgressPercentage
            // Create index
            Index index = new Index(Utilities.indexPath, true);

            index.OperationProgressChanged += index_OperationProgressChanged; // event subscribing
            // all files from folder and its subfolders will be added to the index
            index.AddToIndex(Utilities.documentsPath);
            //ExEnd:GetIndexingProgressPercentage
        }
        /// <summary>
        /// Shows how to limit index report
        /// Feature is supported in version 17.8.0 of the API
        /// </summary>
        public static void LimitIndexReport()
        {
            //ExStart:LimitIndexReport
            Index index = new Index(Utilities.indexPath);

            // Setting the maximum count of indexing reports
            index.IndexingSettings.MaxIndexingReportCount = 2;

            index.AddToIndex(Utilities.documentsPath);
            index.AddToIndex(Utilities.documentsPath2);
            index.AddToIndex(Utilities.documentsPath3);

            // Getting indexing report. Array contains only 2 last records about indexing.
            IndexingReport[] report = index.GetIndexingReport();

            // Three indexing operations were performed, but only 2 last operations will be printed on the console in this example
            foreach (IndexingReport record in report)
            {
                Console.WriteLine("Indexing takes {0}, index size: {1}.", record.IndexingTime, record.TotalIndexSize);
            }
            //ExEnd:LimitIndexReport
        }
示例#17
0
        /// <summary>
        /// Shows how to implement own custom extractor for outlook document for the extension .ost and .pst files
        /// </summary>
        /// <param name="searchString">string to search</param>
        public static void OwnExtractorOst(string searchString)
        {
            //ExStart:OwnExtractorOst
            // Create or load index
            Index index = new Index(Utilities.indexPath);

            index.CustomExtractors.Add(new CustomOstPstExtractor()); // Adding new custom extractor for container document

            index.AddToIndex(Utilities.documentsPath);               // Documents with "ost" and "pst" extension will be indexed using MyCustomContainerExtractor

            SearchResults searchResults = index.Search(searchString);
            //ExEnd:OwnExtractorOst
        }
        /// <summary>
        /// Add PowerPoint Document to index
        /// </summary>
        public static void AddPowerPointDocumentToIndex()
        {
            //ExStart:AddPowerPointDocumentToIndex
            // Create index
            Index index = new Index(Utilities.indexPath);

            // all files from folder and its subfolders will be added to the index
            index.AddToIndex(Utilities.documentsPath);

            SearchResults results1 = index.Search("author:cisco");       // searching by author of presentation
            SearchResults results2 = index.Search("LastSavedBy:teresa"); // searching by person who saved presentation last time
            //ExEnd:AddPowerPointDocumentToIndex
        }
示例#19
0
        /// <summary>
        /// Creates index,
        /// Adds documents to index
        /// Enable fuzzy search
        /// Set similarity level from 0.0 to 1.0
        /// Do Fuzzy search
        /// </summary>
        /// <param name="searchString">Misspelled string</param>
        ///
        public static void FuzzySearch(string searchString)
        {
            //ExStart:Fuzzysearch
            Index index = new Index(Utilities.indexPath);

            index.AddToIndex(Utilities.documentsPath);

            SearchParameters parameters = new SearchParameters();

            // turning on Fuzzy search feature
            parameters.FuzzySearch.Enabled = true;

            // set low similarity level to search for less similar words and get more results
            parameters.FuzzySearch.SimilarityLevel = 0.1;
            SearchResults lessSimilarResults = index.Search(searchString, parameters);

            Console.WriteLine("Results with less similarity level that is currently set to =" + parameters.FuzzySearch.SimilarityLevel);
            foreach (DocumentResultInfo lessSimilarResultsDoc in lessSimilarResults)
            {
                Console.WriteLine(lessSimilarResultsDoc.FileName + "\n");
            }

            // set high similarity level to search for more similar words and get less results
            parameters.FuzzySearch.SimilarityLevel = 0.9;
            SearchResults moreSimilarResults = index.Search(searchString, parameters);

            Console.WriteLine("Results with high similarity level that is currently set to =" + parameters.FuzzySearch.SimilarityLevel);
            foreach (DocumentResultInfo highSimilarityLevelDoc in moreSimilarResults)
            {
                Console.WriteLine(highSimilarityLevelDoc.FileName + "\n");
            }

            /* // Create index
             * Index index = new Index(Utilities.indexPath);
             *
             * // Add documents to index
             * index.AddToIndex(Utilities.documentsPath);
             *
             * SearchParameters parameters = new SearchParameters();
             * parameters.UseFuzzySearch = true; // obolete now it was in 1.1
             *
             * SearchResults searchResults = index.Search(searchString, parameters);
             *
             * foreach (DocumentResultInfo documentResultInfo in searchResults)
             * {
             * Console.WriteLine(documentResultInfo.FileName + "\n");
             * }
             */
            //ExEnd:Fuzzysearch
        }
        /// <summary>
        /// adds documents to old version of the index
        /// </summary>
        public static void AddDocsToOldIndexVersion()
        {
            //ExStart:AddDocsToOldIndexVersion
            // This index should be exist and should have one of previous version
            string oldIndexFolder  = Utilities.oldIndexFolderPath;
            string documentsFolder = Utilities.documentsPath3;

            // Load index
            Index index = new Index(oldIndexFolder);

            // Add documents to index. Index will be updated to actual version before adding new documents.
            index.AddToIndex(documentsFolder, true);
            //ExEnd:AddDocsToOldIndexVersion
        }
        internal static void IndexMetaData()
        {
            //ExStart: IndexMetaData
            // Creating indexing settings object
            IndexingSettings settings = new IndexingSettings();

            settings.IndexType = IndexType.MetadataIndex;

            // Creating index
            Index index = new Index(Utilities.indexPath, settings);

            // Indexing
            index.AddToIndex(Utilities.documentsPath);
            //ExEnd: IndexMetaData
        }
        /// <summary>
        /// Break Index Repository using Cancellation Object
        /// This method is supported by version 18.8 or greater
        /// </summary>
        public static void BreakIndexRepositoryUsingCancellationObject()
        {
            string          documentsFolder = Utilities.documentsPath;
            IndexRepository repository      = new IndexRepository();
            Index           index           = repository.Create();

            index.AddToIndex(documentsFolder);

            Cancellation cnc = new Cancellation();

            // Updating all indexes in repository
            repository.UpdateAsync(cnc);

            // Canceling all operations in index repository
            cnc.Cancel();
        }
        /// <summary>
        /// Shows how to sutomatically detect encoding in text files
        /// Feature is supported in version 17.9.0 or greater
        /// </summary>
        public static void AutomaticDetectEncoding()
        {
            //ExStart:AutomaticDetectEncoding
            // Creating indexing settings object
            IndexingSettings settings = new IndexingSettings();

            // Enabling automatic encoding detection
            settings.AutoDetectEncoding = true;

            // Creating index
            Index index = new Index(Utilities.indexPath, settings);

            // Indexing
            index.AddToIndex(Utilities.documentsPath);
            //ExEnd:AutomaticDetectEncoding
        }
示例#24
0
        /// <summary>
        /// Creates a new books index, add documents in it and performs a search operation in it
        /// </summary>
        public static void SearchBooks()
        {
            // Creating index folder
            Index index = new Index(Utilities.booksIndex);

            // Indexing documents in folder
            index.AddToIndex(Utilities.books);

            // When indexing is finished user can search in it
            SearchResults searchResults = index.Search("Gregor Samsa");

            // List of found files
            foreach (DocumentResultInfo result in searchResults)
            {
                Console.WriteLine((result.FileName));
            }
        }
        /// <summary>
        /// Tracks all the changes in the index folder
        /// </summary>
        public static void TrackAllChanges()
        {
            // Create index
            Index index = new Index(Utilities.indexPath);

            // Add documents to index
            index.AddToIndex(Utilities.documentsPath);

            // Remove some documents from documents path
            // Edit some documents in documents path
            // Add some new documents to documents path

            index.Update();
            // removed documents will be marked as deleted in index and will not be added to search results
            // Edited documents will be reindexed
            // Added documents will be added to index
        }
        /// <summary>
        /// Merges several indexes asynchronously
        /// </summary>
        public static void MergingMultipleIndexesAsync()
        {
            //ExStart:MergingMultipleIndexesAsync
            // Creating/loading first index
            Index index1 = new Index(Utilities.mergeIndexPath1);

            index1.AddToIndex(Utilities.documentsPath);

            // Creating/loading second index
            Index index2 = new Index(Utilities.mergeIndexPath2);

            index2.AddToIndex(Utilities.documentsPath2);

            // Merging data from index2 to index1. The index2 remains unchanged.
            index1.MergeAsync(index2);
            //ExEnd:MergingMultipleIndexesAsync
        }
        /// <summary>
        /// The API implements safe updating of index files to increase reliability
        /// Below example shows how to check if index should be reloaded
        /// Feature is supported in version 17.10 or greater
        /// </summary>
        public static void CheckNeedForIndexReload()
        {
            //ExStart:CheckNeedForIndexReload
            // Creating index
            Index index = new Index(Utilities.indexPath);

            // Indexing
            index.AddToIndex(Utilities.documentsPath);

            // Checking the need to reload
            if (index.IndexStatus == IndexStatus.Failed)
            {
                // Reloading index
                index = new Index(Utilities.indexPath);
            }
            //ExEnd:CheckNeedForIndexReload
        }
        /// <summary>
        /// shows how to get indexing report
        /// Feature is supported in version 17.7 or greater
        /// </summary>
        public static void GetIndexReport()
        {
            //ExStart:GetIndexReport
            Index index = new Index(Utilities.indexPath);

            index.AddToIndex(Utilities.documentsPath);

            // Get indexing report
            IndexingReport[] report = index.GetIndexingReport();

            foreach (IndexingReport record in report)
            {
                Console.WriteLine("Indexing takes {0}, index size: {1}.", record.IndexingTime, record.TotalIndexSize);
            }

            //ExEnd:GetIndexReport
        }
        public static void MultiThreadedIndexing()
        {
            try
            {
                // Creating index
                Index index = new Index(Utilities.indexPath);

                // Indexing in 2 threads
                index.AddToIndex(Utilities.documentsPath, 2);

                // Searching
                SearchResults result = index.Search("Einstein");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        /// <summary>
        /// Shows how to cache text of Indexed Documents in index
        /// Feature is supported in version 17.9.0 or greater of the API
        /// </summary>
        public static void CacheTextOfIndexedDocsInIndex()
        {
            //ExStart:CacheTextOfIndexedDocsInIndex
            // Creating indexing settings object
            IndexingSettings settings = new IndexingSettings();

            // Enabling source document text caching with normal compression level
            // From version 17.10 onwards, value "High" has been added to GroupDocs.Search.Compression enumeration.
            // So in order to cache document's text with high compression level use "Compression.High"
            settings.TextStorageSettings = new TextStorageSettings(Compression.Normal);

            // Creating index
            Index index = new Index(Utilities.indexPath, settings);

            // Indexing
            index.AddToIndex(Utilities.documentsPath);
            //ExEnd:CacheTextOfIndexedDocsInIndex
        }