Search Utility

7 posts by 5 authors in: Forums > CMS Builder
Last Post: July 5, 2010   (RSS)

By nmsinc - June 29, 2010

[font "Times New Roman"]I’m looking for a search utility or code that prints a portion of the content description with the words matched and highlighted – similar to that of Google![/#000000]

[font "Times New Roman"] [/#000000]

[font "Times New Roman"]Example Search: [/#000000]

[font "Times New Roman"]Content Text Search = “Jon”[/#000000]

[font "Times New Roman"] [/#000000]

[font "Times New Roman"]Return: [/#000000]
  1. [font "Times New Roman"]Jon John’s fishing hole[/#000000]


[font "Times New Roman"]…Content description. Jon John’s Fishing hole, established January 31, 1910 is one of America’s finest retreats. Bass masters come from every state in the union on July 4th to show the world their craft. Come see….[/#000000]

[font "Times New Roman"] [/#000000]

[font "Times New Roman"]This would be a terrific add-on to the CSM Builder![/#000000]

[font "Times New Roman"] [/#000000]

[font "Times New Roman"]Any help would be appreciated.[/#000000]
nmsinc

Re: [nmsinc] Search Utility

By Jason - June 30, 2010

Hi,

If you have the text you want to search for in a variable, you can do a search/replace on your content.

for example, say you have your content in a field called "description" and your search text in a variable call "search". You could use code like this:

<?php
$content = $record['description'];

$content=str_replace($search,"<b>$search</b>",$content);

echo $content;
?>


What this code does is find's all the instances of the search text in the description field and places <b> tags around them.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [nmsinc] Search Utility

By nmsinc - June 30, 2010

Thanks Jason,



[font "Tahoma"]That would work fine for a content field that contains less then 1,000 characters, ours can contain 5,000 to 20,000 and I do not want the search result to list the entire field, I only need 25 to 30 words within the field that contain the requested word(s) asked for in the search similar to what one would expect to see in the result listing of a Google search – further help would be appreciated.[/#000000]

Ray
nmsinc

Re: [nmsinc] Search Utility

By flamerz - June 30, 2010

if you need heavy weapons for searching, i use this one:

http://www.wrensoft.com/zoom/screen_images.html

(im not related to that company... just user)

regards..

Re: [nmsinc] Search Utility

By Jason - June 30, 2010

Hi Ray,

If you want to limit the number of times the search word is highlighted, you can try this:

<?php
$content = $record['description'];
$limit=25;
$content=preg_replace("/$search/","<b>$search</b>",$content,$limit);

echo $content;
?>


You can set the variable $limit to the number of times you want the word to be highlighted.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [nmsinc] Search Utility

By zip222 - July 1, 2010

What about using Google Site Search. I just used it for the first a few weeks back and I am very impressed with it.

http://www.google.com/sitesearch/

It only costs $100 per year, and provides great feedback through google analytics.