16 protected $hl = [
'',
'' ];
19 $this->params = $params;
20 $this->server = $server;
23 public function getDocuments() {
25 $offset = $this->params[
'offset'];
26 $limit = $this->params[
'limit'];
28 $options = $this->params;
29 $options[
'language'] = $this->params[
'sourcelanguage'];
32 $options[
'limit'] = $limit * 10;
37 $options[
'offset'] = 0;
40 $search = $this->server->createSearch( $this->params[
'query'], $options, $this->hl );
41 $scroll = $search->scroll(
'5s' );
44 $this->resultset =
null;
46 foreach ( $scroll as $resultSet ) {
47 if ( !$this->resultset ) {
48 $this->resultset = $resultSet;
53 $documents = array_merge( $documents, $results );
55 $count = count( $documents );
57 if ( $count >= $offset + $limit ) {
62 if ( !$this->resultset ) {
64 $this->resultset = $scroll->current();
65 $this->total = $scroll->current()->getTotalHits();
69 if ( is_callable( [ $scroll,
'clear' ] ) ) {
72 $documents = array_slice( $documents, $offset, $limit );
86 $messages = $ret = [];
88 $language = $this->params[
'language'];
89 foreach ( $documents as $document ) {
90 $data = $document->getData();
93 if ( !$this->server->isLocalSuggestion( $data ) ) {
97 $title = Title::newFromText( $data[
'localid'] );
103 if ( !$handle->isValid() ) {
107 $key = $title->getNamespace() .
':' . $title->getDBkey();
108 $messages[$key] = $data[
'content'];
112 $collection = MessageCollection::newFromDefinitions( $definitions, $language );
114 $filter = $this->params[
'filter'];
115 if ( $filter ===
'untranslated' ) {
116 $collection->filter(
'hastranslation',
true );
118 $collection->filter( $filter,
false );
121 if ( $filter ===
'translated' || $filter ===
'fuzzy' ) {
122 $collection->loadTranslations();
125 foreach ( $collection->keys() as $mkey => $titleValue ) {
126 $title = Title::newFromLinkTarget( $titleValue );
129 $result[
'content'] = $messages[$mkey];
130 if ( $filter ===
'translated' || $filter ===
'fuzzy' ) {
131 $result[
'content'] = $collection[$mkey]->translation();
134 $result[
'localid'] = $handle->getTitleForBase()->getPrefixedText();
135 $result[
'language'] = $language;
152 public function getTotalHits() {
156 public function getResultSet() {
157 return $this->resultset;