relevanssi_excerpt_gap

apply_filters( 'relevanssi_excerpt_gap', int $gap, int $count_words, int $excerpt_length )

Adjusts the gap between excerpt candidates. This filter hook can be used to modify the way this excerpt-building optimization technique is used.

Parameters

$gap
(int) The gap between excerpt candidates, default floor( $count_words / 200 - $excerpt_length ).

$count_words
(int) The number of words in the content.

$excerpt_length
(int) The number of words in the excerpt.

More information

In versions 2.14.0 (Premium) and 4.12.0 (free) a new method of optimizing excerpt creation in long posts was introduced. Previously Relevanssi would simply take excerpt-length snippets from the post and see which of those is the best excerpt. If the excerpt is 30 words, then Relevanssi would take first 30 words, next 30 words, next 30 words and so on.

This is fine for shorter posts, but in long posts, this takes surprisingly long. Now Relevanssi will skip parts of the post. If there are more than 200 excerpt candidates, ie. the post is longer than 200 times the excerpt length, Relevanssi will skip words so that it will only create 200 excerpt candidates, but those candidates will the distributed evenly in the post.

Of course, this can mean that if the search term appears only rarely in the content, Relevanssi may skip it. If nothing is found, Relevanssi will then create the excerpt around the first match it finds in the content.

This filter hook can be adjusted to change how this process works. To disable this optimization feature completely, return 0:

add_filter( 'relevanssi_excerpt_gap', '__return_zero' );

To optimize further and only check hundred candidates per post:

add_filter( 'relevanssi_excerpt_gap', function( $gap, $count_words, $excerpt_length ) {
	return floor( $count_words / 100 - $excerpt_length )
}, 10, 3 );