' . $word . '', $page['description'], -1, $match_count);
+ $page['description'] = preg_replace("/$word/i", $word, $page['description'], -1, $match_count);
}
if ($match_count > 0) {
$score += 10 * $match_count;
}
+
}
if ($score != 0) {
- $found_results[] = ['score' => $score, 'title' => $page['title'], 'url' => $page['url'], 'description' => $page['description']];
+ $found_results[] = [
+ 'score' => $score,
+ 'title' => $page['title'],
+ 'time' => $page['time'],
+ 'videoThumbnail' => $page['videoThumbnail'],
+ 'url' => $page['url'],
+ 'published' => $page['published'],
+ 'publishedText' => $page['publishedText'],
+ 'author' => $page['author'],
+ 'authorUrl' => $page['authorUrl'],
+ ];
}
}
@@ -99,72 +112,69 @@ if (isset($_GET['q'])) {
return 0;
}
return ($a['score'] > $b['score']) ? -1 : 1;
+ };
+
+ $stop_results = $found_results;
+ if ($stop_words_ignored) {
+ printf('
%s
', 'Las palabras comunes se ignoran en gran parte');
+ $stop_results = NULL;
}
- if ($stop_words_ignored) {
- printf('
%s
', 'Las palabras comunes se ignoran en gran parte');
- }
$found_results_count = count($found_results);
+
if ($found_results_count > 0) {
usort($found_results, 'comp_result_score');
if ($found_results_count == 1) {
- $found_results_count_str = '1 resultado';
- } else {
- $found_results_count_str = $found_results_count . ' resultados';
+ $found_results_count_str = NULL;
}
} else if ($found_results_count == 0) {
- $found_results_count_str = '';
+ $found_results_count_str = NULL;
printf('
%s
', 'No se ha encontrado nada');
}
- printf('
%s
', $found_results_count_str);
-
- foreach ($found_results as $found_result) {
- printf('
', $found_result['url'], $found_result['title']);
- printf('
', $found_result['url'], $found_result['url']);
-
- $description_words = explode(' ', $found_result['description']);
- $description_words_count = count($description_words);
- $first_match = false;
- for ($i = 0; $i < $description_words_count; $i++) {
- if ($description_words[$i] == '
') {
- $first_match = $i;
- break;
- }
- }
- if ($first_match !== false) {
- echo '';
- if ($first_match - 12 <= 0) {
- for ($i = 0; $i < $DESCRIPTION_LENGTH; $i++) {
- echo $description_words[$i] . ' ';
- }
- echo '...';
- } else if($first_match + 12 >= $description_words_count) {
- echo '...';
- for ($i = $first_match - 12; $i < $description_words_count; $i++) {
- echo ' ' . $description_words[$i];
- }
- }
- else {
- echo '...';
- for ($i = $first_match - 12; $i <= $first_match + 12; $i++) {
- echo $description_words[$i] . ' ';
- }
- echo '...';
- }
- echo '
';
- } elseif ( $description_words_count === 1 ) {
- printf('', 'No hay palabras en el artículo');
- break;
- } else {
- echo '';
- for ($i = 0; $i < $description_words_count - floor($description_words_count/2); $i++) {
- echo $description_words[$i] . ' ';
- }
- if ($description_words_count > $DESCRIPTION_LENGTH) {
- echo '...';
- }
- echo '
';
+ if (!empty($stop_results)) {
+ foreach ($found_results as $found_result) {
+ printf('
+
+
+
+
+

+
%s
+
+
+
+
+
+
+ ',
+ $found_result['url'], $found_result['videoThumbnail'], $found_result['title'],
+ $found_result['time'], $found_result['url'], $found_result['title'],
+ $found_result['title'], $found_result['published'], $found_result['publishedText'],
+ $found_result['authorUrl'], $found_result['author']);
}
}
@@ -172,4 +182,6 @@ if (isset($_GET['q'])) {
printf('%s
', 'Aún no has buscado');
}
?>
-