• Resolved TwoThirdsWater

    (@twothirdswater)


    I’ve enabled searching in the middle of words (using the filter), and ‘Highlight query terms in titles’.

    However, when a search term is in the middle of a word for example ‘roo’ in the middle of ‘macaroon’, the function ‘relevanssi_the_title’ doesn’t return the phrase with the term highlighted. It does work fine when the term is at the start or end of a word, for example ‘mac’ in ‘macaroon’.

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

    (@msaari)

    That is correct. The middle-of-the-word searching only applies to search queries, it has no effect on highlighting. There’s currently no way to change that; middle-of-the-word highlighting is not available, because with short words, it creates very messy results.

    I can throw in a filter hook in the next version so that middle-of-the-word highlights can be enabled that way.

    Thread Starter TwoThirdsWater

    (@twothirdswater)

    Thanks for confirming the behavior @msaari

    I appreciate ours is an edge use case, but if a filter could be made available to enable this it would be great please. We are using relevanssi on a REST api method to quickly filter lots of text based on very fuzzy matching so middle word highlight would really enhance this. Thank you in advance!

    Plugin Author Mikko Saari

    (@msaari)

    If you want a hotfix, modify /lib/excerpts-highlights.php and add

    $regex = apply_filters( 'relevanssi_highlight_regex', $regex, $pr_term );

    before this line:

    $content .= ' ';

    Then you can use this filter hook to modify the regex:

    add_filter( 'relevanssi_highlight_regex', function( $regex, $pr_term ) {
      return "/($pr_term)/iu";
    }, 10, 2 );
    Thread Starter TwoThirdsWater

    (@twothirdswater)

    Hotfix works a treat. Thank you!

    Amazing & speedy support @msaari … I very much appreciate it.

    Thread Starter TwoThirdsWater

    (@twothirdswater)

    Marking resolved.

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

The topic ‘Search term in middle of word not highlighted by relevanssi_the_title’ is closed to new replies.