Search highlighting is broken

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Search highlighting is broken

Post by cmb » Tue Sep 23, 2014 4:29 pm

Hello Community,

I just found out that the search highlighting is broken, when one searches for multiple words, where one of the words is contained in another.

Consider a page with the word "word". Searching for "word or" will list this page; after clicking on this search result, the page will be shown, with "word" being highlighted. Fine -- well, look at the generated HTML source code:

Code: Select all

<span class="xh_find">w<span class="xh_find">or</span>d</span>
Um, do we really want nested classes? Not a problem per se, but looks a bit clumsy.

Anyway, let's search for "or word":

Code: Select all

w<span class="xh_find">or</span>d
Only "or" is highlighted. Bug.

Now consider a page with the text "उद्धरेदात्मनात्मानं नात्मानमवसादयेत्" (that's Sanskrit, BTW). We search for "रेदात्मनात्मानं नात्मान":

Code: Select all

उद्ध<span class="xh_find">रेदात्म<span class="xh_find">नात्मान</span>ं</span> <span class="xh_find">नात्मान</span>मवसादयेत्
Bug, because the diacritic mark " ं" is separated from "न", which should be "नं", actually.

I'm not sure if it is possible to solve the combining character problem efficiently, and I tend to classify that as "won't fix". Solving the problem that only a partial word is highlighted (second case) should be easy by simply ordering the search words by length.

Thoughts?

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1659
Joined: Wed Dec 17, 2008 5:08 pm

Re: Search highlighting is broken

Post by svasti » Tue Sep 23, 2014 7:32 pm

An interesting problem. Seems to me not so terrible and could be fixed in 1.6.4?
Very cute, using the Sanskrit example, and that you realized that there was a doubling of glyphs.
cmb wrote:Solving the problem that only a partial word is highlighted (second case) should be easy by simply ordering the search words by length.
+1

BTW the Sanskrit says: "Lift yourself up by yourself, don't dispirit yourself." (The word "yourself" makes for the doubling of the glyphs)

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Search highlighting is broken

Post by cmb » Sat Jan 10, 2015 10:48 am

I've fixed the "or word" problem, refactored out XH_highlightSearchWords() and added unit-tests for it which serve as documentation of the mentioned issues (r1448).
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply