# Highlighting search results
This article describes how to highlight search results in the text of a document.
This page describes how to highlight search results in the text of a document.
## Hit highlighting in the text of entire document
After performing a search, occurrences of found words and phrases for a particular document can be highlighted in the text of the document using the [highlight](https://reference.groupdocs.com/search/python-net/groupdocs.search/index/highlight/) method of the [Index](https://reference.groupdocs.com/search/python-net/groupdocs.search/index/) class. To do this, a highlighter of the corresponding type must be passed as an argument to the method.
The Index class also provides an overload of the [highlight](https://reference.groupdocs.com/search/python-net/groupdocs.search/index/highlight/) method, which takes an object of the [HighlightOptions](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/highlightoptions/) class as an argument. The [HighlightOptions](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/highlightoptions/) class contains properties for setting the following options:
* [custom_extractor](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/textoptions/custom_extractor/) is an extractor used during indexing, it is necessary if the text of the document was not saved in the index.
* [additional_fields](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/textoptions/additional_fields/) are additional document fields added during document indexing which are also necessary if the document text was not saved in the index.
* [cancellation](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/textoptions/cancellation/) is an object used to cancel the operation.
* [generate_head](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/textoptions/generate_head/) is a flag to specify whether the Head tag is generated in the output HTML. The default value is True.
* [metadata_indexing_options](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/baseoptions/metadata_indexing_options/) is an object for specifying metadata indexing options. This property and the other properties inherited from the [BaseOptions](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/baseoptions/) class (for example, [encoding](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/baseoptions/encoding/), [auto_detect_encoding](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/baseoptions/auto_detect_encoding/) and [ocr_indexing_options](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/baseoptions/ocr_indexing_options/)) specify how the text of the document is extracted; they are necessary if the document text was not saved in the index.
* [use_inline_styles](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/highlightoptions/use_inline_styles/) is a flag to specify whether inline styles or CSS class are used to highlight occurrences. The default value is True.
* [highlight_color](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/highlightoptions/highlight_color/) is a color used to highlight occurrences. The default value is (255, 216, 0).
* [term_highlight_start_tag](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/highlightoptions/term_highlight_start_tag/) is the start tag of the highlighting of the found word. This tag is used only when highlighting in plain text.
* [term_highlight_end_tag](https://reference.groupdocs.com/search/python-net/groupdocs.search.options/highlightoptions/term_highlight_end_tag/) is the end tag of the highlighting of the found word. This tag is used only when highlighting in plain text.
The other options are used for highlighting occurrences in text fragments.
To highlight search results in the text of the whole document, a highlighter of the [DocumentHighlighter](https://reference.groupdocs.com/search/python-net/groupdocs.search.highlighters/documenthighlighter/) class is used. To create a highlighter of this type, you must pass an object of a class derived from the abstract class [OutputAdapter](https://reference.groupdocs.com/search/python-net/groupdocs.search.common/outputadapter/) to its constructor. Details on the output adapters are presented on the page [Output adapters]({{< ref "search/python-net/developer-guide/advanced-usage/searching/output-adapters.md" >}}).
If after generation the text of a document was saved to a file, this file can be opened by an Internet browser to navigate the occurrences of the words found. To navigate the occurrences, the following text is added to the URL in a browser:
#hitN
where N is a number starting from zero. The full document URL in a browser might look like this:
[file:///C:/Text.html#hit0](file:///C:/Text.html#hit0)
The following example demonstrates how to highlight search results in the text of an entire document.
{{< tabs "example1" >}}
{{< tab "Python" >}}
```python
import os
from groupdocs.search import Index, IndexSettings
from groupdocs.search.common import StructureOutputAdapter
from groupdocs.search.highlighters import DocumentHighlighter
from groupdocs.search.options import Compression, HighlightOptions, OutputFormat, TextStorageSettings
# Creating an index settings instance
settings = IndexSettings()
settings.text_storage_settings = TextStorageSettings(Compression.HIGH) # Enabling storage of extracted text in the index
# Creating an index in the specified folder
index = Index("./index", settings)
# Indexing documents from the specified folder
index.add("./documents")
# Search for the word 'Universe'
result = index.search("Universe")
# Highlighting occurrences in the text
if result.document_count > 0:
document = result.get_found_document(0) # Getting the first found document
output_adapter = StructureOutputAdapter(OutputFormat.PLAIN_TEXT) # Creating the output adapter
highlighter = DocumentHighlighter(output_adapter) # Creating the highlighter instance
options = HighlightOptions() # Creating the highlight options
options.term_highlight_start_tag = "
" + fragment + "
\n") ``` {{< /tab >}} {{< tab "documents" >}} {{< tab-text >}} The following sample files are used in this example: [documents/einstein-biography.txt](https://docs.groupdocs.com/search/python-net/_sample_files/developer-guide/advanced-usage/searching/highlighting-search-results/documents/einstein-biography.txt), [documents/nobel-prize.txt](https://docs.groupdocs.com/search/python-net/_sample_files/developer-guide/advanced-usage/searching/highlighting-search-results/documents/nobel-prize.txt) {{< /tab-text >}} {{< /tab >}} {{< tab "Fragments.html" >}} ```textdocuments\einstein-biography.txt
/2026 18:00:18Albert Einstein was a theoretical physicist who
theory of relativity.
In 1905 Einstein published his first paper on