FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum » FUDforum Suggestions » Highlighting keywords in search results
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Highlighting keywords in search results [message #25008 is a reply to message #24451] Sun, 22 May 2005 06:46 Go to previous messageGo to previous message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma:
Senior Member
Administrator
Core Developer
Hi,

Replace the following function in lib.js and let us know if it helped or not:

function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag)
{
        // find all occurences of the search term in the given text,
        // and add some "highlight" tags to them (we're not using a
        // regular expression search, because we want to filter out
        // matches that occur within HTML tags and script blocks, so
        // we have to do a little extra validation)
        var newText = "";
        var i = 0, j = 0;
        var before_c, before_c;
        var lcSearchTerm = searchTerm.toLowerCase();
        var lcBodyText = bodyText.toLowerCase();

        while ((i = lcBodyText.indexOf(lcSearchTerm, i)) > 0) {
                before_c = lcBodyText.charCodeAt(i-1);
                after_c  = lcBodyText.charCodeAt(i+searchTerm.length);
                if (lcBodyText.lastIndexOf(">", i) >= lcBodyText.lastIndexOf("<", i)) {
                        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
                                if ( (before_c < 65 || before_c > 122) && (after_c < 65 || after_c > 122) ) {
                                        newText += bodyText.substring(j, i) + highlightStartTag + bodyText.sub
str(i, searchTerm.length) + highlightEndTag;
                                        i += searchTerm.length;
                                        j = i;
                                        continue;
                                }
                        }
                }
                i++;
        }
        newText += bodyText.substring(j, bodyText.length);

        return newText;
}


Best regards.

Frank
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Template tree view
Next Topic: May we have ability to show some forums only to selected users?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 03:22:03 GMT 2024

Total time taken to generate the page: 0.04062 seconds