EBernhardson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/398192 )

Change subject: Silently drop unknown titles in completion search
......................................................................

Silently drop unknown titles in completion search

This mimics how full text works by silenty dropping results returned from
search that no longer exist. This could be because the search index is slightly
out of sync with reality, or the search engine could simply be broken.

Only silent from the users perspective. We maintain a count in statsd of
the number of titles dropped. This can be monitored over time to
recognize any increases.

Bug: T115756
Change-Id: I2f29d73e258cd448a14d35a2b4902a4fb6f61c68
---
M includes/search/SearchEngine.php
M includes/search/SearchSuggestionSet.php
2 files changed, 31 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/92/398192/1

diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php
index 3c8fe60..94e0d80 100644
--- a/includes/search/SearchEngine.php
+++ b/includes/search/SearchEngine.php
@@ -580,6 +580,16 @@
                $lb->setCaller( __METHOD__ );
                $lb->execute();
 
+               $before = $suggestions->count();
+               $suggestions = $suggestions->filter( function ( 
SearchSuggestion $sugg ) {
+                       return $sugg->getSuggestedTitle()->isKnown();
+               } );
+               $after = $suggestions->count();
+               if ( $before !== $after ) {
+                       MediaWikiServices::getInstance()->getStatsdDataFactory()
+                               ->updateCount( 'search.completion.missing', 
$before - $after );
+               }
+
                $results = $suggestions->map( function ( SearchSuggestion $sugg 
) {
                        return $sugg->getSuggestedTitle()->getPrefixedText();
                } );
diff --git a/includes/search/SearchSuggestionSet.php 
b/includes/search/SearchSuggestionSet.php
index aced5e1..7c4b484 100644
--- a/includes/search/SearchSuggestionSet.php
+++ b/includes/search/SearchSuggestionSet.php
@@ -23,7 +23,7 @@
  * A set of search suggestions.
  * The set is always ordered by score, with the best match first.
  */
-class SearchSuggestionSet {
+class SearchSuggestionSet implements Countable {
        /**
         * @var SearchSuggestion[]
         */
@@ -73,6 +73,19 @@
                return array_map( $callback, $this->suggestions );
        }
 
+       /**
+        * Filter the suggestions array
+        * @param callback $callback
+        * @return self
+        */
+       public function filter( $callback ) {
+               $suggestions = array_filter( $this->suggestions, $callback );
+               if ( count( $suggestions ) === count( $this->suggestions ) ) {
+                       return $this;
+               } else {
+                       return new self( $suggestions );
+               }
+       }
        /**
         * Add a new suggestion at the end.
         * If the score of the new suggestion is greater than the worst one,
@@ -171,6 +184,13 @@
        }
 
        /**
+        * @return int The number of suggestions held
+        */
+       public function count() {
+               return count( $this->suggestions );
+       }
+
+       /**
         * Builds a new set of suggestion based on a title array.
         * Useful when using a backend that supports only Titles.
         *

-- 
To view, visit https://gerrit.wikimedia.org/r/398192
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2f29d73e258cd448a14d35a2b4902a4fb6f61c68
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to