Hi @swinggraphics
I would propose to add tags to the search index, to the separate cluster “my_tags” and then assign this cluster a biggest weight (1).
So these posts will be ordered much higher than others when any tag is matched.
The same way you can apply to H2 texts in content – first you need to find those texts (using preg_match for example), put them to the separate index cluster and assign more weight to this cluster.
Here is how the idea can be implemented with tags:
add_filter('wpfts_index_post', function($index, $post)
{
// Basic tokens
/*
* This piece of code was commented out intentionally to display things
* which was already done before in the caller code
$index['post_title'] = $post->post_title;
$index['post_content'] = strip_tags($post->post_content);
*/
if ($post->post_type == 'my_custom_post_type') { // You need to specify your own post type here
// You can add tags to the index in order to make this post
// searchable by them (means fulltext search by tag name)
$tags = wp_get_post_tags($post->ID);
$t = array();
if (is_array($tags)) {
foreach ($tags as $tag) {
if (isset($tag->name)) {
$t[] = $tag->name;
}
}
}
$index['my_tags'] = implode(' ', $t); // Cluster name is imaginary
}
return $index;
}, 3, 2);
This code will be called on each post update or on full rebuild index.
I’d recommend to update specific post to check how it works.
You also can use WPFTS Settings / Sandbox / Index Tester to see what’s coming to index.
Hope this helps.