An Error Has Occurred!Where can I find 1.7.0.2 ?
The topic or board you are looking for appears to be either missing or off limits to you.
foreach ($searchArray as $word) {usort ($searchArray, "cmp");
if (isset ($ _GET [' searched ']) && isset ($ _GET [' highlight '])) {function cmp($a, $b) {
if (mb_strlen($a) == mb_strlen($b)) {
return 0;
}
return (mb_strlen($a) < mb_strlen($b)) ? 1 : -1;
}/* ------------------------------------------------------------------------ Plugin: Search_Highlight v1.2.0.1 ------------------------------------------------------------------------ Changes: 10/02/08 - Strip_tags added to avoid sql injection and XSS 01/03/07 - Added fies/updates from forum from users mikkelwe/identity (better highlight replacement, additional div around term/removal message) ------------------------------------------------------------------------ Description: When a user clicks on the link from the AjaxSearch results the target page will have the terms highlighted. ------------------------------------------------------------------------ Created By: Susan Ottwell ([email protected]) Kyle Jaebker ([email protected]) ------------------------------------------------------------------------ Based off the the code by Susan Ottwell (www.sottwell.com) http://modxcms.com/forums/index.php/topic,1237.0.html ------------------------------------------------------------------------ CSS: The classes used for the highlighting are the same as the AjaxSearch ------------------------------------------------------------------------ Notes: To add a link to remove the highlighting and to show the searchterms put the following on your page where you would like this to appear: <!--search_terms--> Example output for this: Search Terms: the, template Remove Highlighting Set the following variables to change the text: $termText - the text before the search terms $removeText - the text for the remove link ------------------------------------------------------------------------ */ function cmp($a, $b) { if (mb_strlen($a) == mb_strlen($b)) { return 0; } return (mb_strlen($a) < mb_strlen($b)) ? 1 : -1; } if(isset($_GET['searched']) && isset($_GET['highlight'])) { // Set these to customize the text for the highlighting key // -------------------------------------------------------- $termText = '<div class="searchTerms">Запрос: '; $removeText = 'Отменить подсветку'; // -------------------------------------------------------- $highlightText = $termText; $searched = strip_tags(urldecode($_GET['searched'])); $highlight = strip_tags(urldecode($_GET['highlight'])); $output = $modx->documentOutput; // get the parsed document $body = explode("<!--highlight-->", $output); // break out the head $searchArray = explode(' ', $searched); // break apart the search terms $highlightClass = explode(' ',$highlight); // break out the highlight classes $j = 0; // store initial order of terms $initOrder = array(); foreach($searchArray as $word) { $j++; $initOrder[$word] = $j; $class = $highlightClass[0].' '.$highlightClass[$j]; $highlightText .= ($j > 1) ? ', ' : ''; $highlightText .= '<span class="'.$class.'">'.$word.'</span>'; } // sorting of terms according to decrease of their length usort($searchArray, "cmp"); $i = 0; // for individual class names foreach($searchArray as $word) { $i++; $j = $initOrder[$word]; $class = $highlightClass[0].' '.$highlightClass[$j]; $pattern = '/' . preg_quote($word) . '(?=[^>]*<)/iu'; $replacement = '<span class="' . $class . '">${0}</span>'; $body[1] = preg_replace($pattern, $replacement, $body[1]); } $output = implode("<body>", $body); $removeUrl = $modx->makeUrl($modx->documentIdentifier); $highlightText .= '<br /><a href="'.$removeUrl.'" class="ajaxSearch_removeHighlight">'.$removeText.'</a></div>'; $output = str_replace('<!--search_terms-->',$highlightText,$output); $modx->documentOutput = $output; }
$cleansedWords. = $word. ' '; //to remove a punctuation
$word = ereg_replace ("[[:blank:] [:punct:]] +", "", $word);define (MAX_TERMS, '10');
$maxCount = 0;
foreach($searchWords as $word){
if ($word != '' &&
!in_array(strtolower($word),$snippetNameArray) &&
((!$useAllWords) && (strlen($word) >= $minChars) ||
($searchStyle == 'partial') && (strlen($word) >= $minChars) ||
(strlen($word) >= $minChars && $useAllWords && $searchStyle == 'relevance'))
){
// to remove a punctuation
$word = ereg_replace("[[:blank:][:punct:]]+", "", $word);
$cleansedWords .= $word.' ';
$maxCount++;
}
if ($maxCount == MAX_TERMS) break;
}Incorrect highlighting of resultsAjaxSearch runs as "partial" search which means that when you search for example china wall, you search the first extract which contains "china" and then the first extract which contains "wall". Not the extract "china wall". And you will get the same extract with "china" highligthed and a second one (the same) with "wall" highligthed.
Shortly. The superfluous is highlighted. The necessary is not highlighted.
At first to highlight the terms having the big length. At the subsequent highlightings of shorter terms it is necessary to check, whether they enter in longer already highlighted. If yes, highlighting of short words to cancel.
I perfectly understand what about you speak. But on my site I do a little in another way.
AjaxSearch runs as "partial" search which means that when you search for example china wall, you search the first extract which contains "china" and then the first extract which contains "wall". Not the extract "china wall". And you will get the same extract with "china" highligthed and a second one (the same) with "wall" highligthed...
This discussion is closed to further replies. Keep calm and carry on.