Created
March 22, 2010 03:59
-
-
Save josegonzalez/339788 to your computer and use it in GitHub Desktop.
One of many iterations on a helper for the Searchable plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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