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

48 lines
1.1 KiB
PHP
Raw Normal View History

2015-10-27 21:10:05 +00:00
<?php
register_module([
"name" => "Search",
"version" => "0.1",
"author" => "Starbeamrainbowlabs",
"description" => "Adds proper search functionality to Pepperminty Wiki. Note that this module, at the moment, just contains test code while I figure out how best to write a search engine.",
"id" => "feature-search",
"code" => function() {
add_action("index", function() {
global $settings, $env;
$breakable_chars = "\r\n\t .,\\/!\"£$%^&*[]()+`_~#";
header("content-type: text/plain");
$source = file_get_contents("$env->page.md");
$source_length = strlen($source);
$index = [];
// Regex from
$terms = preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/", $source, -1, PREG_SPLIT_NO_EMPTY);
$i = 0;
foreach($terms as $term)
2015-10-27 21:10:05 +00:00
{
$nterm = strtolower($term);
if(!isset($index[$nterm]))
2015-10-27 21:10:05 +00:00
{
$index[$nterm] = [ "freq" => 0, "offsets" => [] ];
2015-10-27 21:10:05 +00:00
}
$index[$nterm]["freq"]++;
$index[$nterm]["offsets"][] = $i;
$i++;
2015-10-27 21:10:05 +00:00
}
var_dump($env->page);
var_dump($source);
echo("source length: $source_length\n");
2015-10-27 21:10:05 +00:00
var_dump($index);
});
}
]);
?>