Build your full text search solution in C#
Tags: webdev, dotnet, csharp, searchapi
Published: 2019-11-22 08:17:01

There are two main steps to perform or implement full text search.
<!-- wp:list -->
<ul>
<li>Indexing</li>
<li>Search process</li>
</ul>
<!-- /wp:list -->
Before we leap into the details, let’s get an overview of this technique. Full text search is basically a more advanced way to search a text/query over a collection of documents in a computer. This approach quickly finds all instances of a term and it works by using text indexes.

One of the examples of full text search implementation is in Word processors and text editors. It helps you to find a phrase or word anywhere in the document.
# API Usage
GroupDocs.Search for .NET is a full text search, back-end API that can be integrated in any .NET application without any third party tool or software dependency. It allows you to search over a <a href="https://docs.groupdocs.com/display/searchnet/Supported+Document+Formats">multitude</a> of document formats in your applications. To make it possible to search instantly across thousands of documents, they must be added to the index. All you have to do is to add <a href="https://downloads.groupdocs.com/search/net">DLL</a> reference in your project in order to get started.

# Indexing
If you are supposed to perform search over a large number of documents with different or same file formats, you need to create an index.

**What is an index?**

An index possesses scanned text of all the documents. Therefore, when you are going to perform a search operation (search a specific query), only the index is referenced, rather than the text of the original documents.

**Index creation**

It can be created in memory or on disk. An index created in memory cannot be saved after exiting your program. In contrast, an index created on disk may be loaded in the future to continue working. The following example shows how to create an index on disk.
{% gist https://gist.github.com/GroupDocsGists/932dafc08016292a3aa473cca0d50930 %}

# Perform Search
When documents are indexed, the index is ready to handle search queries. Following types of search queries are supported:

<!-- wp:list -->
<ul>
<li>Faceted</li>
<li>Simple</li>
<li>Case sensitive</li>
<li>Boolean</li>
</ul>
<!-- /wp:list -->

See complete list in this <a href="https://docs.groupdocs.com/display/searchnet/Features+Overview#FeaturesOverview-Searching">article</a>.

{% gist https://gist.github.com/GroupDocsGists/a2e55bfc7b67d19a963bb91f76c5b135 %}

Lets go through a use-case. Suppose we have multiple documents (Word, PDF, Excel and HTML) and we want to perform a specific search query (search term “video”) over them.

{% gist https://gist.github.com/GroupDocsGists/eaa4ea35ded2e19f062eb12d7499fcdb %}

We will get document path and search term occurrences in all the documents available in _documentFolder_.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/74er8343x0y1nbulig1n.JPG)

Lets generate output HTML with highlighted search results.

{% gist https://gist.github.com/GroupDocsGists/1f391adf95ca5a55a79e03aa40b520c5 %}

As an output, we will get 6 HTML files. Each file will show content of a different document (e.g. excel.xlsx, source.docx, target.docx) with highlighted search term/word. Given below is the output of _excel.xlsx_ and _source.docx_ files.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/k13gqisp825qfuioz3hc.JPG)

We have an open-source example <a href="https://github.com/groupdocs-search/GroupDocs.Search-for-.NET">project</a> that you can use in order to evaluate API features. Visit <a href="https://blog.groupdocs.com/category/search/">blog</a> to get more updates.