Skip to content

Commit

Permalink
PHP8 support
Browse files Browse the repository at this point in the history
* Swap Match and MatchQuery around in heirarchy
* Start testing on PHP 8
* Add yoast/phpunit-polyfills for PHPUnit support
* PHPUnit version for PHP 8 support (8.5.12 is lowest version with
  PHP >= 7.2 support; previous are ^7.2).
** Inspiration and help from
  e701617
  • Loading branch information
reedy authored and thePanz committed Sep 30, 2021
1 parent d2678ed commit d1a8e08
Show file tree
Hide file tree
Showing 59 changed files with 471 additions and 398 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
elasticsearch: '6.5.2'
- php: '7.4'
elasticsearch: '6.5.2'
- php: '8.0'
elasticsearch: '6.5.2'
fail-fast: false
steps:
- name: 'Checkout'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.vagrant
.php_cs
.php_cs.cache
.phpunit.result.cache

cache.properties
/nbproject
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
}
],
"require": {
"php": "^7.0",
"php": "^7.0||^8.0",
"ext-json": "*",
"psr/log": "~1.0",
"elasticsearch/elasticsearch": "^6.0"
},
"require-dev": {
"aws/aws-sdk-php": "~3.0",
"guzzlehttp/guzzle": "~6.0",
"phpunit/phpunit": "^6.0"
"phpunit/phpunit": "^6.0||^8.5.20",
"yoast/phpunit-polyfills": "1.0.1"
},
"conflict": {
"elasticsearch/elasticsearch": "6.8.0 || 6.8.1"
Expand Down
208 changes: 2 additions & 206 deletions lib/Elastica/Query/Match.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,212 +5,8 @@
/**
* Match query.
*
* @author F21
* @author WONG Wing Lun <luiges90@gmail.com>
*
* @deprecated since version 6.1.2, use the MatchQuery class instead.
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
* @deprecated since 6.1.2, use the MatchQuery class instead.
*/
class Match extends AbstractQuery
class Match extends MatchQuery
{
const OPERATOR_OR = 'or';
const OPERATOR_AND = 'and';

const ZERO_TERM_NONE = 'none';
const ZERO_TERM_ALL = 'all';

const FUZZINESS_AUTO = 'AUTO';

/**
* @param string $field
* @param mixed $values
*/
public function __construct($field = null, $values = null)
{
if (null !== $field && null !== $values) {
$this->setParam($field, $values);
}
}

/**
* Sets a param for the message array.
*
* @param string $field
* @param mixed $values
*
* @return $this
*/
public function setField($field, $values)
{
return $this->setParam($field, $values);
}

/**
* Sets a param for the given field.
*
* @param string $field
* @param string $key
* @param string $value
*
* @return $this
*/
public function setFieldParam($field, $key, $value)
{
if (!isset($this->_params[$field])) {
$this->_params[$field] = [];
}

$this->_params[$field][$key] = $value;

return $this;
}

/**
* Sets the query string.
*
* @param string $field
* @param string $query
*
* @return $this
*/
public function setFieldQuery($field, $query)
{
return $this->setFieldParam($field, 'query', $query);
}

/**
* Set field operator.
*
* @param string $field
* @param string $operator
*
* @return $this
*/
public function setFieldOperator($field, $operator = self::OPERATOR_OR)
{
return $this->setFieldParam($field, 'operator', $operator);
}

/**
* Set field analyzer.
*
* @param string $field
* @param string $analyzer
*
* @return $this
*/
public function setFieldAnalyzer($field, $analyzer)
{
return $this->setFieldParam($field, 'analyzer', $analyzer);
}

/**
* Set field boost value.
*
* If not set, defaults to 1.0.
*
* @param string $field
* @param float $boost
*
* @return $this
*/
public function setFieldBoost($field, $boost = 1.0)
{
return $this->setFieldParam($field, 'boost', (float) $boost);
}

/**
* Set field minimum should match.
*
* @param string $field
* @param int|string $minimumShouldMatch
*
* @return $this
*
* @see Possible values for minimum_should_match https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html
*/
public function setFieldMinimumShouldMatch($field, $minimumShouldMatch)
{
return $this->setFieldParam($field, 'minimum_should_match', $minimumShouldMatch);
}

/**
* Set field fuzziness.
*
* @param string $field
* @param mixed $fuzziness
*
* @return $this
*/
public function setFieldFuzziness($field, $fuzziness)
{
return $this->setFieldParam($field, 'fuzziness', $fuzziness);
}

/**
* Set field fuzzy rewrite.
*
* @param string $field
* @param string $fuzzyRewrite
*
* @return $this
*/
public function setFieldFuzzyRewrite($field, $fuzzyRewrite)
{
return $this->setFieldParam($field, 'fuzzy_rewrite', $fuzzyRewrite);
}

/**
* Set field prefix length.
*
* @param string $field
* @param int $prefixLength
*
* @return $this
*/
public function setFieldPrefixLength($field, $prefixLength)
{
return $this->setFieldParam($field, 'prefix_length', (int) $prefixLength);
}

/**
* Set field max expansions.
*
* @param string $field
* @param int $maxExpansions
*
* @return $this
*/
public function setFieldMaxExpansions($field, $maxExpansions)
{
return $this->setFieldParam($field, 'max_expansions', (int) $maxExpansions);
}

/**
* Set zero terms query.
*
* If not set, default to 'none'
*
* @param string $field
* @param string $zeroTermQuery
*
* @return $this
*/
public function setFieldZeroTermsQuery($field, $zeroTermQuery = self::ZERO_TERM_NONE)
{
return $this->setFieldParam($field, 'zero_terms_query', $zeroTermQuery);
}

/**
* Set cutoff frequency.
*
* @param string $field
* @param float $cutoffFrequency
*
* @return $this
*/
public function setFieldCutoffFrequency($field, $cutoffFrequency)
{
return $this->setFieldParam($field, 'cutoff_frequency', $cutoffFrequency);
}
}
Loading

0 comments on commit d1a8e08

Please sign in to comment.