Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
One of many iterations on a helper for the Searchable plugin
<?php
class SearchableHelper extends AppHelper {
var $helpers = array('Html', 'Text');
function snippets($data) {
$data = json_decode($data, true);
$term = (isset($this->data['SearchIndex']['term'])) ? trim($this->data['SearchIndex']['term']) : '';
$snippets = '';
while (strlen($snippets) < 255 && $value = next($data)) {
$snippets .= $this->Text->highlight($this->Text->excerpt($value, $term, 20), $term);
$snippets .= "<br />";
}
return $snippets;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment