Forums / Developer / search result highlighted with search keyword

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

search result highlighted with search keyword

Author Message

manoj sharma

Monday 14 September 2009 11:54:54 pm

Hi guyz,

is there any way through which i can make my search result highlighted with some color.

the word which user uses should be highlighted.

example:
user has made a search on "web development".

web development is search keyword, so whenever "web development" comes in the content or in the result.. web development should be highlighted with some color.

i am using Exponential 4.0.1 with ezflow and ezwebin.

thanks & regards,
Manoj Sharma

Jean-Luc Nguyen

Tuesday 15 September 2009 3:36:12 am

Hello,

You can create a new operator, equivalent of php function str_replace().

When you are displaying your results, writing something like:

{foreach $results as $result}
{str_replace( $keyword, concat( '<span style="color:red">', $keyword, '</span>' ), $result.name )}
{/foreach}

Where $results is your search array results, $result is each line of result, and $keyword is your search word.

http://www.acidre.com

manoj sharma

Tuesday 15 September 2009 5:47:37 am

i couldn't found the foreach loop to do this.
i am not fluent with Exponential..
please elaborate more..

thanks & regards,
Manoj

Jean-Luc Nguyen

Tuesday 15 September 2009 7:28:28 am

First, check the default search template code: design/standard/templates/content/search.tpl and searchresult.tpl. On this template, you may have something like:

{section name=SearchResult loop=$search_result show=$search_result sequence=array(bglight,bgdark)}

which is the equivalent of the foreach loop

http://www.acidre.com

manoj sharma

Wednesday 16 September 2009 12:26:48 am

Thanks Jean-Luc Nguyen for taking out time for my post.

but had no luck with searchresult.tpl.

Whatever changes i does on search.tpl or searchresult.tpl. is not viewable on frontend, and there are no override files for them either.

as far as i have studies the code,
Exponential uses ezwebin/design/ezwebin/override/templates/line and files in it to show search result, for folder it will use folder.tpl and for article it will use article.tpl.

what i want is a common script to highlight the searched word (both in heading and in description)..

is there any common way to do this?

Thanks & Regards
manoj

 

Jean-Luc Nguyen

Wednesday 16 September 2009 12:47:23 am

Hello,

I think that before trying to highlight your search results, try to override default search templates; do not edit design/standard/templates/content/search.tpl and searchresult.tpl, but override them by creating them on your extension, something like extension/your_extension/design/your_frontoffice_design/templates/content/search.tpl and searchresult.tpl.

http://www.acidre.com