diff --git a/module_index.json b/module_index.json index 64122ca..ef6fbf7 100755 --- a/module_index.json +++ b/module_index.json @@ -135,7 +135,7 @@ "version": "0.10", "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.", - "lastupdate": 1566517659, + "lastupdate": 1566519828, "optional": false, "extra_data": [] }, diff --git a/modules/feature-search.php b/modules/feature-search.php index 59360d4..15f8bde 100644 --- a/modules/feature-search.php +++ b/modules/feature-search.php @@ -316,6 +316,53 @@ register_module([ $result->search_results = $searchResults; exit(json_encode($result, JSON_PRETTY_PRINT)); }); + + add_action("stas-parse", function() { + global $settings; + + $tokens = search::stas_split($_GET["query"]); + $stas_query = search::stas_parse($tokens); + + $result = ""; + foreach($tokens as $token) { + if(in_array(substr($token, 1), $stas_query["exclude"])) { + $result .= "$token "; + continue; + } + + $term = null; + $token_part = $token; + if(strpos($token_part, ":") !== false) $token_part = explode(":", $token_part, 2)[1]; + foreach($stas_query["terms"] as $c_term) { + if($c_term["term"] == $token_part) { + $term = $c_term; + break; + } + } + if($term == null) { + $result .= "$token "; + continue; + } + + $title = "?"; + $style = ""; + switch($term["weight"]) { + case -1: $style .= "color: grey; text-decoration: wavy line-through;"; $title = "stop word"; break; + case 1: $style .= "color: blue;"; $title = "normal word"; break; + } + switch($term["location"]) { + case "body": $style = "color: cyan"; $title = "body only"; break; + case "title": $style .= "font-weight: bolder; font-size: 1.2em; color: orange;"; $title = "searching title only"; break; + case "tags": $style .= "font-weight: bolder; color: purple;"; $title = "searching tags only"; break; + case "all": $title .= ", searching everywhere"; + } + + $result .= "$token "; + } + + exit(page_renderer::render_main("STAS Query Analysis - $settings->sitename", "
$settings->sitename understood your query to mean the following:
+$result")); + }); /* * ██████ ██████ ███████ ███ ██ ███████ ███████ █████ ██████ ██████ ██ ██ @@ -1066,7 +1113,7 @@ class search $result[$parts[0]] = []; switch($parts[0]) { - case "intitle": + case "intitle": // BUG: What if a normal word is found in a title? $result["terms"][] = [ "term" => $parts[1], "weight" => $settings->search_title_matches_weighting * mb_strlen($parts[1]),