19 protected $hl = [
'',
'' ];
22 $this->params = $params;
23 $this->server = $server;
26 public function getDocuments() {
28 $offset = $this->params[
'offset'];
29 $limit = $this->params[
'limit'];
31 $options = $this->params;
32 $options[
'language'] = $this->params[
'sourcelanguage'];
35 $options[
'limit'] = $limit * 10;
40 $options[
'offset'] = 0;
43 $search = $this->server->createSearch( $this->params[
'query'], $options, $this->hl );
44 $scroll = $search->scroll(
'5s' );
47 $this->resultset =
null;
49 foreach ( $scroll as $resultSet ) {
50 if ( !$this->resultset ) {
51 $this->resultset = $resultSet;
56 $documents = array_merge( $documents, $results );
58 $count = count( $documents );
60 if ( $count >= $offset + $limit ) {
65 if ( !$this->resultset ) {
67 $this->resultset = $scroll->current();
68 $this->total = $scroll->current()->getTotalHits();
72 if ( is_callable( [ $scroll,
'clear' ] ) ) {
75 $documents = array_slice( $documents, $offset, $limit );
89 $messages = $ret = [];
91 $language = $this->params[
'language'];
92 foreach ( $documents as $document ) {
93 $data = $document->getData();
96 if ( !$this->server->isLocalSuggestion( $data ) ) {
100 $title = Title::newFromText( $data[
'localid'] );
106 if ( !$handle->isValid() ) {
110 $key = $title->getNamespace() .
':' . $title->getDBkey();
111 $messages[$key] = $data[
'content'];
115 $collection = MessageCollection::newFromDefinitions( $definitions, $language );
117 $filter = $this->params[
'filter'];
118 if ( $filter ===
'untranslated' ) {
119 $collection->filter(
'hastranslation',
true );
121 $collection->filter( $filter,
false );
124 if ( $filter ===
'translated' || $filter ===
'fuzzy' ) {
125 $collection->loadTranslations();
128 foreach ( $collection->keys() as $mkey => $titleValue ) {
129 $title = Title::newFromLinkTarget( $titleValue );
132 $result[
'content'] = $messages[$mkey];
133 if ( $filter ===
'translated' || $filter ===
'fuzzy' ) {
134 $result[
'content'] = $collection[$mkey]->translation();
137 $result[
'localid'] = $handle->getTitleForBase()->getPrefixedText();
138 $result[
'language'] = $language;
155 public function getTotalHits() {
159 public function getResultSet() {
160 return $this->resultset;