Hi VanMeter,
Find enclosed, as christmas gift

, a fix (1.6.2
e) for your issue . This download zip file is a fix to the 1.6.2 version of AjaxSearch. About this release look at :
http://modxcms.com/forums/index.php/topic,5357.msg123851.html#msg123851
It ’s a cumulative patch which includes 1.6.2b, 1.6.2c and 1.6.2d fixes
Just for information, this bug is a
true testbook case. Let’s me explain you why ...
Here is the code of the build of the search results which must be displayed :
$toAdd = PrepareSearchContent( $text, $length=200, $search[0] );
strip_tags( $text );
foreach ($search as $searchTerm) {
if (preg_match('/' . preg_quote($searchTerm) . '/i', $text)) {
if ($count > 1) { // The first summary was already extracted above
$toAdd = SmartSubstr( $text , $length=200, $searchTerm );
}
$summary .= preg_replace( '/' . preg_quote( $searchTerm, '/' ) . '/i', '<span class="AS_ajax_highlight AS_ajax_highlight'.$count.'">\0</span>', $toAdd ) . ' ';
First you prepare the content result got from the database (PrepareSearchContent function) by cleaning particulars characters (like Modx Tags)
Then :
- you strip HTML tags (remove tags from the text.
strip_tags is a native php function)
- and for each search term you get a
Smart substring (get 200 characters around you search term)
- then you add the css style to highlight the term found
The prepareSearchContent function is :
function prepareSearchContent( $text, $length=200, $search ) {
....
// Remove modx sensitive tags
foreach ($modRegExArray as $mReg){
$text = preg_replace($mReg,'',$text);
}
// strips tags won't remove the actual jscript
$text = preg_replace( "'<script[^>]*>.*?</script>'si", "", $text );
$text = preg_replace( '/{.+?}/', '', $text);
// $text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is','\2', $text );
// replace line breaking tags with whitespace
$text = preg_replace( "'<(br[^/>]*?/|hr[^/>]*?/|/(div|h[1-6]|li|p|td))>'si", ' ', $text );
return $this->smartSubstr( strip_tags( $text ), $length, $search );
}The goal of this code is to clean the text got from the database and get the first extract (first search term)
The main problem of this code is that :
In the first step, you use the PrepareSearchContent function to clean the code and get the first extract ($toAdd) in same time.
BUT you clean the text ($text) only for this first extract. Because, $text is a local variable cleaned only in the PrepareSearchContent and never returned to the calling code

So, for the following search terms, the code is not cleaning. The strip_tags function has worked only for the first search term. Is typically the issue you raised.
for the correction of this issue look at :
- snippet-ajaxSearch-tpl.php : lines 499 to 504
- AjaxSearch.php : lines 98 to 103
- AjaxSearch.inc.php (includes folder) : lines 213 to 236
Install this fix and let me know if it ’s ok for you now. Overwrite the snippet code of AjaxSearch with the content of
AjaxSearch.inc.php snippet-ajaxSearch-tpl.php
I have installed this fix on my web site, so do not hesitate

, try it with "world phonecard" as search terms on
my site
But keep in mind, because it’s a limitation, that the
strip_tags function works well only if the html tags are correctly writed and ended.
Ryan, not sure,
but i think that this correction will fix the issue raised by Paul :
http://modxcms.com/forums/index.php/topic,5357.msg128909.html#msg128909
Ok could i check that ?
In fact the strip_tags is only applied on the text content not on title nor on description as suggested by Paul. I will correct that.
Regarding
http://modxcms.com/forums/index.php/topic,20136.msg124792.html#msg124792
I will ask to Rick.
The version 1.7 of AjaxSearch which is in preparation, will include this new fix and some others enhancements.
My last concern is that when a search string is found inside a html tag (e.g an image name), this term could be erased before the displaying of the result. So in this case, i think i will not displayed the result as the search term can’t be seen and highlighted