Forum Discussion

djondinium's avatar
4 years ago

Remove highlight class from messages.search_snippet

Hello all,

We have a custom homepage component built that is showing a few latest threads from our Announcement board. Simple stuff.

The problem is that the 'search_snippet' is highlighting the text if it's the same as the search query. In our case, the Announcement board is called 'news' and if it finds a word 'news' inside the 'search_snippet', it will be highlighted with the 'lia-search-match-lithium' class. 

For now, I'm considering removing it manually with the

 

$('.lia-search-match-lithium').removeClass();

 


As far as I saw, the 'search_snippet' will always return highlighted text. Is there any way around this?

Thank you!

 

  • The "search_snippet" is doing exactly what it is intended to do. So usually don't recommend using that field for that reason (unless to display search results). 

    Otherwise... options include:

    1. Use messages.body instead; then trim HTML with utils.owasp freemarker context object, then trim to X number of characters.
    2. Taking the HTML of messages.search_snippet and doing a ?replace("lia-search-match-lithium","") on the string
  • MattV's avatar
    MattV
    Khoros Staff

    The "search_snippet" is doing exactly what it is intended to do. So usually don't recommend using that field for that reason (unless to display search results). 

    Otherwise... options include:

    1. Use messages.body instead; then trim HTML with utils.owasp freemarker context object, then trim to X number of characters.
    2. Taking the HTML of messages.search_snippet and doing a ?replace("lia-search-match-lithium","") on the string
  • Hi there Matt!

    Thank you very much for the help. It worked like a charm 🙂