fix search

This commit is contained in:
Jesús 2019-04-27 14:27:54 -05:00
parent 794ba7b6a7
commit e4b891bed6
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766

View File

@ -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", '<span class="tipue_search_content_bold">' . $word . '</span>', $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", '<span class="tipue_search_content_bold highlighted">' . $word . '</span>', $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('<div id="tipue_search_warning">%s</div>', '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('<div id="tipue_search_warning">No se ha encontrado nada</div>');
$found_results_count_str = '';
printf('<div id="tipue_search_warning">No se ha encontrado nada</div>');
printf('<div id="tipue_search_warning">%s</div>', 'No se ha encontrado nada');
}
printf('<div id="tipue_search_results_count">%s</div>', $found_results_count_str);
@ -151,9 +153,12 @@ if (isset($_GET['q'])) {
echo '...';
}
echo '</div>';
} elseif ( $description_words_count === 1 ) {
printf('<div class="tipue_search_content_text"><p>%s</p></div>', 'No hay palabras en el artículo');
break;
} else {
echo '<div class="tipue_search_content_text">';
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('<div id="tipue_search_warning">Aún no has buscado</div>');
printf('<div id="tipue_search_warning">%s</div>', 'Aún no has buscado');
}
?>
</div>