Skip to:

Sometimes strange search results (no post_text?)

  • chrishajer


    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?


Viewing 3 replies - 1 through 3 (of 3 total)

  • chrishajer


    Narrowed it down a little bit. When using PHP 5.2.0, the results are odd for some posts, as described above. When using PHP 4.4.4, the search results are normal and as expected. Could be something different with the install or the compiled options. But, this is a little bit of the problem. In the phpinfo, one small thing I noted is that PCRE is version 6.6 in PHP4 and version 6.7 in PHP5. Is there anything else I can check in the phpinfo that would be helpful?



    –selfish bump–

    I coded around this (hack!) to make it work with PHP5, but is anyone seeing the same type of results that I was with PHP5?

    Did you report it as a bug? (if it is one)

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar