1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 04:23:01 +00:00

Add progress to invindex-rebuild - ready for addition to the master control panel

This commit is contained in:
Starbeamrainbowlabs 2017-07-10 21:53:52 +01:00
parent f9a56272b7
commit c2dcf43bc2
3 changed files with 31 additions and 15 deletions

View file

@ -3178,7 +3178,7 @@ register_module([
// Create the inverted index if it doesn't exist.
// todo In the future perhaps a CLI for this would be good?
if(!file_exists($paths->searchindex))
search::rebuild_invindex();
search::rebuild_invindex(false);
if(!isset($_GET["query"]))
exit(page_renderer::render("No Search Terms - Error - $settings->sitename", "<p>You didn't specify any search terms. Try typing some into the box above.</p>"));
@ -3558,10 +3558,11 @@ class search
return str_replace([ "[", "]", "\"", "*", "_", " - ", "`" ], "", $source);
}
public static function rebuild_invindex()
public static function rebuild_invindex($output = true)
{
global $pageindex, $env, $paths;
if($output)
header("content-type: text/event-stream");
// Clear the id index out
@ -3569,6 +3570,7 @@ class search
// Reindex each page in turn
$invindex = [];
$i = 0; $max = count(get_object_vars($pageindex));
foreach($pageindex as $pagename => $pagedetails)
{
$pagesource = utf8_encode(file_get_contents("$env->storage_prefix$pagename.md"));
@ -3577,12 +3579,18 @@ class search
$pageid = ids::getid($pagename);
self::merge_into_invindex($invindex, $pageid, $index);
echo("Added $pagename (id #$pageid) to the new search index.\n\n");
if($output) {
echo("[" . ($i + 1) . " / $max] Added $pagename (id #$pageid) to the new search index.\n\n");
flush();
}
$i++;
}
if($output) {
echo("Search index rebuilding complete.\n\n");
echo("Saving new search index to '$paths->searchindex'.\n\n");
}
self::save_invindex($paths->searchindex, $invindex);
}

View file

@ -104,7 +104,7 @@
"author": "Starbeamrainbowlabs",
"description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
"id": "feature-search",
"lastupdate": 1499102118,
"lastupdate": 1499719908,
"optional": false
},
{

View file

@ -102,7 +102,7 @@ register_module([
// Create the inverted index if it doesn't exist.
// todo In the future perhaps a CLI for this would be good?
if(!file_exists($paths->searchindex))
search::rebuild_invindex();
search::rebuild_invindex(false);
if(!isset($_GET["query"]))
exit(page_renderer::render("No Search Terms - Error - $settings->sitename", "<p>You didn't specify any search terms. Try typing some into the box above.</p>"));
@ -482,10 +482,11 @@ class search
return str_replace([ "[", "]", "\"", "*", "_", " - ", "`" ], "", $source);
}
public static function rebuild_invindex()
public static function rebuild_invindex($output = true)
{
global $pageindex, $env, $paths;
if($output)
header("content-type: text/event-stream");
// Clear the id index out
@ -493,6 +494,7 @@ class search
// Reindex each page in turn
$invindex = [];
$i = 0; $max = count(get_object_vars($pageindex));
foreach($pageindex as $pagename => $pagedetails)
{
$pagesource = utf8_encode(file_get_contents("$env->storage_prefix$pagename.md"));
@ -501,12 +503,18 @@ class search
$pageid = ids::getid($pagename);
self::merge_into_invindex($invindex, $pageid, $index);
echo("Added $pagename (id #$pageid) to the new search index.\n\n");
if($output) {
echo("[" . ($i + 1) . " / $max] Added $pagename (id #$pageid) to the new search index.\n\n");
flush();
}
$i++;
}
if($output) {
echo("Search index rebuilding complete.\n\n");
echo("Saving new search index to '$paths->searchindex'.\n\n");
}
self::save_invindex($paths->searchindex, $invindex);
}