Support » Plugin: Relevanssi - A Better Search » [Plugin: Relevanssi – A Better Search] Incorrect excerpts for posts with tab characters

  • 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/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Thanks, I’ll take a look at this.

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Relevanssi – A Better Search] Incorrect excerpts for posts with tab characters’ is closed to new replies.