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

  1. Alexander Gieg
    Posted 4 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);


    $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!


  2. Mikko Saari
    Plugin Author

    Posted 4 years ago #

    Thanks, I'll take a look at this.

  3. Alexander Gieg
    Posted 4 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);


    $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

  • Relevanssi - A Better Search
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic