jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/343754 )

Change subject: Allow completion suggester to work with titles that look like 
integers
......................................................................


Allow completion suggester to work with titles that look like integers

Php is quite helpful by doing a wide variety of casting to array keys,
so it's not safe to assume that if you put arbitrary data into an array
key you can take that data back out. In this particular case we were
hitting:

* Strings containing valid integers will be cast to the integer type.

This caused us to pass integers to elasticsearch as the input, and
elasticsearch rejected those inputs and failed to complete building
the completion suggester indices. To fix stop using array keys, they
don't seem to be used for deduplication or anything useful here. Instead
hold onto the text string as part of the data array.

Also fixes an error where the provided $inputDoc is wrong, whatever
doc was last iterated was used as the $inputDoc, instead of the specific
$inputDoc that matches the suggest being generated.

Change-Id: I5b6abe658db0746c763f27b16e4826302899b777
(cherry picked from commit 37b8839080b8e9f8d0856fe5a64cbd4e4f691eee)
---
M includes/BuildDocument/Completion/SuggestBuilder.php
1 file changed, 7 insertions(+), 5 deletions(-)

Approvals:
  jenkins-bot: Verified
  Dereckson: Looks good to me, approved



diff --git a/includes/BuildDocument/Completion/SuggestBuilder.php 
b/includes/BuildDocument/Completion/SuggestBuilder.php
index 642d1af..ea0875a 100644
--- a/includes/BuildDocument/Completion/SuggestBuilder.php
+++ b/includes/BuildDocument/Completion/SuggestBuilder.php
@@ -147,9 +147,11 @@
                                        $score = (int) ($score * 
self::CROSSNS_DISCOUNT);
 
                                        $title = Title::makeTitle( 
$redir['namespace'], $redir['title'] );
-                                       $crossNsTitles[$redir['title']] = [
+                                       $crossNsTitles[] = [
                                                'title' => $title,
                                                'score' => $score,
+                                               'text' => $redir['title'],
+                                               'inputDoc' => $inputDoc,
                                        ];
                                }
                        }
@@ -158,7 +160,7 @@
                // Build cross ns suggestions
                if ( !empty ( $crossNsTitles ) ) {
                        $titles = [];
-                       foreach( $crossNsTitles as $text => $data ) {
+                       foreach( $crossNsTitles as $data ) {
                                $titles[] = $data['title'];
                        }
                        $lb = new LinkBatch( $titles );
@@ -169,12 +171,12 @@
                        //   is the official one
                        // - we will certainly suggest multiple times the same 
pages
                        // - we must not run a second pass at query time: no 
redirect suggestion
-                       foreach ( $crossNsTitles as $text => $data ) {
+                       foreach ( $crossNsTitles as $data ) {
                                $suggestion = [
-                                       'text' => $text,
+                                       'text' => $data['text'],
                                        'variants' => []
                                ];
-                               $docs[] = $this->buildTitleSuggestion( 
$data['title']->getArticleID(), $suggestion, $data['score'], $inputDoc );
+                               $docs[] = $this->buildTitleSuggestion( 
$data['title']->getArticleID(), $suggestion, $data['score'], $data['inputDoc'] 
);
                        }
                }
                return $docs;

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5b6abe658db0746c763f27b16e4826302899b777
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: wmf/1.29.0-wmf.16
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: DCausse <[email protected]>
Gerrit-Reviewer: Dereckson <[email protected]>
Gerrit-Reviewer: Gehel <[email protected]>
Gerrit-Reviewer: Smalyshev <[email protected]>
Gerrit-Reviewer: Tjones <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to