diff --git a/content/pages/buscar.php.md b/content/pages/buscar.php.md index 35bd263..accc6d8 100644 --- a/content/pages/buscar.php.md +++ b/content/pages/buscar.php.md @@ -32,7 +32,7 @@ $STOP_WORDS = ['a', 'un', 'una', 'unas', 'unos', 'uno', 'sobre', 'todo', 'trabajas', 'trabaja', 'trabajamos', 'trabajais', 'trabajan', 'podria', 'podrias', 'podriamos', 'podrian', 'podriais', 'yo', 'aquel']; -$DESCRIPTION_LENGTH = 25; +$DESCRIPTION_LENGTH = 20; $HALF_DESCRIPTION_LENGTH = floor($DESCRIPTION_LENGTH / 2); $web_content = json_decode(file_get_contents('tipuesearch_content.json'), true); @@ -76,8 +76,12 @@ if (isset($_GET['q'])) { if (preg_match("/$word/i", $page['tags'])) { $score += 30; } - // It replaces upper case matches with lower case matches, but it's fine for now. - $page['text'] = preg_replace("/$word/i", '' . $word . '', $page['text'], -1, $match_count); + // It replaces uppercase matches with lowercase matches, but it's fine for now. + if ($stop_words_ignored == 1) { + $page['text'] = preg_replace("/$word/i", $word, $page['text'], -1, $match_count); + } else { + $page['text'] = preg_replace("/$word/i", '' . $word . '', $page['text'], -1, $match_count); + } if ($match_count > 0) { $score += 10 * $match_count; } @@ -96,7 +100,6 @@ if (isset($_GET['q'])) { } return ($a['score'] > $b['score']) ? -1 : 1; } - if ($stop_words_ignored) { printf('
%s
', 'Las palabras comunes se ignoran en gran parte'); } @@ -110,9 +113,8 @@ if (isset($_GET['q'])) { $found_results_count_str = $found_results_count . ' resultados'; } } else if ($found_results_count == 0) { - // die('
No se ha encontrado nada
'); $found_results_count_str = ''; - printf('
No se ha encontrado nada
'); + printf('
%s
', 'No se ha encontrado nada'); } printf('
%s
', $found_results_count_str); @@ -151,9 +153,12 @@ if (isset($_GET['q'])) { echo '...'; } echo ''; + } elseif ( $description_words_count === 1 ) { + printf('

%s

', 'No hay palabras en el artículo'); + break; } else { echo '
'; - for ($i = 0; $i < $DESCRIPTION_LENGTH; $i++) { + for ($i = 0; $i < $description_words_count - floor($description_words_count/2); $i++) { echo $description_words[$i] . ' '; } if ($description_words_count > $DESCRIPTION_LENGTH) { @@ -164,8 +169,7 @@ if (isset($_GET['q'])) { } } else { - printf('
Aún no has buscado
'); + printf('
%s
', 'Aún no has buscado'); } - ?>