WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
Incorrect excerpts for posts with tab characters (3 posts)

  1. Alexander Gieg
    Member
    Posted 2 years ago #

    Relevanssi was accurately finding the posts in a site I manage, but for some of those posts the search excerpt it generated was incorrect in that it showed the beginning of the post text, while the word searched was near the end of the text, hence beyond the excerpt's maximum length and thus cut out from it. Other posts had correct excerpts though.

    Looking carefully at both kinds of posts, I noticed the problematic ones all had tab characters. So, in searching around Relevanssi's code, I found the solution. Changing line 1624 from:

    $content = preg_replace("/\n\r|\r\n|\n|\r/", " ", $content);

    to:

    $content = preg_replace("/\n\r|\r\n|\n|\r|\t/", " ", $content);

    makes the issue go away, and now search excerpts appear correctly for all posts.

    I hope this helps!

    http://wordpress.org/extend/plugins/relevanssi/

  2. Mikko Saari
    Member
    Plugin Author

    Posted 2 years ago #

    Thanks, I'll take a look at this.

  3. Alexander Gieg
    Member
    Posted 2 years ago #

    Awesome, thanks!

    By the way, there's another minor improvement I thought that might (or not, I'm not quite sure) help: adding a second preg_replace to convert double (and triple etc.) spaces into single ones, then trimming the result. So, from:

    $content = preg_replace("/\n\r|\r\n|\n|\r/", " ", $content);

    To:

    $content = preg_replace("/\n\r|\r\n|\n|\r/", " ", $content);
    $content = trim(preg_replace("/\s\s+/", " ", $content));

    The \t wouldn't be needed as \s includes it.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags