improve search results

This commit is contained in:
John Bintz 2009-09-23 21:50:42 -04:00
parent 0723e03ce9
commit 03e3d4694c
1 changed files with 6 additions and 5 deletions

View File

@ -188,7 +188,6 @@ class WhatDidTheySayAdmin {
} }
function the_matching_transcript_excerpts($transcripts, $search_string = '', $output = "") { function the_matching_transcript_excerpts($transcripts, $search_string = '', $output = "") {
var_dump($search_string);
ob_start(); ob_start();
if (!empty($search_string)) { if (!empty($search_string)) {
$language_options = new WDTSLanguageOptions(); $language_options = new WDTSLanguageOptions();
@ -198,7 +197,7 @@ class WhatDidTheySayAdmin {
if (($pos = strpos($transcript['transcript'], $search_string)) !== false) { if (($pos = strpos($transcript['transcript'], $search_string)) !== false) {
$l = strlen($transcript['transcript']) - 1; $l = strlen($transcript['transcript']) - 1;
echo '<div class="transcript-match">'; echo '<div class="transcript-match">';
echo '<h4>' . sprintf(__("%s transcript:", 'what-did-they-say'), $language_options->get_language_name($transcript['language'])) . '</h4>'; echo '<h4>' . sprintf(__("%s transcript excerpt:", 'what-did-they-say'), $language_options->get_language_name($transcript['language'])) . '</h4>';
echo '<p>'; echo '<p>';
$start_ellipsis = $end_ellipsis = true; $start_ellipsis = $end_ellipsis = true;
foreach (array( foreach (array(
@ -207,14 +206,16 @@ class WhatDidTheySayAdmin {
) as $variable => $direction) { ) as $variable => $direction) {
${$variable} = $pos + ($options['excerpt_distance'] * $direction); ${$variable} = $pos + ($options['excerpt_distance'] * $direction);
if ($variable == "end") { ${$variable} += strlen($search_string); }
if (${$variable} < 0) { ${$variable} = 0; $start_ellipsis = false; } if (${$variable} < 0) { ${$variable} = 0; $start_ellipsis = false; }
if (${$variable} > $l) { ${$variable} = $l; $end_ellipsis = false; } if (${$variable} > $l) { ${$variable} = $l; $end_ellipsis = false; }
} }
$output = ""; $output = "";
if ($start_ellipsis) { $output .= "... "; } if ($start_ellipsis) { $output .= "..."; }
$output .= str_replace($search_string, "<strong>" . $search_string . "</strong>", $transcript['transcript']); $output .= str_replace($search_string, "<strong>" . $search_string . "</strong>", trim(substr($transcript['transcript'], $start, $end - $start)));
if ($end_ellipsis) { $output .= " ..."; } if ($end_ellipsis) { $output .= "..."; }
echo $output; echo $output;
echo '</p>'; echo '</p>';