jenkins-bot has submitted this change and it was merged.
Change subject: Support search for all words in the search string.
......................................................................
Support search for all words in the search string.
Provide a link under the search bar when the total results found is
greater than 100, to filter the results for all search words.
Parse the query string to get all the words and use nested bool
queries to find messages containing all the words.
Search for "page compare First", returns the messages containing
all the three terms "page", "compare" and "First" words in any order.
Bug: T100346
Change-Id: I8748d739eaff7ad2199c18ea09d2f12951ebe770
---
M i18n/search/en.json
M i18n/search/qqq.json
M resources/css/ext.translate.special.searchtranslations.css
M specials/SpecialSearchTranslations.php
M ttmserver/ElasticSearchTTMServer.php
5 files changed, 43 insertions(+), 7 deletions(-)
Approvals:
Nikerabbit: Looks good to me, approved
jenkins-bot: Verified
diff --git a/i18n/search/en.json b/i18n/search/en.json
index 6338ce0..498febe 100644
--- a/i18n/search/en.json
+++ b/i18n/search/en.json
@@ -24,5 +24,7 @@
"tux-sst-untranslated": "No translation from $1",
"tux-sst-outdated": "Outdated translations from $1",
"tux-sst-ellipsis-untranslated": "No translation",
- "tux-sst-ellipsis-outdated": "Outdated translations"
+ "tux-sst-ellipsis-outdated": "Outdated translations",
+ "tux-sst-link-all-match": "Require all search words.",
+ "tux-sst-match-message": "Showing translations which match any of the
search words. $1"
}
diff --git a/i18n/search/qqq.json b/i18n/search/qqq.json
index 1a5d303..6546902 100644
--- a/i18n/search/qqq.json
+++ b/i18n/search/qqq.json
@@ -26,5 +26,7 @@
"tux-sst-untranslated": "Label for a tab to show untranslated messages
matching the query in the source language. Parameters:\n* $1 - the language
code of the source text.",
"tux-sst-outdated": "Label for a tab to show outdated messages matching
the query in the source language. Parameters:\n* $1 - the language code of the
source text.",
"tux-sst-ellipsis-untranslated": "Used as label for an ellipsis to hide
untranslated messages.",
- "tux-sst-ellipsis-outdated": "Used as label for an ellipsis to hide
outdated messages."
+ "tux-sst-ellipsis-outdated": "Used as label for an ellipsis to hide
outdated messages.",
+ "tux-sst-link-all-match": "Link to filter the results to match all
search words.",
+ "tux-sst-match-message": "Used to inform users about an option to get
results for all search words. Parameters:\n* $1 - message
tux-sst-link-all-match."
}
diff --git a/resources/css/ext.translate.special.searchtranslations.css
b/resources/css/ext.translate.special.searchtranslations.css
index 7ab43a1..b13a374 100644
--- a/resources/css/ext.translate.special.searchtranslations.css
+++ b/resources/css/ext.translate.special.searchtranslations.css
@@ -180,3 +180,7 @@
.tux-searchpage .tux-message-selector .more ul a {
white-space: pre-wrap;
}
+
+.tux-searchpage .successbox {
+ margin-left: 25%;
+}
diff --git a/specials/SpecialSearchTranslations.php
b/specials/SpecialSearchTranslations.php
index 273505a..0d74f42 100644
--- a/specials/SpecialSearchTranslations.php
+++ b/specials/SpecialSearchTranslations.php
@@ -71,6 +71,7 @@
$opts->add( 'group', '' );
$opts->add( 'grouppath', '' );
$opts->add( 'filter', '' );
+ $opts->add( 'match', '' );
$opts->add( 'limit', $this->limit );
$opts->add( 'offset', 0 );
@@ -239,7 +240,7 @@
$search = $this->getSearchInput( $queryString );
$count = $this->msg( 'tux-sst-count' )->numParams( $total );
- $this->showSearch( $search, $count, $facetHtml, $resultsHtml );
+ $this->showSearch( $search, $count, $facetHtml, $resultsHtml,
$total );
}
protected function getLanguages( array $facet ) {
@@ -330,7 +331,7 @@
return $output;
}
- protected function showSearch( $search, $count, $facets, $results ) {
+ protected function showSearch( $search, $count, $facets, $results,
$total ) {
$messageSelector = $this->messageSelector();
$this->getOutput()->addHtml( <<<HTML
<div class="grid tux-searchpage">
@@ -340,6 +341,27 @@
<div class="row count">
<div class="nine columns offset-by-three">$count</div>
</div>
+HTML
+ );
+
+ $query = trim( $this->opts->getValue( 'query' ) );
+ $hasSpace = preg_match( '/\s/', $query );
+ $match = $this->opts->getValue( 'match' );
+ $size = 100;
+ if ( $total > $size && $match !== 'all' && $hasSpace ) {
+ $params = $this->opts->getChangedValues();
+ $params = array( 'match' => 'all' ) + $params;
+ $linkText = $this->msg( 'tux-sst-link-all-match'
)->text();
+ $link = $this->getTitle()->getFullUrl( $params );
+ $link = "<span class='plainlinks'>[$link
$linkText]</span>";
+
+ $this->getOutput()->wrapWikiMsg(
+ '<div class="successbox">$1</div>',
+ array( 'tux-sst-match-message', $link )
+ );
+ }
+
+ $this->getOutput()->addHtml( <<<HTML
<div class="row searchcontent">
<div class="three columns facets">$facets</div>
<div class="nine columns results">$results</div>
diff --git a/ttmserver/ElasticSearchTTMServer.php
b/ttmserver/ElasticSearchTTMServer.php
index bef1ed8..130675c 100644
--- a/ttmserver/ElasticSearchTTMServer.php
+++ b/ttmserver/ElasticSearchTTMServer.php
@@ -491,9 +491,10 @@
}
// Parse query string and build the search query
- protected function parseQueryString( $queryString ) {
+ protected function parseQueryString( $queryString, array $opts ) {
$fields = $highlights = array();
$terms = preg_split( '/\s+/', $queryString );
+ $match = $opts['match'];
// Map each word in the query string with its corresponding
field
foreach ( $terms as $term ) {
@@ -518,7 +519,12 @@
$messageQuery = new \Elastica\Query\Term();
$messageQuery->setTerm( 'localid', $word );
$boolQuery->addShould( $messageQuery );
- $searchQuery->addShould( $boolQuery );
+
+ if ( $match === 'all' ) {
+ $searchQuery->addMust( $boolQuery );
+ } else {
+ $searchQuery->addShould( $boolQuery );
+ }
// Fields for highlighting
$highlights[$analyzer] = array(
@@ -553,7 +559,7 @@
public function search( $queryString, $opts, $highlight ) {
$query = new \Elastica\Query();
- list( $searchQuery, $highlights ) = $this->parseQueryString(
$queryString );
+ list( $searchQuery, $highlights ) = $this->parseQueryString(
$queryString, $opts );
$query->setQuery( $searchQuery );
$language = new \Elastica\Facet\Terms( 'language' );
--
To view, visit https://gerrit.wikimedia.org/r/223765
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8748d739eaff7ad2199c18ea09d2f12951ebe770
Gerrit-PatchSet: 15
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Phoenix303 <[email protected]>
Gerrit-Reviewer: Nemo bis <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Phoenix303 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits