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

Finish up enhancements to search system.

I _think_ it works with utf-8 everywhere in the search system? I'm not
sure - lots of testing is needed. Fortunately, I know just where to do
such testing.....
This commit is contained in:
Starbeamrainbowlabs 2018-03-18 16:52:55 +00:00
parent 3dc505992d
commit 893492c5a6
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 19 additions and 11 deletions

View file

@ -3810,10 +3810,13 @@ register_module([
//echo("Extracting context for result " . $result["pagename"] . ".\n");
$context = $result["context"];
if(strlen($context) === 0)
$context = substr($pagesource, 0, $settings->search_characters_context * 2);
if(mb_strlen($context) === 0)
$context = mb_substr($pagesource, 0, $settings->search_characters_context * 2);
//echo("'Generated search context for " . $result["pagename"] . ": $context'\n");
$context = search::highlight_context($_GET["query"], htmlentities($context));
$context = search::highlight_context(
$_GET["query"],
preg_replace('/</u', '&lt;', $context)
);
/*if(strlen($context) == 0)
{
$context = search::strip_markup(file_get_contents("$env->page.md", null, null, null, $settings->search_characters_context * 2));
@ -4143,7 +4146,7 @@ class search
*/
public static function tokenize($source)
{
$source = strtolower($source);
$source = Normalizer::normalize(strtolower($source), Normalizer::FORM_C);
$source = preg_replace('/[\[\]\|\{\}\/]/u', " ", $source);
return preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))|\|/u", $source, -1, PREG_SPLIT_NO_EMPTY);
}
@ -4571,7 +4574,8 @@ class search
if(in_array($qterm, static::$stop_words))
continue;
// From http://stackoverflow.com/a/2483859/1460422
$context = preg_replace("/" . str_replace("/", "\/", preg_quote($qterm)) . "/iu", "<strong class='search-term-highlight'>$0</strong>", $context);
$context = preg_replace("/" . preg_replace('/\\//u', "\/", preg_quote($qterm)) . "/iu", "<strong class='search-term-highlight'>$0</strong>", $context);
}
return $context;

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": 1521390977,
"lastupdate": 1521391886,
"optional": false
},
{

View file

@ -210,10 +210,13 @@ register_module([
//echo("Extracting context for result " . $result["pagename"] . ".\n");
$context = $result["context"];
if(strlen($context) === 0)
$context = substr($pagesource, 0, $settings->search_characters_context * 2);
if(mb_strlen($context) === 0)
$context = mb_substr($pagesource, 0, $settings->search_characters_context * 2);
//echo("'Generated search context for " . $result["pagename"] . ": $context'\n");
$context = search::highlight_context($_GET["query"], htmlentities($context));
$context = search::highlight_context(
$_GET["query"],
preg_replace('/</u', '&lt;', $context)
);
/*if(strlen($context) == 0)
{
$context = search::strip_markup(file_get_contents("$env->page.md", null, null, null, $settings->search_characters_context * 2));
@ -543,7 +546,7 @@ class search
*/
public static function tokenize($source)
{
$source = strtolower($source);
$source = Normalizer::normalize(strtolower($source), Normalizer::FORM_C);
$source = preg_replace('/[\[\]\|\{\}\/]/u', " ", $source);
return preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))|\|/u", $source, -1, PREG_SPLIT_NO_EMPTY);
}
@ -971,7 +974,8 @@ class search
if(in_array($qterm, static::$stop_words))
continue;
// From http://stackoverflow.com/a/2483859/1460422
$context = preg_replace("/" . str_replace("/", "\/", preg_quote($qterm)) . "/iu", "<strong class='search-term-highlight'>$0</strong>", $context);
$context = preg_replace("/" . preg_replace('/\\//u', "\/", preg_quote($qterm)) . "/iu", "<strong class='search-term-highlight'>$0</strong>", $context);
}
return $context;