1<?php 2 3namespace Elastica\Query; 4 5/** 6 * Match Phrase query. 7 * 8 * @author Jacques Moati <jacques@moati.net> 9 * @author Tobias Schultze <http://tobion.de> 10 * 11 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html 12 */ 13class MatchPhrase extends AbstractQuery 14{ 15 /** 16 * @param mixed $values 17 */ 18 public function __construct(?string $field = null, $values = null) 19 { 20 if (null !== $field && null !== $values) { 21 $this->setParam($field, $values); 22 } 23 } 24 25 /** 26 * Sets a param for the message array. 27 * 28 * @param mixed $values 29 * 30 * @return $this 31 */ 32 public function setField(string $field, $values): self 33 { 34 return $this->setParam($field, $values); 35 } 36 37 /** 38 * Sets a param for the given field. 39 * 40 * @param bool|float|int|string $value 41 * 42 * @return $this 43 */ 44 public function setFieldParam(string $field, string $key, $value): self 45 { 46 if (!isset($this->_params[$field])) { 47 $this->_params[$field] = []; 48 } 49 50 $this->_params[$field][$key] = $value; 51 52 return $this; 53 } 54 55 /** 56 * Sets the query string. 57 * 58 * @return $this 59 */ 60 public function setFieldQuery(string $field, string $query): self 61 { 62 return $this->setFieldParam($field, 'query', $query); 63 } 64 65 /** 66 * Set field analyzer. 67 * 68 * @return $this 69 */ 70 public function setFieldAnalyzer(string $field, string $analyzer): self 71 { 72 return $this->setFieldParam($field, 'analyzer', $analyzer); 73 } 74 75 /** 76 * Set field boost value. 77 * 78 * If not set, defaults to 1.0. 79 * 80 * @return $this 81 */ 82 public function setFieldBoost(string $field, float $boost = 1.0): self 83 { 84 return $this->setFieldParam($field, 'boost', $boost); 85 } 86} 87