From c057dcf6fe84b88cdec274293d0671d338e3d3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Thu, 11 Jun 2020 12:11:25 -0500 Subject: [PATCH] buscar.php.md: improved search according to platform --- content/pages/buscar.php.md | 142 +++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 65 deletions(-) diff --git a/content/pages/buscar.php.md b/content/pages/buscar.php.md index b06a021..7605c9d 100644 --- a/content/pages/buscar.php.md +++ b/content/pages/buscar.php.md @@ -1,13 +1,18 @@ Author: Jorge Maldonado Ventura Date: 2017-04-22 20:38 -Modified: 2018-01-11 16:38 +Modified: 2020-06-11 11:38 Save_as: buscar.php Status: hidden Title: Resultados -
+ +
+
+
' . $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('

%s

', '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(' + ', + $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'); } ?> -
+
+
+