Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
FuzzyLikeThis.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\TtmServer;
5
6use Elastica\Query\AbstractQuery;
7
46class FuzzyLikeThis extends AbstractQuery {
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;
54
55 public function addFieldNames( array $fieldNames ): self {
56 $this->fieldNames = $fieldNames;
57 return $this;
58 }
59
60 public function setLikeText( string $text ): self {
61 $this->likeText = trim( $text );
62
63 return $this;
64 }
65
66 public function setIgnoreTermFrequency( bool $ignoreTermFrequency ): self {
67 $this->ignoreTermFrequency = $ignoreTermFrequency;
68
69 return $this;
70 }
71
72 public function setFuzziness( int $value ): self {
73 $this->fuzziness = $value;
74
75 return $this;
76 }
77
78 public function setPrefixLength( int $value ): self {
79 $this->prefixLength = $value;
80
81 return $this;
82 }
83
84 public function setMaxQueryTerms( int $value ): self {
85 $this->maxQueryTerms = $value;
86
87 return $this;
88 }
89
90 public function setAnalyzer( string $text ): self {
91 $this->analyzer = trim( $text );
92
93 return $this;
94 }
95
101 public function toArray(): array {
102 $args = [];
103 if ( $this->fieldNames !== [] ) {
104 $args['fields'] = $this->fieldNames;
105 }
106
107 if ( $this->analyzer ) {
108 $args['analyzer'] = $this->analyzer;
109 }
110
111 $args['fuzziness'] = ( $this->fuzziness > 0 ) ? $this->fuzziness : 0;
112
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;
117
118 $data = parent::toArray();
119 $args = array_merge( $args, $data['fuzzy_like_this'] );
120
121 return [ 'fuzzy_like_this' => $args ];
122 }
123}
NOTE: the following class has been copied from elastica 2.3.1 : https://github.com/ruflin/Elastica/bl...
toArray()
Converts fuzzy like this query to array.