public function extractRelevant($words, $fulltext, $rellength = 300, $prevcount = 50, $indicator = '...')
{
$words = preg_split('/\\PL+/u', $words, -1, PREG_SPLIT_NO_EMPTY);
$textlength = strlen($fulltext);
if ($textlength <= $rellength) {
return $fulltext;
}
$locations = $this->_extractLocations($words, $fulltext);
$startpos = $this->_determineSnipLocation($locations, $prevcount);
// if we are going to snip too much...
if ($textlength - $startpos < $rellength) {
$startpos = $startpos - ($textlength - $startpos) / 2;
}
$reltext = substr($fulltext, $startpos, $rellength);
// check to ensure we dont snip the last word if thats the match
if ($startpos + $rellength < $textlength) {
$reltext = substr($reltext, 0, strrpos($reltext, " ")) . $indicator;
// remove last word
}
// If we trimmed from the front add ...
if ($startpos != 0) {
$reltext = $indicator . substr($reltext, strpos($reltext, " ") + 1);
// remove first word
}
return $reltext;
}