API Reference / API Parameters / replaceSynonymsInHighlight
Type: boolean
Engine default: false
Parameter syntax
'replaceSynonymsInHighlight' => true|false

Can be used in these methods:

About this parameter

Whether to highlight and snippet the original word that matches the synonym or the synonym itself.

For example, let’s say you set up home as a synonym for house, and the user types home. Synonym logic will match any record that contains ‘house’ with the synonym ‘home’. This setting will replace the word ‘house’ with ‘home’ in the response. The effect of this is that all highlighting and snippeting will be on the synonym ‘home’. Without this setting, the original word ‘house’ would have been returned and highlighted and snippeted.

Usage notes

  • When true, highlighting and snippeting will use words from the query rather than the original words from the objects.

  • When false, highlighting and snippeting will always display the original words from the objects.

  • Multiple words can be replaced by a one-word synonym, but not the other way round. For example, if “NYC” and “New York City” are synonyms, searching for “NYC” will replace “New York City” with “NYC” in highlights and snippets, but searching for “New York City” will not replace “NYC” with “New York City” in highlights and snippets.

Examples

Set default synonyms highlights replacement mode

1
2
3
$index->setSettings([
  'replaceSynonymsInHighlight' => false
]);
1
2
3
$results = $index->search('query', [
  'replaceSynonymsInHighlight' => true
]);
Did you find this page helpful?