mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-25 17:23:00 +00:00
Fix some mroe odd bugs in the new search system
This commit is contained in:
parent
edf1be5801
commit
9505e0653e
2 changed files with 8 additions and 13 deletions
|
@ -135,7 +135,7 @@
|
||||||
"version": "0.10",
|
"version": "0.10",
|
||||||
"author": "Starbeamrainbowlabs",
|
"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.",
|
"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.",
|
||||||
"lastupdate": 1566506237,
|
"lastupdate": 1566508042,
|
||||||
"optional": false,
|
"optional": false,
|
||||||
"extra_data": []
|
"extra_data": []
|
||||||
},
|
},
|
||||||
|
|
|
@ -366,8 +366,7 @@ register_module([
|
||||||
add_action("suggest-pages", function() {
|
add_action("suggest-pages", function() {
|
||||||
global $settings, $pageindex;
|
global $settings, $pageindex;
|
||||||
|
|
||||||
if($settings->dynamic_page_suggestion_count === 0)
|
if($settings->dynamic_page_suggestion_count === 0) {
|
||||||
{
|
|
||||||
header("content-type: application/json");
|
header("content-type: application/json");
|
||||||
header("content-length: 3");
|
header("content-length: 3");
|
||||||
exit("[]\n");
|
exit("[]\n");
|
||||||
|
@ -386,10 +385,8 @@ register_module([
|
||||||
exit("Error: The type '$type' is not one of the supported output types. Available values: json, opensearch. Default: json");
|
exit("Error: The type '$type' is not one of the supported output types. Available values: json, opensearch. Default: json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$query = search::transliterate($_GET["query"]);
|
$query = search::transliterate($_GET["query"]);
|
||||||
|
|
||||||
|
|
||||||
// Rank each page name
|
// Rank each page name
|
||||||
$results = [];
|
$results = [];
|
||||||
foreach($pageindex as $pageName => $entry) {
|
foreach($pageindex as $pageName => $entry) {
|
||||||
|
@ -699,7 +696,7 @@ class search
|
||||||
if(self::$literator == null)
|
if(self::$literator == null)
|
||||||
self::$literator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Lower(); :: NFC;', Transliterator::FORWARD);
|
self::$literator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Lower(); :: NFC;', Transliterator::FORWARD);
|
||||||
|
|
||||||
return self::$literator->transliterate($_GET["query"]);
|
return self::$literator->transliterate($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1095,7 +1092,7 @@ class search
|
||||||
// Set the weight to -1 if it's a stop word
|
// Set the weight to -1 if it's a stop word
|
||||||
$result["terms"][] = [
|
$result["terms"][] = [
|
||||||
"term" => $tokens[$i],
|
"term" => $tokens[$i],
|
||||||
"weight" => in_array($tokens[$i], self::$stop_words) ? 0 : -1,
|
"weight" => in_array($tokens[$i], self::$stop_words) ? -1 : 1,
|
||||||
"location" => "all"
|
"location" => "all"
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -1148,7 +1145,7 @@ class search
|
||||||
foreach($term_pageids as $pageid) {
|
foreach($term_pageids as $pageid) {
|
||||||
// Check to see if it contains any words we should exclude
|
// Check to see if it contains any words we should exclude
|
||||||
$skip = false;
|
$skip = false;
|
||||||
foreach($query_stas["exclude"] as $exlc_term) {
|
foreach($query_stas["exclude"] as $excl_term) {
|
||||||
if(self::$invindex->has("$excl_term|$pageid")) {
|
if(self::$invindex->has("$excl_term|$pageid")) {
|
||||||
$skip = true;
|
$skip = true;
|
||||||
break;
|
break;
|
||||||
|
@ -1165,9 +1162,9 @@ class search
|
||||||
// Add it to the appropriate $matching_pages entry, not forgetting to apply the weighting
|
// Add it to the appropriate $matching_pages entry, not forgetting to apply the weighting
|
||||||
$matching_pages[$pageid]["offsets_body"] = array_merge(
|
$matching_pages[$pageid]["offsets_body"] = array_merge(
|
||||||
$matching_pages[$pageid]["offsets_body"],
|
$matching_pages[$pageid]["offsets_body"],
|
||||||
$page_offsets
|
$page_offsets->offsets
|
||||||
);
|
);
|
||||||
$matching_pages[$pageid]["nterms"][$term_def["term"]] = count($page_offsets) * $term_def["weight"];
|
$matching_pages[$pageid]["nterms"][$term_def["term"]] = $page_offsets->freq * $term_def["weight"];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1241,8 +1238,6 @@ class search
|
||||||
|
|
||||||
// TODO: Implement the rest of STAS here
|
// TODO: Implement the rest of STAS here
|
||||||
|
|
||||||
// TODO: We got up to here; finish refactoring invindex_query
|
|
||||||
|
|
||||||
reset($matching_pages);
|
reset($matching_pages);
|
||||||
foreach($matching_pages as $pageid => &$pagedata) {
|
foreach($matching_pages as $pageid => &$pagedata) {
|
||||||
$pagedata["pagename"] = ids::getpagename($pageid);
|
$pagedata["pagename"] = ids::getpagename($pageid);
|
||||||
|
@ -1376,7 +1371,7 @@ class search
|
||||||
|
|
||||||
foreach($qterms as $qterm) {
|
foreach($qterms as $qterm) {
|
||||||
// Stop words are marked by STAS
|
// Stop words are marked by STAS
|
||||||
if($qterm["weight"] <= 0)
|
if($qterm["weight"] == -1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// From http://stackoverflow.com/a/2483859/1460422
|
// From http://stackoverflow.com/a/2483859/1460422
|
||||||
|
|
Loading…
Reference in a new issue