diff --git a/module_index.json b/module_index.json index e551b5b..6b0d40e 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": 1566506237, + "lastupdate": 1566508042, "optional": false, "extra_data": [] }, diff --git a/modules/feature-search.php b/modules/feature-search.php index 07ce496..1cfdf7d 100644 --- a/modules/feature-search.php +++ b/modules/feature-search.php @@ -366,8 +366,7 @@ register_module([ add_action("suggest-pages", function() { global $settings, $pageindex; - if($settings->dynamic_page_suggestion_count === 0) - { + if($settings->dynamic_page_suggestion_count === 0) { header("content-type: application/json"); header("content-length: 3"); 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"); } - $query = search::transliterate($_GET["query"]); - // Rank each page name $results = []; foreach($pageindex as $pageName => $entry) { @@ -699,7 +696,7 @@ class search if(self::$literator == null) 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 $result["terms"][] = [ "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" ]; } @@ -1148,7 +1145,7 @@ class search foreach($term_pageids as $pageid) { // Check to see if it contains any words we should exclude $skip = false; - foreach($query_stas["exclude"] as $exlc_term) { + foreach($query_stas["exclude"] as $excl_term) { if(self::$invindex->has("$excl_term|$pageid")) { $skip = true; break; @@ -1165,9 +1162,9 @@ class search // 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"], - $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: We got up to here; finish refactoring invindex_query - reset($matching_pages); foreach($matching_pages as $pageid => &$pagedata) { $pagedata["pagename"] = ids::getpagename($pageid); @@ -1376,7 +1371,7 @@ class search foreach($qterms as $qterm) { // Stop words are marked by STAS - if($qterm["weight"] <= 0) + if($qterm["weight"] == -1) continue; // From http://stackoverflow.com/a/2483859/1460422