• Resolved Pelly Benassi

    (@plasmax)


    Hello, and thank you so much for this wonderful plugin ??

    I’m scratching my head trying to figure out how to only highlight a perfect match without the user having to use quotes (I doubt most of the visitors know about that).

    Is that even possible or should I stop trying?

    See this example, where green is what I want, and I don’t want red to happen.

    My settings:

    So in short, is there any way to only highlight Call of Duty, but not the words Call, of, and Duty individually?

    Thank you!

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

    (@msaari)

    Yeah: use quotes ??

    I suppose you could add a filter that automatically adds quotes around the search terms before excerpts are created, but that will lead to search results without any highlighting when users search with less precise search terms.

    Thread Starter Pelly Benassi

    (@plasmax)

    Yeah, I can use quotes, but honestly who knows about that besides geeks and developers? ??
    Like if you search for Call of Duty on Google, it only highlights the whole sentence in the results, and you certainly don’t need to add quotes for that.

    True a filter like that might work, but like you said it might be too aggressive for other searches :/

    I guess a cool option would be to have individual CSS classes for partials and full sentences, so that if 's' => 'Call of Duty' , then ‘Call of Duty’ gets a CSS class and the individual words get another one. That would at least give the dev an option to not highlight partials.

    I don’t know I’m probably not thinking this through and talking out of my bum haha.

    Either way thanks for your prompt reply and again for this beautiful plugin!

    Plugin Author Mikko Saari

    (@msaari)

    Google is powered by one of the largest and wealthiest corporations in the world; I’m one guy. Comparisons may or may not be useful. When I search for “call of duty”, Google even highlights “CoD-pelit”, which is way beyond what I can provide.

    Also, highlighting individual search terms sometimes makes sense. When you search for “call of duty”, then yeah, you only want highlights for the whole phrase, but if I search for “aurora heathens”, the right thing to do is to highlight both “aurora” and “heathens” separately. Figuring out when to do what takes more intelligence than Relevanssi can have.

    Anyway, I was thinking of something like this:

    add_filter( 'relevanssi_excerpt_query', function( $query ) {
        return '"' . $query . '"';
    } );

    This won’t affect the search results at all, only the excerpts. Now Relevanssi will only highlight full search phrases in the excerpts. However, this does affect excerpt creation, so you’ll see more default excerpts from the beginning of the post.

    I’ll add a new filter hook in the next version (relevanssi_highlight_query) that will filter the query for highlights only. You can then use that filter hook to add quotes around the query to get better excerpts, but with highlights only in full phrases.

    Thread Starter Pelly Benassi

    (@plasmax)

    Hi Mikko sorry for the late reply!
    I’m sorry if my comparison to Google came across as disrespectful but I hope you understand it was just an example, and you’re right in saying that it’s not a fair comparison. You’re doing a fantastic job with Relevanssi, especially for one guy only!

    I’ll play around with your solution, and I’m looking forward to that hook.

    Thank you so much, I’ll go ahead and ask the company to pay for premium as good work shouldn’t go unpaid.

    Take care ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to avoid part of a sentence to be highlighted?’ is closed to new replies.