An HTML file with highlighted search results can be further processed after generation by the GroupDocs.Search library, for example, using the Aspose.HTML library. You will need to find a tags named hitN (where N is an integer number) and subsequent span tags with the highlighted-term class. Then you need to replace groups of such consecutive tags with single span tags that include the found phrases in their entirety. To highlight with different colors, you need to replace the highlighted-term class with others that correspond to the required colors.
<a title="alice had" name="hit0"><span class="highlighted-term">Alice</span></a> <span class="highlighted-term">had</span>
<span class="highlighted-term-pink">Alice had</span>
Each found word can be marked with its own CSS class so that it is highlighted with its own color.