24 private const CONSTRUCTOR_OPTIONS = [
26 'TranslateTranslationDefaultService',
27 'TranslateTranslationServices',
30 public function __construct(
36 parent::__construct( $main, $moduleName );
37 $this->options =
new ServiceOptions( self::CONSTRUCTOR_OPTIONS, $config );
40 public function execute():
void {
41 if ( !$this->getSearchableTtmServers() ) {
42 $this->dieWithError(
'apierror-translate-notranslationservices' );
45 $params = $this->extractRequestParams();
47 $server = $this->ttmServerFactory->create( $params[
'service' ] );
49 $this->dieWithError(
'apierror-translate-notranslationservices' );
52 $result = $this->getResult();
55 if ( $params[
'filter'] !==
'' ) {
57 $documents = $translationSearch->getDocuments();
58 $total = $translationSearch->getTotalHits();
60 $searchResults = $server->search(
65 $documents = $server->getDocuments( $searchResults );
66 $total = $server->getTotalHits( $searchResults );
71 'Translation search server failed: {exception}',
74 $this->dieWithError(
'tux-sst-search-backend-error' );
79 $result->addValue( [
'search',
'metadata' ],
'total', $total );
80 $result->addValue(
'search',
'translations', $documents );
84 private function getSearchableTtmServers(): array {
85 $ttmServiceIds = $this->ttmServerFactory->getNames();
88 foreach ( $ttmServiceIds as $serviceId ) {
89 $ttmServer = $this->ttmServerFactory->create( $serviceId );
98 protected function getAllowedFilters(): array {
107 protected function getAllowedParams(): array {
108 $available = $this->getSearchableTtmServers();
110 $filters = $this->getAllowedFilters();
114 ParamValidator::PARAM_TYPE => $available,
117 ParamValidator::PARAM_TYPE =>
'string',
118 ParamValidator::PARAM_REQUIRED =>
true,
120 'sourcelanguage' => [
121 ParamValidator::PARAM_TYPE =>
'string',
122 ParamValidator::PARAM_DEFAULT => $this->options->get(
'LanguageCode' ),
125 ParamValidator::PARAM_TYPE =>
'string',
126 ParamValidator::PARAM_DEFAULT =>
'',
129 ParamValidator::PARAM_TYPE =>
'string',
130 ParamValidator::PARAM_DEFAULT =>
'',
133 ParamValidator::PARAM_TYPE => $filters,
134 ParamValidator::PARAM_DEFAULT =>
'',
137 ParamValidator::PARAM_TYPE =>
'string',
138 ParamValidator::PARAM_DEFAULT =>
'',
141 ParamValidator::PARAM_TYPE =>
'string',
142 ParamValidator::PARAM_DEFAULT =>
'0',
145 ParamValidator::PARAM_TYPE =>
'integer',
146 ParamValidator::PARAM_DEFAULT => 0,
149 ParamValidator::PARAM_DEFAULT => 25,
150 ParamValidator::PARAM_TYPE =>
'limit',
151 IntegerDef::PARAM_MIN => 1,
152 IntegerDef::PARAM_MAX => ApiBase::LIMIT_SML1,
153 IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_SML2
160 $ret[
'service'][ParamValidator::PARAM_DEFAULT] =
161 $this->options->get(
'TranslateTranslationDefaultService' );
167 protected function getExamplesMessages(): array {
169 'action=searchtranslations&language=fr&query=aide'
170 =>
'apihelp-searchtranslations-example-1',
171 'action=searchtranslations&language=fr&query=edit&filter=untranslated'
172 =>
'apihelp-searchtranslations-example-2',