47 private array $fieldNames = [];
48 private string $likeText =
'';
49 private bool $ignoreTermFrequency =
false;
50 private int $maxQueryTerms = 25;
51 private int $fuzziness = 2;
52 private int $prefixLength = 0;
53 private ?
string $analyzer =
null;
55 public function addFieldNames( array $fieldNames ):
self {
56 $this->fieldNames = $fieldNames;
60 public function setLikeText(
string $text ):
self {
61 $this->likeText = trim( $text );
66 public function setIgnoreTermFrequency(
bool $ignoreTermFrequency ):
self {
67 $this->ignoreTermFrequency = $ignoreTermFrequency;
72 public function setFuzziness(
int $value ):
self {
73 $this->fuzziness = $value;
78 public function setPrefixLength(
int $value ):
self {
79 $this->prefixLength = $value;
84 public function setMaxQueryTerms(
int $value ):
self {
85 $this->maxQueryTerms = $value;
90 public function setAnalyzer(
string $text ):
self {
91 $this->analyzer = trim( $text );
103 if ( $this->fieldNames !== [] ) {
104 $args[
'fields'] = $this->fieldNames;
107 if ( $this->analyzer ) {
108 $args[
'analyzer'] = $this->analyzer;
111 $args[
'fuzziness'] = ( $this->fuzziness > 0 ) ? $this->fuzziness : 0;
113 $args[
'like_text'] = $this->likeText;
114 $args[
'prefix_length'] = $this->prefixLength;
115 $args[
'ignore_tf'] = $this->ignoreTermFrequency;
116 $args[
'max_query_terms'] = $this->maxQueryTerms;
118 $data = parent::toArray();
119 $args = array_merge( $args, $data[
'fuzzy_like_this'] );
121 return [
'fuzzy_like_this' => $args ];