buscar.php.md: improved search according to platform
This commit is contained in:
parent
4e47debdec
commit
c057dcf6fe
@ -1,13 +1,18 @@
|
|||||||
Author: Jorge Maldonado Ventura
|
Author: Jorge Maldonado Ventura
|
||||||
Date: 2017-04-22 20:38
|
Date: 2017-04-22 20:38
|
||||||
Modified: 2018-01-11 16:38
|
Modified: 2020-06-11 11:38
|
||||||
Save_as: buscar.php
|
Save_as: buscar.php
|
||||||
Status: hidden
|
Status: hidden
|
||||||
Title: Resultados
|
Title: Resultados
|
||||||
|
|
||||||
<div id="tipue_search_content">
|
|
||||||
|
<main class="row main-videos">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="row">
|
||||||
<?php
|
<?php
|
||||||
$STOP_WORDS = ['a', 'un', 'una', 'unas', 'unos', 'uno', 'sobre', 'todo',
|
$STOP_WORDS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||||
|
'ñ', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||||
|
'un', 'una', 'unas', 'unos', 'uno', 'sobre', 'todo',
|
||||||
'también', 'tras', 'otro', 'algun', 'alguno', 'alguna', 'algunos',
|
'también', 'tras', 'otro', 'algun', 'alguno', 'alguna', 'algunos',
|
||||||
'algunas', 'ser', 'es', 'soy', 'eres', 'somos', 'sois', 'estoy', 'esta',
|
'algunas', 'ser', 'es', 'soy', 'eres', 'somos', 'sois', 'estoy', 'esta',
|
||||||
'estamos', 'estais', 'estan', 'como', 'en', 'para', 'atras', 'porque',
|
'estamos', 'estais', 'estan', 'como', 'en', 'para', 'atras', 'porque',
|
||||||
@ -32,9 +37,6 @@ $STOP_WORDS = ['a', 'un', 'una', 'unas', 'unos', 'uno', 'sobre', 'todo',
|
|||||||
'trabajas', 'trabaja', 'trabajamos', 'trabajais', 'trabajan', 'podria',
|
'trabajas', 'trabaja', 'trabajamos', 'trabajais', 'trabajan', 'podria',
|
||||||
'podrias', 'podriamos', 'podrian', 'podriais', 'yo', 'aquel'];
|
'podrias', 'podriamos', 'podrian', 'podriais', 'yo', 'aquel'];
|
||||||
|
|
||||||
$DESCRIPTION_LENGTH = 20;
|
|
||||||
$HALF_DESCRIPTION_LENGTH = floor($DESCRIPTION_LENGTH / 2);
|
|
||||||
|
|
||||||
$web_content = json_decode(file_get_contents('tipuesearch_content.json'), true);
|
$web_content = json_decode(file_get_contents('tipuesearch_content.json'), true);
|
||||||
$stop_words_ignored = false;
|
$stop_words_ignored = false;
|
||||||
|
|
||||||
@ -43,7 +45,7 @@ if (isset($_GET['q'])) {
|
|||||||
$search_str = trim($_REQUEST['q']);
|
$search_str = trim($_REQUEST['q']);
|
||||||
|
|
||||||
$keywords = explode(' ', $search_str);
|
$keywords = explode(' ', $search_str);
|
||||||
$keywords_temp = '';
|
$keywords_temp = NULL;
|
||||||
foreach ($keywords as $keyword) {
|
foreach ($keywords as $keyword) {
|
||||||
$is_stop_word = false;
|
$is_stop_word = false;
|
||||||
foreach ($STOP_WORDS as $stop_word) {
|
foreach ($STOP_WORDS as $stop_word) {
|
||||||
@ -80,14 +82,25 @@ if (isset($_GET['q'])) {
|
|||||||
if ($stop_words_ignored == 1) {
|
if ($stop_words_ignored == 1) {
|
||||||
$page['description'] = preg_replace("/$word/i", $word, $page['description'], -1, $match_count);
|
$page['description'] = preg_replace("/$word/i", $word, $page['description'], -1, $match_count);
|
||||||
} else {
|
} else {
|
||||||
$page['description'] = preg_replace("/$word/i", '<span class="tipue_search_content_bold highlighted">' . $word . '</span>', $page['description'], -1, $match_count);
|
$page['description'] = preg_replace("/$word/i", $word, $page['description'], -1, $match_count);
|
||||||
}
|
}
|
||||||
if ($match_count > 0) {
|
if ($match_count > 0) {
|
||||||
$score += 10 * $match_count;
|
$score += 10 * $match_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if ($score != 0) {
|
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 0;
|
||||||
}
|
}
|
||||||
return ($a['score'] > $b['score']) ? -1 : 1;
|
return ($a['score'] > $b['score']) ? -1 : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
$stop_results = $found_results;
|
||||||
|
if ($stop_words_ignored) {
|
||||||
|
printf('<div id="tipue_search_warning">%s</div>', 'Las palabras comunes se ignoran en gran parte');
|
||||||
|
$stop_results = NULL;
|
||||||
}
|
}
|
||||||
if ($stop_words_ignored) {
|
|
||||||
printf('<div id="tipue_search_warning">%s</div>', 'Las palabras comunes se ignoran en gran parte');
|
|
||||||
}
|
|
||||||
|
|
||||||
$found_results_count = count($found_results);
|
$found_results_count = count($found_results);
|
||||||
|
|
||||||
if ($found_results_count > 0) {
|
if ($found_results_count > 0) {
|
||||||
usort($found_results, 'comp_result_score');
|
usort($found_results, 'comp_result_score');
|
||||||
if ($found_results_count == 1) {
|
if ($found_results_count == 1) {
|
||||||
$found_results_count_str = '1 resultado';
|
$found_results_count_str = NULL;
|
||||||
} else {
|
|
||||||
$found_results_count_str = $found_results_count . ' resultados';
|
|
||||||
}
|
}
|
||||||
} else if ($found_results_count == 0) {
|
} else if ($found_results_count == 0) {
|
||||||
$found_results_count_str = '';
|
$found_results_count_str = NULL;
|
||||||
printf('<div id="tipue_search_warning">%s</div>', 'No se ha encontrado nada');
|
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);
|
if (!empty($stop_results)) {
|
||||||
|
foreach ($found_results as $found_result) {
|
||||||
foreach ($found_results as $found_result) {
|
printf('
|
||||||
printf('<div class="tipue_search_content_title"><a class="is-cyan" href="%s">%s</a></div>', $found_result['url'], $found_result['title']);
|
<article class="col-md-3 video" itemscope itemtype="https://schema.org/Movie">
|
||||||
printf('<div class="tipue_search_content_url"><a href="%s">%s</a></div>', $found_result['url'], $found_result['url']);
|
<a href="%s">
|
||||||
|
<div class="area">
|
||||||
$description_words = explode(' ', $found_result['description']);
|
<div class="mask">
|
||||||
$description_words_count = count($description_words);
|
<div class="vertical-align">
|
||||||
$first_match = false;
|
<i class="soumaicon play"><svg><use href="/theme/images/svg/master.svg#play"></use></svg></i>
|
||||||
for ($i = 0; $i < $description_words_count; $i++) {
|
</div>
|
||||||
if ($description_words[$i] == '<span>') {
|
</div>
|
||||||
$first_match = $i;
|
<img itemprop="image" src="%s" alt="%s" class="img-fluid">
|
||||||
break;
|
<span class="duration">%s</span>
|
||||||
}
|
</div>
|
||||||
}
|
</a>
|
||||||
if ($first_match !== false) {
|
<h2 itemprop="name">
|
||||||
echo '<div class="tipue_search_content_text">';
|
<a href="%s" rel="bookmark" title="Ver %s">%s</a>
|
||||||
if ($first_match - 12 <= 0) {
|
</h2>
|
||||||
for ($i = 0; $i < $DESCRIPTION_LENGTH; $i++) {
|
<!-- post footer -->
|
||||||
echo $description_words[$i] . ' ';
|
<footer class="card-content-footer mb-4">
|
||||||
}
|
<span class="soumaicon text-info">
|
||||||
echo '...';
|
<svg>
|
||||||
} else if($first_match + 12 >= $description_words_count) {
|
<use href="/theme/images/svg/master.svg#calendar"></use>
|
||||||
echo '...';
|
</svg>
|
||||||
for ($i = $first_match - 12; $i < $description_words_count; $i++) {
|
</span>
|
||||||
echo ' ' . $description_words[$i];
|
<time class="entry-date published" datetime="%s" itemprop="datePublished">
|
||||||
}
|
<small>%s</small>
|
||||||
}
|
</time>
|
||||||
else {
|
<span class="soumaicon text-info">
|
||||||
echo '...';
|
<svg>
|
||||||
for ($i = $first_match - 12; $i <= $first_match + 12; $i++) {
|
<use href="/theme/images/svg/master.svg#user"></use>
|
||||||
echo $description_words[$i] . ' ';
|
</svg>
|
||||||
}
|
</span>
|
||||||
echo '...';
|
<small itemprop="director" itemscope itemtype="https://schema.org/Person">
|
||||||
}
|
<a href="%s" title="Autor del artículo" itemprop="name">%s</a>
|
||||||
echo '</div>';
|
</small>
|
||||||
} elseif ( $description_words_count === 1 ) {
|
</footer>
|
||||||
printf('<div class="tipue_search_content_text"><p>%s</p></div>', 'No hay palabras en el artículo');
|
<!-- end of post footer -->
|
||||||
break;
|
</article>',
|
||||||
} else {
|
$found_result['url'], $found_result['videoThumbnail'], $found_result['title'],
|
||||||
echo '<div class="tipue_search_content_text">';
|
$found_result['time'], $found_result['url'], $found_result['title'],
|
||||||
for ($i = 0; $i < $description_words_count - floor($description_words_count/2); $i++) {
|
$found_result['title'], $found_result['published'], $found_result['publishedText'],
|
||||||
echo $description_words[$i] . ' ';
|
$found_result['authorUrl'], $found_result['author']);
|
||||||
}
|
|
||||||
if ($description_words_count > $DESCRIPTION_LENGTH) {
|
|
||||||
echo '...';
|
|
||||||
}
|
|
||||||
echo '</div>';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,4 +182,6 @@ if (isset($_GET['q'])) {
|
|||||||
printf('<div id="tipue_search_warning">%s</div>', 'Aún no has buscado');
|
printf('<div id="tipue_search_warning">%s</div>', 'Aún no has buscado');
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user