GroupDocs.Search for .NET is a easy to use document search library which performs search operations over various file formats - DOC, XLS, PPT, ODP and many others. The search API allows to create search index with flexible settings with different requirements: quick and lightweight document search or advanced document search features. Customize search index with custom fields and search your custom data along with document text and metadata.
$ dotnet add package GroupDocs.Search.NETFramework
GroupDocs.Search for .NET is a powerful full-text search API that allows you to search through over 70 document formats in your applications. To make it possible to search instantly across thousands of documents, they must be added to the index.
First of all, you need to create an index. Documents will be processed and added to the index in a special format that provides very high search speed. The following example shows how to create an index on disk.
string indexFolder = @"c:/MyIndex/";
Index index = new Index(indexFolder);
Once the index is created, you can add documents to it that you want to search. Adding documents to the index takes some time to convert the data into a searchable format. The following example shows how to perform indexing synchronously.
string documentsFolder = @"c:/MyDocuments/";
index.Add(documentsFolder);
After indexing your documents, you can search the index. The example below shows how to perform simple search in the index.
string query = "Einstein";
SearchResult result = index.Search(query);
Search results can be seen highlighted in the text of the entire document or in fragments of text. The following example shows how to highlight search results in the text of an entire document in HTML format.
if (result.DocumentCount > 0)
{
FoundDocument document = result.GetFoundDocument(0);
OutputAdapter outputAdapter = new FileOutputAdapter(OutputFormat.Html, @"c:\Highlighted.html");
DocumentHighlighter highlighter = new DocumentHighlighter(outputAdapter);
index.Highlight(document, highlighter);
}
Below is a complete example code for a fuzzy search with an acceptable number of differences of 2 characters.
string indexFolder = @"c:\MyIndex\";
string documentsFolder = @"c:\MyDocuments\";
string query = "Deoxyribonucleic";
// Creating an index in the specified folder
Index index = new Index(indexFolder);
// Indexing documents from the specified folder
index.Add(documentsFolder);
// Creating the fuzzy search algorithm
SearchOptions options = new SearchOptions();
options.FuzzySearch.Enabled = true;
options.FuzzySearch.FuzzyAlgorithm = new TableDiscreteFunction(2);
// Search in index
SearchResult result = index.Search(query, options);
The following listing shows a complete code example for searching for different word forms in the index.
string indexFolder = @"c:\MyIndex\";
string documentsFolder = @"c:\MyDocuments\";
// Creating an index in the specified folder
Index index = new Index(indexFolder);
// Indexing documents from the specified folder
index.Add(documentsFolder);
// Enabling search for word forms
SearchOptions options = new SearchOptions();
options.UseWordFormsSearch = true;
// Search in the index
SearchResult result = index.Search("relative", options);
// The following words can be found:
// relative
// relatives
// relatively
The following code example demonstrates all stages of the reverse image search.
string indexFolder = @"c:\MyIndex";
string documentFolder = @"c:\MyDocuments";
// Creating an index
Index index = new Index(indexFolder);
// Setting the image indexing options
IndexingOptions indexingOptions = new IndexingOptions();
indexingOptions.ImageIndexingOptions.EnabledForContainerItemImages = true;
indexingOptions.ImageIndexingOptions.EnabledForEmbeddedImages = true;
indexingOptions.ImageIndexingOptions.EnabledForSeparateImages = true;
// Indexing documents in a document folder
index.Add(documentFolder, indexingOptions);
// Setting the image search options
ImageSearchOptions imageSearchOptions = new ImageSearchOptions();
imageSearchOptions.HashDifferences = 10;
imageSearchOptions.MaxResultCount = 100;
imageSearchOptions.SearchDocumentFilter =
SearchDocumentFilter.CreateFileExtension(".zip", ".png", ".jpg");
// Creating a reference image for search
SearchImage searchImage = SearchImage.Create(@"c:\MyDocuments\image.png");
// Search in the index
ImageSearchResult result = index.Search(searchImage, imageSearchOptions);
Aspose | GroupDocs | Advanced Document Search | Indexing API | .NET Search Library | Boolean Search | Fuzzy Search | Metadata Search | Full-Text Search | Field Search | Regular Expressions Search | Custom Search Ranking | Indexing Optimization | Distributed Search Network | Reverse Image Search | Search API | .NET Document Search | Document Indexing API | GroupDocs.Search for .NET | Text Search API | Search Results Highlighting | Document Metadata Search | Snippets Extraction | Wildcard Search | Search API for .NET