relevanssi_punctuation_filter

apply_filters( 'relevanssi_punctuation_filter', array $replacement_array )

This filter hook controls the default replacements for punctuation removal.

Parameters

$replacement_array
(array) An array of replacement pairs: Relevanssi replaces the character in the key with the content in the value.

More information

Like any other search engine, Relevanssi controls what punctuation goes into the index. Relevanssi does the punctuation control in the function relevanssi_remove_punct(), which Relevanssi hooks to the relevanssi_remove_punctuation filter hook. Relevanssi applies the filter in the tokenization, so it applies both in indexing and in searching.

The punctuation control removes tags, replaces some punctuation with specific replacement values, removes unwanted whitespace and then handles the rest of the punctuation. This filter hook controls the replacements. You can adjust some punctuation from Relevanssi advanced indexing settings, but this filter hook is often the best solution for everything else.

Here are the default replacements this filter hook does:

  • ß to ss
  • ı to i
  • ₂ to 2
  • × to a space
  • remove ·, …, €, ®, ©, ™
  • remove soft hyphens
  • replace non-breaking spaces with spaces

Depending on your settings, apostrophes, quotes, hyphens, dashes and ampersands may be removed, replaced with spaces or converted into temporary strings, which Relevanssi later converts back to the original characters.

Relevanssi replaces everything else with a space (the relevanssi_default_punctuation_replacement filter controls this). If you want to, for example, remove underscores instead of replacing them with spaces, that’s easy with this filter hook. Add this to your site:

add_filter( 'relevanssi_punctuation_filter', 'rlv_adjust_punctuation' );
function rlv_adjust_punctuation( $replacements ) {
    $replacements['_'] = '';
    return $replacements;
}

For more drastic changes to the punctuation control, add new functions to the relevanssi_remove_punctuation filter hook or remove the existing function and replace it with your own.