Page 1 of 1

CMSimple XH version 1.7.2 Search [Workaround and Extention]

Posted: Mon Nov 05, 2018 10:57 am
by simpleSolutions.dk
This is a workoraund for the highlight bug in search function (viewtopic.php?f=10&t=14178|) in CMSimple XH version 1.7.2 ONLY.

Instead of inserting extra tags to highlight search results, keywords are highlighted with javascript.

Now, when I started correcting the search function, I also expanded the class Search in file Serch.php in core CMSimple with sorted results list.

Sorted result list has the following order:
1 exact match
2 All keywords are found on the page
3 only some keywords are found on the page

And finally, if search has only one result, the extended version redirects to the actual page with keywords instead of displaying a result page with link to the page. This work fine with javascript highlights as javascript scroll the page to the first hit.

Changes to the core code will of course be overwritten by the next update of CMSimple XH. By that time, I hope that the the bug is corrected and that the development team implements the extension to the search function itself. The development team is of course welcome to use my code.

Followed files are changed:
tlpfunc.php
Search.php

Download: https://simplesolutions.dk/?SearchHi

Re: CMSimple XH version 1.7.2 Search [Workaround and Extention]

Posted: Mon Nov 05, 2018 7:16 pm
by lck
Hi Jerry,

in your website https://simplesolutions.dk/ the workoraand already seems to be implemented, right?
I tested the search there once, works well, also the direct forwarding to the page, if the search has only one result.

There is one problem. I know normally no one would ever search for a protected space, but I did it with the following result.
1. https://example.com/?search=%C2%A0&function=search
2. the page "Result of your search" is displayed
3. if you now click on a link in the result list, this page will be loaded, but the page freezes, no action possible :? .
After about 40 seconds a popup appears with the message "Seite reagiert nicht ...".
The popup disappears after a few minutes and a blank white page is displayed.

Re: CMSimple XH version 1.7.2 Search [Workaround and Extention]

Posted: Mon Nov 05, 2018 7:43 pm
by simpleSolutions.dk
Well, that's right my site is running extended search.
This is a workaround and I can live with a freezing page after search for protected space.

Re: CMSimple XH version 1.7.2 Search [Workaround and Extention]

Posted: Tue Nov 06, 2018 12:18 pm
by cmb
simpleSolutions.dk wrote:
Mon Nov 05, 2018 10:57 am
Instead of inserting extra tags to highlight search results, keywords are highlighted with javascript.

Now, when I started correcting the search function, I also expanded the class Search in file Serch.php in core CMSimple with sorted results list.

Sorted result list has the following order:
1 exact match
2 All keywords are found on the page
3 only some keywords are found on the page

And finally, if search has only one result, the extended version redirects to the actual page with keywords instead of displaying a result page with link to the page. This work fine with javascript highlights as javascript scroll the page to the first hit.
All in all, I like these improvements. However, according to SemVer patches should contain only backward-compatible bug fixes, but no new features. Since only the currently broken highlighting would qualify as bug, I would suggest to postpone the other improvements to XH 1.8.0.

I'm inclined to suggest to do the insertion of the <span class="xh_find"> with JS instead of PHP for XH 1.7.3. However, it seems we'd only need a small bit of searchhi.js to do this.

Re: CMSimple XH version 1.7.2 Search [Workaround and Extention]

Posted: Tue Nov 06, 2018 3:50 pm
by cmb
cmb wrote:
Tue Nov 06, 2018 12:18 pm
I'm inclined to suggest to do the insertion of the <span class="xh_find"> with JS instead of PHP for XH 1.7.3. However, it seems we'd only need a small bit of searchhi.js to do this.
I think merging https://github.com/cmsimple-xh/cmsimple-xh/pull/373 would be appropriate for XH 1.7.3.

PS: I've noticed that we basically loose our testHighlightSearchWords() unit tests. :(