mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 16:33:00 +00:00
Display basic similar page suggestions.
They are w=even appearing in the right pace! Next up, we need to write the CSS to make it look pretty :D
This commit is contained in:
parent
5693c24358
commit
e55308f50a
1 changed files with 18 additions and 4 deletions
|
@ -68,6 +68,23 @@ register_module([
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
page_renderer::register_part_preprocessor(function(&$parts) {
|
||||||
|
global $env;
|
||||||
|
|
||||||
|
$html = "<h2>Other pages to explore</h2>\n\t\t<ul class='similar-page-suggestions'>\n";
|
||||||
|
$start_time = microtime(true);
|
||||||
|
$suggestions = similar_suggest(
|
||||||
|
$env->page,
|
||||||
|
file_get_contents($env->page_filename)
|
||||||
|
);
|
||||||
|
$env->perfdata->similar_suggest = round((microtime(true) - $start_time) * 1000, 2);
|
||||||
|
foreach($suggestions as $suggested_pagename => $rank)
|
||||||
|
$html .= "<li data-rank='$rank'><a href='?page=".rawurlencode($suggested_pagename)."'>".htmlentities($suggested_pagename)."</a></li>\n";
|
||||||
|
$html .= "</ul>\n\t\t<!-- Took {$env->perfdata->similar_suggest}ms to compute similar page suggestions -->\n";
|
||||||
|
|
||||||
|
$parts["{extra}"] = $html . $parts["{extra}"];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -95,7 +112,6 @@ function similar_suggest(string $pagename, string $content, bool $limit_output =
|
||||||
$max_count = -1;
|
$max_count = -1;
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach($index as $term => $data) {
|
foreach($index as $term => $data) {
|
||||||
error_log("[similar_suggest] checking $term | {$data["freq"]}");
|
|
||||||
// Only search the top 20% most common words
|
// Only search the top 20% most common words
|
||||||
// Stop words are skipped automagically
|
// Stop words are skipped automagically
|
||||||
// if($i > $max_count * 0.2) break;
|
// if($i > $max_count * 0.2) break;
|
||||||
|
@ -112,8 +128,6 @@ function similar_suggest(string $pagename, string $content, bool $limit_output =
|
||||||
// Check is it's present just in case (todo figure out if it's necessary)
|
// Check is it's present just in case (todo figure out if it's necessary)
|
||||||
if(!search::invindex_term_exists($term)) continue;
|
if(!search::invindex_term_exists($term)) continue;
|
||||||
|
|
||||||
error_log("ok");
|
|
||||||
|
|
||||||
$otherpages = search::invindex_term_getpageids($term);
|
$otherpages = search::invindex_term_getpageids($term);
|
||||||
foreach($otherpages as $pageid) {
|
foreach($otherpages as $pageid) {
|
||||||
if($pageid == $our_pageid) continue;
|
if($pageid == $our_pageid) continue;
|
||||||
|
@ -133,7 +147,7 @@ function similar_suggest(string $pagename, string $content, bool $limit_output =
|
||||||
|
|
||||||
$result = []; $i = 0;
|
$result = []; $i = 0;
|
||||||
foreach($pages as $pageid => $count) {
|
foreach($pages as $pageid => $count) {
|
||||||
if($limit_output && $i > $settings->similarpages_count) break;
|
if($limit_output && $i >= $settings->similarpages_count) break;
|
||||||
$result[ids::getpagename($pageid)] = $count;
|
$result[ids::getpagename($pageid)] = $count;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue