Skip to content

Instantly share code, notes, and snippets.

@josegonzalez
Created March 22, 2010 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josegonzalez/339788 to your computer and use it in GitHub Desktop.
Save josegonzalez/339788 to your computer and use it in GitHub Desktop.
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