Page 1 of 1

Highlight search terms

Posted: 25 Jul 2013, 22:27
by feader
Recently, I used the search function of Tiny Tiny RSS. Worked fine, only I thought it would be nice if the search terms were highlighted in the feed content, like they are when one queries the Google Cache.

Re: Highlight search terms

Posted: 26 Jul 2013, 01:47
by imsinfo
I wrote a similar post View Topic. I did not get any responses. Since then my company paid a freelancer to achieve this and the results of the plugin were not consistent. It was implemented poorly using a bad hook and is only compatible with MySQL. The other issue is it times out a lot making it unreliable and will prevent feeds from displaying when this happens.

My company is willing to share this coding with the community for improvement and personal use but the coding needs to be fixed or completely re-developed. I am sure this code could be used for the search and filters. Since I am not a programmer I don't want to put it on the forums for everyone else until it is a fully functional plugin, especially since I cannot provide support for it. If this is something you would be interested in PM me and I can get the code your way. If anyone would be interested in coding / fixing this plugin my company would be willing to pay (if reasonable) for your time.

Filtering is an extremely powerful tool for our company and having the highlighting would make it a lot easier for us to refine our filters while determining the focal point of the articles being flagged.Tiny RSS has been an extreme help in our project research we do surpassing all of the other readers we have tried in the past (Thanks Fox!).

Re: Highlight search terms

Posted: 26 Jul 2013, 04:46
by gbcox
Not sure what your freelancer did but I did a quick google search and found where this could be accomplished via the sphinx buildexcerpts function. I'll dig in a little deeper...
http://sphinxsearch.com/docs/2.0.8/api- ... erpts.html

Re: Highlight search terms

Posted: 26 Jul 2013, 23:21
by imsinfo
The issue with the freelancer was he "made it work", not "made it work right"so to say. Poor implementation overall. Looking at the link seems to show a viable method, but I am unsure how this gets implemented correctly. Thanks for looking into this, any other help / point in the right direction is greatly appreciated.

Re: Highlight search terms

Posted: 31 Jul 2013, 14:56
by fox
https://github.com/gothfox/Tiny-Tiny-RS ... 568db5ea4e

Only works for article content (search also matches title, author, etc) and combined mode.

Image

Re: Highlight search terms

Posted: 31 Jul 2013, 22:52
by feader
Looks good, but it seems that this guy is right; because the XPath function contains in the query

Code: Select all

$elements = $xpath->query('//*[contains(.,"'.$word.'")]');

is case sensitive, the highlighting in the article content is so (Yes, I actually tested this before posting here). A complete solution probably would have to test every possible capitalization of $word, but IMO the three additional tests

Code: Select all

strtolower($word), strtoupper($word), ucfirst(strtolower($word))

would suffice.

Thank you! :)

Re: Highlight search terms

Posted: 01 Aug 2013, 08:57
by fox
Yes, xpath contains() is case sensitive, I figured it was still worth using this approach for performance reasons (going through every domtext is quite slow).

I'll try to add this hack you proposed later (it would be great if you sent a pull request tho). :)