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 ezpublish 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 ezpublish..
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,
ezpublish 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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 19:05:29
Script start
Timing: Jan 18 2025 19:05:29
Module start 'layout'
Timing: Jan 18 2025 19:05:29
Module start 'content'
Timing: Jan 18 2025 19:05:29
Module end 'content'
Timing: Jan 18 2025 19:05:29
Script end

Main resources:

Total runtime0.0222 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0095 589.1797152.6406
Module start 'layout' 0.00950.0039 741.820339.4766
Module start 'content' 0.01340.0065 781.296993.4922
Module end 'content' 0.01980.0023 874.789138.3047
Script end 0.0222  913.0938 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003616.2006140.0003
Check MTime0.00146.1363140.0001
Mysql Total
Database connection0.00104.602210.0010
Mysqli_queries0.003415.210830.0011
Looping result0.00000.062310.0000
Template Total0.00188.210.0018
Template load0.00104.417610.0010
Template processing0.00083.715510.0008
Override
Cache load0.00073.278510.0007
General
dbfile0.00031.191680.0000
String conversion0.00000.042940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs