You are here: Overviews > Highlighting Hits > Highlighting each term using different attributes
Close
dtSearch Text Retrieval Engine Programmer's Reference
Highlighting each term using different attributes

How to highlight each search term in a search using a different highlighting attribute.

To highlight each term in a search with different highlighting criteria,

  1. Search using the flags dtsSearchWantHitsByWord, dtsSearchWantHitsArray, and dtsSearchWantHitsByWordOrdinals in SearchJob, so the SearchResults will contain HitsByWord information with the hit offsets of each search term.
  2. Set the flag dtsConvertMultiHighlight in FileConverter
  3. Pass the HitsByWord result from the search results item to FileConverter in FileConverter.HitsByWord. If you set up FileConverter using SetInputItem, this will happen automatically.
  4. Use BeforeHit and AfterHit to pass the highlighting strings as an array, with the first character (which must be punctuation) used as a delimiter.

The words listed in the HitsByWord table will be assigned to the highlight markings listed in BeforeHit and AfterHit. If HitsByWord contains more items than BeforeHit or AfterHit, items in BeforeHit and AfterHit will be reused in order.

Limitations and requirements

Because HitsByWord treats each phrase as a single item, all words in a phrase will have the same color. 

Because SearchResults.UrlDecodeItem does not preserve HitsByWord information, it cannot be used to create a SearchResults object to use with multiple highlighting.

Copyright (c) 1995-2020 dtSearch Corp. All rights reserved.