public function searchHighlighter($query, $body) { /*$searchTerms = explode(' ', str_replace(')', '', str_replace('(', '', str_replace(')(', ' ', $query)))); $len = count($searchTerms); $chunk = ''; $maxChar = 160; for ($i = 0; $i < $len; $i++) { if (preg_match('/' . $searchTerms[$i] . '/', $body)) { $pos = strpos($body, $searchTerms[$i]); if (($pos - ($maxChar/2)) < 0) { $startPos = 0; } else { $startPos = ($pos - ($maxChar/2)); $chunk .= '...'; } $chunk .= substr($body, $startPos, $maxChar); if (($pos + ($maxChar/2)) < strlen($body)) { $chunk .= '...'; } break; } } if ($chunk == '') { $chunk = substr($body, 0, $maxChar) . '...'; }*/ $sentLength = new Zym_Filter_SentenceLength(250); $chunk = $sentLength->filter($body); $fullHightlightedText = $query->htmlFragmentHighlightMatches(htmlspecialchars($chunk), '', new FFR_Search_Highlighter()); return htmlspecialchars_decode($fullHightlightedText); }
/** * Defined by Zend_Filter_Interface * * Returns the filtered string of $value * * @param string $value * @return string */ public function filter($value) { $value = parent::filter($value); $value = str_replace(' ', $this->_wordSeparator, $value); $value = urlencode($value); return $this->_encodeSlashes ? $value : str_replace('%2F', '/', $value); }
/** * Tests using an object as input * */ public function testObject() { $obj = new Zym_Filter_SentenceLength(); try { $this->_filter1->filter($obj); } catch (Exception $e) { return; } $this->fail('An exception has not been raised'); }