mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-12-22 13:45:02 +00:00
Half fixed search context generation for #30.
The problem: The matches were being sorted in the wrong direction. Next up we need to improve the context generation, as there are several contexts that are being generated without the keywork in question in them.
This commit is contained in:
parent
70f9c398cc
commit
c5017919a1
5 changed files with 23 additions and 15 deletions
|
@ -3,7 +3,7 @@ A Wiki in a box
|
|||
|
||||
Pepperminty Wiki is a complete wiki contained in a single file, inspired by @am2064's [Minty Wiki](https://github.com/am2064/Minty-Wiki). It's open source too (under MPL-2.0), so contributions are welcome!
|
||||
|
||||
**Latest Version:** v0.12 (stable) v0.13-dev (development)
|
||||
**Latest Version:** v0.12 (stable) v0.12.1-dev (development)
|
||||
|
||||
## Screenshots
|
||||
![Main Page Example](https://i.imgur.com/8TokPXw.png)
|
|
@ -305,7 +305,7 @@ Actions:
|
|||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////// Do not edit below this line unless you know what you are doing! ///////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
$version = "v0.12";
|
||||
$version = "v0.12.1-dev";
|
||||
/// Environment ///
|
||||
$env = new stdClass();
|
||||
$env->action = $settings->defaultaction;
|
||||
|
@ -1025,7 +1025,7 @@ class page_renderer
|
|||
|
||||
<footer>
|
||||
<p>{footer-message}</p>
|
||||
<p>Powered by Pepperminty Wiki v0.12, which was built by <a href='//starbeamrainbowlabs.com/'>Starbeamrainbowlabs</a>. Send bugs to 'bugs at starbeamrainbowlabs dot com' or <a href='//github.com/sbrl/Pepperminty-Wiki' title='Github Issue Tracker'>open an issue</a>.</p>
|
||||
<p>Powered by Pepperminty Wiki v0.12.1-dev, which was built by <a href='//starbeamrainbowlabs.com/'>Starbeamrainbowlabs</a>. Send bugs to 'bugs at starbeamrainbowlabs dot com' or <a href='//github.com/sbrl/Pepperminty-Wiki' title='Github Issue Tracker'>open an issue</a>.</p>
|
||||
<p>Your local friendly administrators are {admins-name-list}.</p>
|
||||
<p>This wiki is managed by <a href='mailto:{admin-details-email}'>{admin-details-name}</a>.</p>
|
||||
</footer>
|
||||
|
@ -1037,7 +1037,7 @@ class page_renderer
|
|||
<p><em>From {sitename}, which is managed by {admin-details-name}.</em></p>
|
||||
<p>{footer-message}</p>
|
||||
<p><em>Timed at {generation-date}</em></p>
|
||||
<p><em>Powered by Pepperminty Wiki v0.12.</em></p>
|
||||
<p><em>Powered by Pepperminty Wiki v0.12.1-dev.</em></p>
|
||||
</footer>";
|
||||
|
||||
// An array of functions that have been registered to process the
|
||||
|
@ -1092,7 +1092,7 @@ class page_renderer
|
|||
"{body}" => $body_template,
|
||||
|
||||
"{sitename}" => $logo_html,
|
||||
"v0.12" => $version,
|
||||
"v0.12.1-dev" => $version,
|
||||
"{favicon-url}" => $settings->favicon,
|
||||
"{header-html}" => self::get_header_html(),
|
||||
|
||||
|
@ -2210,6 +2210,7 @@ register_module([
|
|||
$link = "?page=" . rawurlencode($result["pagename"]);
|
||||
$pagesource = file_get_contents($env->storage_prefix . $result["pagename"] . ".md");
|
||||
$context = search::extract_context($_GET["query"], $pagesource);
|
||||
//echo("Generated search context for " . $result["pagename"] . ": $context\n");
|
||||
$context = search::highlight_context($_GET["query"], $context);
|
||||
/*if(strlen($context) == 0)
|
||||
{
|
||||
|
@ -2340,7 +2341,7 @@ class search
|
|||
|
||||
self::merge_into_invindex($invindex, ids::getid($pagename), $index);
|
||||
}
|
||||
error_log("Saving inverted index to $paths->searchindex");
|
||||
|
||||
self::save_invindex($paths->searchindex, $invindex);
|
||||
}
|
||||
|
||||
|
@ -2557,9 +2558,10 @@ class search
|
|||
}
|
||||
}
|
||||
|
||||
// Sort the matches by offset
|
||||
usort($matches, function($a, $b) {
|
||||
if($a[1] == $b[1]) return 0;
|
||||
return ($a[1] < $b[1]) ? +1 : -1;
|
||||
return ($a[1] > $b[1]) ? +1 : -1;
|
||||
});
|
||||
|
||||
$contexts = [];
|
||||
|
@ -2567,8 +2569,7 @@ class search
|
|||
$matches_count = count($matches);
|
||||
while($basepos < $matches_count)
|
||||
{
|
||||
// Store the next match along - all others will be relative to that
|
||||
// one
|
||||
// Store the next match along - all others will be relative to that one
|
||||
$group = [$matches[$basepos]];
|
||||
|
||||
// Start scanning at the next one along - we always store the first match
|
||||
|
@ -2595,6 +2596,9 @@ class search
|
|||
$context_start = $group[0][1] - $settings->search_characters_context;
|
||||
$context_end = $group[count($group) - 1][1] + $settings->search_characters_context;
|
||||
|
||||
//echo("Got context. Start: $context_start, End: $context_end\n");
|
||||
//echo("Group:"); var_dump($group);
|
||||
|
||||
$context = substr($source, $context_start, $context_end - $context_start);
|
||||
|
||||
// Strip the markdown from the context - it's most likely going to
|
|
@ -68,7 +68,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": 1471597850,
|
||||
"lastupdate": 1471604218,
|
||||
"optional": false
|
||||
},
|
||||
{
|
|
@ -137,6 +137,7 @@ register_module([
|
|||
$link = "?page=" . rawurlencode($result["pagename"]);
|
||||
$pagesource = file_get_contents($env->storage_prefix . $result["pagename"] . ".md");
|
||||
$context = search::extract_context($_GET["query"], $pagesource);
|
||||
//echo("Generated search context for " . $result["pagename"] . ": $context\n");
|
||||
$context = search::highlight_context($_GET["query"], $context);
|
||||
/*if(strlen($context) == 0)
|
||||
{
|
||||
|
@ -267,7 +268,7 @@ class search
|
|||
|
||||
self::merge_into_invindex($invindex, ids::getid($pagename), $index);
|
||||
}
|
||||
error_log("Saving inverted index to $paths->searchindex");
|
||||
|
||||
self::save_invindex($paths->searchindex, $invindex);
|
||||
}
|
||||
|
||||
|
@ -484,9 +485,10 @@ class search
|
|||
}
|
||||
}
|
||||
|
||||
// Sort the matches by offset
|
||||
usort($matches, function($a, $b) {
|
||||
if($a[1] == $b[1]) return 0;
|
||||
return ($a[1] < $b[1]) ? +1 : -1;
|
||||
return ($a[1] > $b[1]) ? +1 : -1;
|
||||
});
|
||||
|
||||
$contexts = [];
|
||||
|
@ -494,8 +496,7 @@ class search
|
|||
$matches_count = count($matches);
|
||||
while($basepos < $matches_count)
|
||||
{
|
||||
// Store the next match along - all others will be relative to that
|
||||
// one
|
||||
// Store the next match along - all others will be relative to that one
|
||||
$group = [$matches[$basepos]];
|
||||
|
||||
// Start scanning at the next one along - we always store the first match
|
||||
|
@ -522,6 +523,9 @@ class search
|
|||
$context_start = $group[0][1] - $settings->search_characters_context;
|
||||
$context_end = $group[count($group) - 1][1] + $settings->search_characters_context;
|
||||
|
||||
//echo("Got context. Start: $context_start, End: $context_end\n");
|
||||
//echo("Group:"); var_dump($group);
|
||||
|
||||
$context = substr($source, $context_start, $context_end - $context_start);
|
||||
|
||||
// Strip the markdown from the context - it's most likely going to
|
2
version
2
version
|
@ -1 +1 @@
|
|||
v0.12
|
||||
v0.12.1-dev
|
Loading…
Reference in a new issue