20 protected $hl = [
'',
'' ];
23 $this->params = $params;
24 $this->server = $server;
27 public function getDocuments() {
29 $offset = $this->params[
'offset'];
30 $limit = $this->params[
'limit'];
32 $options = $this->params;
33 $options[
'language'] = $this->params[
'sourcelanguage'];
36 $options[
'limit'] = $limit * 10;
41 $options[
'offset'] = 0;
44 $search = $this->server->createSearch( $this->params[
'query'], $options, $this->hl );
45 $scroll = $search->scroll(
'5s' );
48 $this->resultset =
null;
50 foreach ( $scroll as $resultSet ) {
51 if ( !$this->resultset ) {
52 $this->resultset = $resultSet;
57 $documents = array_merge( $documents, $results );
59 $count = count( $documents );
61 if ( $count >= $offset + $limit ) {
66 if ( !$this->resultset ) {
68 $this->resultset = $scroll->current();
69 $this->total = $scroll->current()->getTotalHits();
73 if ( is_callable( [ $scroll,
'clear' ] ) ) {
76 $documents = array_slice( $documents, $offset, $limit );
90 $messages = $ret = [];
92 $language = $this->params[
'language'];
93 foreach ( $documents as $document ) {
94 $data = $document->getData();
97 if ( !$this->server->isLocalSuggestion( $data ) ) {
101 $title = Title::newFromText( $data[
'localid'] );
107 if ( !$handle->isValid() ) {
111 $key = $title->getNamespace() .
':' . $title->getDBkey();
112 $messages[$key] = $data[
'content'];
116 $collection = MessageCollection::newFromDefinitions( $definitions, $language );
118 $filter = $this->params[
'filter'];
119 if ( $filter ===
'untranslated' ) {
120 $collection->filter(
'hastranslation',
true );
122 $collection->filter( $filter,
false );
125 if ( $filter ===
'translated' || $filter ===
'fuzzy' ) {
126 $collection->loadTranslations();
129 foreach ( $collection->keys() as $mkey => $titleValue ) {
130 $title = Title::newFromLinkTarget( $titleValue );
133 $result[
'content'] = $messages[$mkey];
134 if ( $filter ===
'translated' || $filter ===
'fuzzy' ) {
135 $result[
'content'] = $collection[$mkey]->translation();
138 $result[
'localid'] = $handle->getTitleForBase()->getPrefixedText();
139 $result[
'language'] = $language;
156 public function getTotalHits() {
160 public function getResultSet() {
161 return $this->resultset;