Forums / Developer / search result highlighted with search keyword

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

eZ debug

Timing: Jan 18 2025 15:55:01
Script start
Timing: Jan 18 2025 15:55:01
Module start 'content'
Timing: Jan 18 2025 15:55:02
Module end 'content'
Timing: Jan 18 2025 15:55:03
Script end

Main resources:

Total runtime1.0375 sec
Peak memory usage4,096.0000 KB
Database Queries203

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0084 589.2734180.8125
Module start 'content' 0.00840.9007 770.0859578.0938
Module end 'content' 0.90910.1284 1,348.1797337.3672
Script end 1.0375  1,685.5469 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00460.4454210.0002
Check MTime0.00160.1519210.0001
Mysql Total
Database connection0.00130.129110.0013
Mysqli_queries0.952191.76042030.0047
Looping result0.00240.22782010.0000
Template Total0.990995.520.4954
Template load0.00250.237720.0012
Template processing0.988495.264520.4942
Template load and register function0.00020.015310.0002
states
state_id_array0.00120.114910.0012
state_identifier_array0.00210.207020.0011
Override
Cache load0.00220.2084450.0000
Sytem overhead
Fetch class attribute can translate value0.00110.102730.0004
Fetch class attribute name0.00100.101170.0001
XML
Image XML parsing0.00080.079030.0003
class_abstraction
Instantiating content class attribute0.00010.005590.0000
General
dbfile0.00810.7822270.0003
String conversion0.00000.000830.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 32
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs