Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
FuzzyLikeThis.php
Go to the documentation of this file.
1<?php
48class FuzzyLikeThis extends \Elastica\Query\AbstractQuery {
49 // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
55 protected $_fields = [];
61 protected $_likeText = '';
67 protected $_ignoreTF = false;
73 protected $_maxQueryTerms = 25;
79 protected $_fuzziness = 2;
85 protected $_prefixLength = 0;
91 protected $_analyzer;
92 // phpcs:enable
93
101 public function addFields( array $fields ) {
102 $this->_fields = $fields;
103
104 return $this;
105 }
106
114 public function setLikeText( $text ) {
115 $text = trim( $text );
116 $this->_likeText = $text;
117
118 return $this;
119 }
120
128 public function setIgnoreTF( $ignoreTF ) {
129 $this->_ignoreTF = (bool)$ignoreTF;
130
131 return $this;
132 }
133
141 public function setFuzziness( $value ) {
142 $value = (int)$value;
143 $this->_fuzziness = $value;
144
145 return $this;
146 }
147
153 public function setPrefixLength( $value ) {
154 $this->_prefixLength = (int)$value;
155
156 return $this;
157 }
158
166 public function setMaxQueryTerms( $value ) {
167 $this->_maxQueryTerms = (int)$value;
168
169 return $this;
170 }
171
177 public function setAnalyzer( $text ) {
178 $text = trim( $text );
179 $this->_analyzer = $text;
180
181 return $this;
182 }
183
191 public function toArray() {
192 $args = [];
193 if ( !empty( $this->_fields ) ) {
194 $args['fields'] = $this->_fields;
195 }
196
197 if ( !empty( $this->_analyzer ) ) {
198 $args['analyzer'] = $this->_analyzer;
199 }
200
201 $args['fuzziness'] = ( $this->_fuzziness > 0 ) ? $this->_fuzziness : 0;
202
203 $args['like_text'] = $this->_likeText;
204 $args['prefix_length'] = $this->_prefixLength;
205 $args['ignore_tf'] = $this->_ignoreTF;
206 $args['max_query_terms'] = $this->_maxQueryTerms;
207
208 $data = parent::toArray();
209 $args = array_merge( $args, $data['fuzzy_like_this'] );
210
211 return [ 'fuzzy_like_this' => $args ];
212 }
213}
Fuzzy Like This query.
toArray()
Converts fuzzy like this query to array.
addFields(array $fields)
Adds field to flt query.
setMaxQueryTerms( $value)
Set max_query_terms.
setLikeText( $text)
Set the "like_text" value.
setIgnoreTF( $ignoreTF)
Set the "ignore_tf" value (ignore term frequency).
setFuzziness( $value)
Set the minimum similarity.
setPrefixLength( $value)