Search Hi-Light
2 posts by 2 authors in: Forums > CMS Builder
Last Post: March 31, 2015 (RSS)
By Perchpole - March 30, 2015
Hello, All
I had thought my cmsb search facilities were fine until I realised that we can now use 'MultiSearch'. It's great. Just what I need. So now I'm in the process of updating loads of sites....
I've been a iTools customer for so long that I remember the days of their standalone site search script. That was nearly 15 years ago! The one thing it had that Cmsb does not is a search word hi-lighter.
Could we add the same functionality to MultiSearch?
:0)
Perchpole
By gregThomas - March 31, 2015
Hi Perch,
You can do that using the following method:
<!-- show errors -->
<?php if ($searchDetails['invalidPageNum']): ?>
Results page '<?php echo $searchDetails['page']?>' not found, <a href="<?php echo $searchDetails['firstPageLink'] ?>">start over >></a>.<br/>
<?php elseif ($searchOptions['keywords'] && $searchDetails['noRecordsFound']): ?>
No records matched search query!<br/><br/>
<?php elseif ($searchOptions['keywords'] == ""): ?>
Enter a keyword to search.<br/><br/>
<?php endif ?>
<!-- STEP2: Display Record List -->
<?php foreach ($searchRows as $record): ?>
<?php
$record['_title'] = str_ireplace(@$_REQUEST['q'], "<i>" . @ucfirst($_REQUEST['q']) . "</i>", $record['_title']);
$record['_summary'] = str_ireplace(@$_REQUEST['q'], "<i>" . @ucfirst($_REQUEST['q']) . "</i>", $record['_summary']);
?>
<a href="/<?php echo $record['field1'] ?>"><?php echo $record['_title'] ?></a><br/>
<?php if ($record['_summary']): ?>
<?php echo $record['_summary']); ?><br/>
<?php else: ?>
No description available for page.<br/>
<?php endif ?>
<a href="/<?php echo $record['field1'] ?>" style="color: #008000"><?php echo $record['field1'] ?></a><br/><br/>
<?php endforeach ?>
<!-- /STEP2: Display Record List -->
So the code above searches the returned title and summary and replaces the search term with itself, but with italic tags. You can read about the str_ireplce function here: http://php.net/manual/en/function.str-ireplace.php
Cheers,
Greg
PHP Programmer - interactivetools.com