Posted on

Non-ASCII highlights

Relevanssi has problems with highlighting terms when non-ASCII alphabet are used. The highlights don’t work with Cyrillic alphabet, for example.

This is a problem with the regular expression I’m using to find the terms in the text. The regular expression uses word boundaries to find terms that are at the beginning or at the end of a word. That way a term that appears inside another word doesn’t get highlighted. If you search for ‘cat’, Relevanssi would highlight ‘catastrophe’ or ‘cat‘, but not ‘dedicated’.

However, the word boundaries are only recognised in ASCII characters (a-z, 0-9, pretty much). This means that Relevanssi can’t find any terms to highlight in Cyrillic text or other non-ASCII alphabets.

Relevanssi 2.8 added a feature to fix this (and Premium 1.4 will add it too). It’s a checkbox that eases the restriction a bit: if you uncheck it, Relevanssi won’t care about word boundaries. It’ll highlight every occasion of the search term, also inside other words. It’s not as clean as the original highlighting regexp, but it works.

5 comments Non-ASCII highlights

  1. Is it possible to provide alternatives for special characters (eg. Romanian characters) in order for Relevanssi to highlight the results with/without special characters (eg. ă, â = a ? For instance, if the searched term is ”vânzare”, Relevanssi should highlight both ”vânzare” (with special character) and ”vanzare” (without special character).

    1. No, not at the moment at least. The highlighting is done with a regular expression rule, and in theory it’d be possible to modify the regex so that it would catch alternate versions. It would not be impossible to provide a filter that you could use to modify the regex. Would that be helpful?

  2. Hi,
    The term highlight works perfectly with me for Arabic (UTF-8) texts, even in the free version.
    However, is there an option to change the color of the highlighted text? currently it becomes bold, but it is not recongizable much due to the font i use.
    it definity detects the word, but can i change the color to yellow for example?
    thanks

    1. Yes, see Relevanssi settings: there’s some settings you can adjust to change the highlighting from bolding to background color and you can also adjust the color.

Leave a Reply

Your email address will not be published. Required fields are marked *