From 9d7a21e99333197b0510e2d6113646dc04f6dc0b Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Fri, 29 Jun 2018 12:08:38 +0100 Subject: [PATCH] Format the index action nicely --- build/index.php | 18 ++++++++++++------ module_index.json | 2 +- modules/feature-search.php | 15 ++++++++++----- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/build/index.php b/build/index.php index c6fe8eb..319bb53 100644 --- a/build/index.php +++ b/build/index.php @@ -397,7 +397,7 @@ if($settings->sessionprefix == "auto") ///////////////////////////////////////////////////////////////////////////// /** The version of Pepperminty Wiki currently running. */ $version = "v0.17-dev"; -$commit = "3d3b6c491a0848922e0dc3d8c1c89a5f87673c0e"; +$commit = "80f2cc77a8fa474394492f08ea7f4c998d076acc"; /// Environment /// /** Holds information about the current request environment. */ $env = new stdClass(); @@ -3682,10 +3682,15 @@ register_module([ $index = search::index($source); - var_dump($env->page); - var_dump($source); - - var_dump($index); + echo("Page name: $env->page\n"); + echo("--------------- Source ---------------\n"); + echo($source); echo("\n"); + echo("--------------------------------------\n\n"); + echo("---------------- Index ---------------\n"); + foreach($index as $term => $entry) { + echo("$term: {$entry["freq"]} matches | " . implode(", ", $entry["offsets"]) . "\n"); + } + echo("--------------------------------------\n"); }); /** @@ -4454,9 +4459,10 @@ class search reset($pageindex); // Reset array/object pointer foreach ($pageindex as $pagename => $pagedata) { - // Seteup a variable to hold the current page's id + // Setup a variable to hold the current page's id $pageid = false; // Only fill this out if we find a match // Consider matches in the page title + // FUTURE: We may be able to optimise this further by using preg_match_all + preg_quote instead of mb_stripos_all. Experimentation / benchmarking is required to figure out which one is faster $title_matches = mb_stripos_all($literator->transliterate($pagename), $qterm); $title_matches_count = $title_matches !== false ? count($title_matches) : 0; if($title_matches_count > 0) diff --git a/module_index.json b/module_index.json index b8a6513..9a853b9 100755 --- a/module_index.json +++ b/module_index.json @@ -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": 1530019335, + "lastupdate": 1530270319, "optional": false }, { diff --git a/modules/feature-search.php b/modules/feature-search.php index bb0251f..5b6114c 100644 --- a/modules/feature-search.php +++ b/modules/feature-search.php @@ -36,10 +36,15 @@ register_module([ $index = search::index($source); - var_dump($env->page); - var_dump($source); - - var_dump($index); + echo("Page name: $env->page\n"); + echo("--------------- Source ---------------\n"); + echo($source); echo("\n"); + echo("--------------------------------------\n\n"); + echo("---------------- Index ---------------\n"); + foreach($index as $term => $entry) { + echo("$term: {$entry["freq"]} matches | " . implode(", ", $entry["offsets"]) . "\n"); + } + echo("--------------------------------------\n"); }); /** @@ -808,7 +813,7 @@ class search reset($pageindex); // Reset array/object pointer foreach ($pageindex as $pagename => $pagedata) { - // Seteup a variable to hold the current page's id + // Setup a variable to hold the current page's id $pageid = false; // Only fill this out if we find a match // Consider matches in the page title // FUTURE: We may be able to optimise this further by using preg_match_all + preg_quote instead of mb_stripos_all. Experimentation / benchmarking is required to figure out which one is faster