Sometimes, when I search my forum, I get search results with a title and post meta (date, poster name, etc.) but the context of the search term is not shown. It appears this piece of code is returning nothing (in bb-templates/search.php):
<?php echo show_context($q, $bb_post->post_text); ?>
Here’s the function from bb-includes/formatting-functions.php, which I don’t understand:
function show_context( $term, $text ) {
$text = strip_tags($text);
$term = preg_quote($term);
$text = preg_replace("|.*?(.{0,80})$term(.{0,80}).*|is", "... $1<strong>$term</strong>$2 ...", $text, 1);
$text = substr($text, 0, 210);
return $text;
}
The source of the search results page just shows
where that context would be shown.
Is it possible that only the first (however many) characters/words are searched and used for context? It seems like when the results are missing, it’s because the search term appears late in a lengthy post.
In one instance I checked, the search term is word 674, around 3796 characters into the post. Total length of that post is 1360 words, 7546 characters.
In another instance, the search term is word 1423, starting around character 8487. Total length on this post is 2661 words, 15604 characters.
It has happened in other instances, but I never looked into where the term appears in the post to see if that’s related at all. Maybe it’s not related at all to where the search term is in the post, but just how long the post is?
Also: I have edited the search.php file (should have put a copy in my-templates/search.php, but I didn’t know then what I know now) BUT the same results happen with the stock bb-templates/search.php
.
Any ideas?
Thanks