Skip to content
Snippets Groups Projects
Unverified Commit 6f0e33bc authored by Simonas Šerlinskas's avatar Simonas Šerlinskas
Browse files

Merge branch '6.x'

parents 197eedda 9b023dc9
No related branches found
No related tags found
No related merge requests found
Showing
with 216 additions and 31 deletions
......@@ -12,11 +12,11 @@ install:
- tar -xzf elasticsearch-${ES_VERSION}.tar.gz
- ./elasticsearch-${ES_VERSION}/bin/elasticsearch -d
before_script:
- composer config -g github-oauth.github.com $GITHUB_COMPOSER_AUTH
- if [ "$GITHUB_COMPOSER_AUTH" ]; then composer config -g github-oauth.github.com $GITHUB_COMPOSER_AUTH; fi
- composer install --no-interaction --prefer-dist
script:
- wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200
- vendor/bin/phpunit --coverage-clover=coverage.xml
- vendor/bin/phpcs -p --standard=PSR2 --ignore=vendor/ ./
after_script:
- travis_retry bash <(curl -s https://codecov.io/bash)
\ No newline at end of file
- travis_retry bash <(curl -s https://codecov.io/bash)
......@@ -105,7 +105,7 @@ $queryArray = $search->toArray();
```php
$functionScoreQuery = new FunctionScoreQuery(new MatchAllQuery());
$existsQuery = new ExistsQuery('price');
$functionScoreQuery->addFieldValueFactorFunction('price', 0.5, 'ln', $existsQuery);
$functionScoreQuery->addFieldValueFactorFunction('price', 0.5, 'ln', $existsQuery, 0);
$search = new Search();
$search->addQuery($functionScoreQuery);
......
......@@ -58,10 +58,14 @@ abstract class AbstractAggregation implements NamedBuilderInterface
/**
* @param string $field
*
* @return $this
*/
public function setField($field)
{
$this->field = $field;
return $this;
}
/**
......
......@@ -50,13 +50,15 @@ class ChildrenAggregation extends AbstractAggregation
}
/**
* Sets children.
*
* @param string $children
*
* @return $this
*/
public function setChildren($children)
{
$this->children = $children;
return $this;
}
/**
......
......@@ -29,11 +29,21 @@ class CompositeAggregation extends AbstractAggregation
*/
private $sources = [];
/**
* @var int
*/
private $size;
/**
* @var array
*/
private $after;
/**
* Inner aggregations container init.
*
* @param string $name
* @param BuilderInterface[] $sources
* @param AbstractAggregation[] $sources
*/
public function __construct($name, $sources = [])
{
......@@ -45,16 +55,20 @@ class CompositeAggregation extends AbstractAggregation
}
/**
* @param BuilderInterface $agg
* @param AbstractAggregation $agg
*
* @throws \LogicException
*
* @return self
*/
public function addSource(BuilderInterface $agg)
public function addSource(AbstractAggregation $agg)
{
$array = $agg->getArray();
$array = is_array($array) ? array_merge($array, $agg->getParameters()) : $array;
$this->sources[] = [
$agg->getName() => [ $agg->getType() => $agg->getArray() ]
$agg->getName() => [ $agg->getType() => $array ]
];
return $this;
......@@ -65,9 +79,19 @@ class CompositeAggregation extends AbstractAggregation
*/
public function getArray()
{
return [
$array = [
'sources' => $this->sources,
];
if ($this->size !== null) {
$array['size'] = $this->size;
}
if (!empty($this->after)) {
$array['after'] = $this->after;
}
return $array;
}
/**
......@@ -77,4 +101,52 @@ class CompositeAggregation extends AbstractAggregation
{
return 'composite';
}
/**
* Sets size
*
* @param int $size Size
*
* @return $this
*/
public function setSize($size)
{
$this->size = $size;
return $this;
}
/**
* Returns size
*
* @return int
*/
public function getSize()
{
return $this->size;
}
/**
* Sets after
*
* @param array $after After
*
* @return $this
*/
public function setAfter(array $after)
{
$this->after = $after;
return $this;
}
/**
* Returns after
*
* @return array
*/
public function getAfter()
{
return $this->after;
}
}
......@@ -59,18 +59,26 @@ class DateHistogramAggregation extends AbstractAggregation
/**
* @param string $interval
*
* @return $this
*/
public function setInterval($interval)
{
$this->interval = $interval;
return $this;
}
/**
* @param string $format
*
* @return $this
*/
public function setFormat($format)
{
$this->format = $format;
return $this;
}
/**
......
......@@ -29,25 +29,29 @@ class DateRangeAggregation extends AbstractAggregation
private $format;
/**
* @return string
* @var array
*/
public function getFormat()
{
return $this->format;
}
private $ranges = [];
/**
* @var bool
*/
private $keyed = false;
/**
* @param string $name
* @param string $field
* @param string $format
* @param array $ranges
* @param bool $keyed
*/
public function __construct($name, $field = null, $format = null, array $ranges = [])
public function __construct($name, $field = null, $format = null, array $ranges = [], $keyed = false)
{
parent::__construct($name);
$this->setField($field);
$this->setFormat($format);
$this->setKeyed($keyed);
foreach ($ranges as $range) {
$from = isset($range['from']) ? $range['from'] : null;
$to = isset($range['to']) ? $range['to'] : null;
......@@ -57,23 +61,41 @@ class DateRangeAggregation extends AbstractAggregation
}
/**
* @param string $format
* Sets if result buckets should be keyed.
*
* @param bool $keyed
*
* @return DateRangeAggregation
*/
public function setFormat($format)
public function setKeyed($keyed)
{
$this->format = $format;
$this->keyed = $keyed;
return $this;
}
/**
* @var array
* @return string
*/
private $ranges = [];
public function getFormat()
{
return $this->format;
}
/**
* @param string $format
*/
public function setFormat($format)
{
$this->format = $format;
}
/**
* Add range to aggregation.
*
* @param string|null $from
* @param string|null $to
* @param string|null $key
*
* @return $this
*
......@@ -111,6 +133,7 @@ class DateRangeAggregation extends AbstractAggregation
'format' => $this->getFormat(),
'field' => $this->getField(),
'ranges' => $this->ranges,
'keyed' => $this->keyed,
];
return $data;
......
......@@ -54,10 +54,14 @@ class DiversifiedSamplerAggregation extends AbstractAggregation
/**
* @param mixed $shardSize
*
* @return $this
*/
public function setShardSize($shardSize)
{
$this->shardSize = $shardSize;
return $this;
}
/**
......
......@@ -45,13 +45,15 @@ class FilterAggregation extends AbstractAggregation
}
/**
* Sets a filter.
*
* @param BuilderInterface $filter
*
* @return $this
*/
public function setFilter(BuilderInterface $filter)
{
$this->filter = $filter;
return $this;
}
/**
......
......@@ -58,7 +58,7 @@ class FiltersAggregation extends AbstractAggregation
/**
* @param bool $anonymous
*
* @return FiltersAggregation
* @return $this
*/
public function setAnonymous($anonymous)
{
......
......@@ -78,10 +78,14 @@ class GeoDistanceAggregation extends AbstractAggregation
/**
* @param mixed $origin
*
* @return $this
*/
public function setOrigin($origin)
{
$this->origin = $origin;
return $this;
}
/**
......@@ -94,10 +98,14 @@ class GeoDistanceAggregation extends AbstractAggregation
/**
* @param string $distanceType
*
* @return $this
*/
public function setDistanceType($distanceType)
{
$this->distanceType = $distanceType;
return $this;
}
/**
......@@ -110,10 +118,14 @@ class GeoDistanceAggregation extends AbstractAggregation
/**
* @param string $unit
*
* @return $this
*/
public function setUnit($unit)
{
$this->unit = $unit;
return $this;
}
/**
......
......@@ -67,10 +67,14 @@ class GeoHashGridAggregation extends AbstractAggregation
/**
* @param int $precision
*
* @return $this
*/
public function setPrecision($precision)
{
$this->precision = $precision;
return $this;
}
/**
......@@ -83,10 +87,14 @@ class GeoHashGridAggregation extends AbstractAggregation
/**
* @param int $size
*
* @return $this
*/
public function setSize($size)
{
$this->size = $size;
return $this;
}
/**
......@@ -99,10 +107,14 @@ class GeoHashGridAggregation extends AbstractAggregation
/**
* @param int $shardSize
*
* @return $this
*/
public function setShardSize($shardSize)
{
$this->shardSize = $shardSize;
return $this;
}
/**
......
......@@ -102,10 +102,14 @@ class HistogramAggregation extends AbstractAggregation
* Get response as a hash instead keyed by the buckets keys.
*
* @param bool $keyed
*
* @return $this
*/
public function setKeyed($keyed)
{
$this->keyed = $keyed;
return $this;
}
/**
......@@ -113,11 +117,15 @@ class HistogramAggregation extends AbstractAggregation
*
* @param string $mode
* @param string $direction
*
* @return $this
*/
public function setOrder($mode, $direction = self::DIRECTION_ASC)
{
$this->orderMode = $mode;
$this->orderDirection = $direction;
return $this;
}
/**
......@@ -142,10 +150,14 @@ class HistogramAggregation extends AbstractAggregation
/**
* @param int $interval
*
* @return $this
*/
public function setInterval($interval)
{
$this->interval = $interval;
return $this;
}
/**
......@@ -160,10 +172,14 @@ class HistogramAggregation extends AbstractAggregation
* Set limit for document count buckets should have.
*
* @param int $minDocCount
*
* @return $this
*/
public function setMinDocCount($minDocCount)
{
$this->minDocCount = $minDocCount;
return $this;
}
/**
......@@ -177,6 +193,8 @@ class HistogramAggregation extends AbstractAggregation
/**
* @param int $min
* @param int $max
*
* @return $this
*/
public function setExtendedBounds($min = null, $max = null)
{
......@@ -188,6 +206,8 @@ class HistogramAggregation extends AbstractAggregation
'strlen'
);
$this->extendedBounds = $bounds;
return $this;
}
/**
......
......@@ -52,13 +52,15 @@ class NestedAggregation extends AbstractAggregation
}
/**
* Sets path.
*
* @param string $path
*
* @return $this
*/
public function setPath($path)
{
$this->path = $path;
return $this;
}
/**
......
......@@ -60,7 +60,7 @@ class RangeAggregation extends AbstractAggregation
*
* @param bool $keyed
*
* @return RangeAggregation
* @return $this
*/
public function setKeyed($keyed)
{
......
......@@ -52,13 +52,15 @@ class ReverseNestedAggregation extends AbstractAggregation
}
/**
* Sets path.
*
* @param string $path
*
* @return $this
*/
public function setPath($path)
{
$this->path = $path;
return $this;
}
/**
......
......@@ -54,10 +54,14 @@ class SamplerAggregation extends AbstractAggregation
/**
* @param int $shardSize
*
* @return $this
*/
public function setShardSize($shardSize)
{
$this->shardSize = $shardSize;
return $this;
}
/**
......
......@@ -60,10 +60,14 @@ class MaxAggregation extends AbstractAggregation
/**
* @param string $mode
*
* @return $this
*/
public function setMode($mode)
{
$this->mode = $mode;
return $this;
}
/**
......@@ -76,10 +80,14 @@ class MaxAggregation extends AbstractAggregation
/**
* @param array $missing
*
* @return $this
*/
public function setMissing($missing)
{
$this->missing = $missing;
return $this;
}
/**
......
......@@ -58,13 +58,15 @@ class CardinalityAggregation extends AbstractAggregation
}
/**
* Precision threshold.
* @param int $precision
*
* @param int $precision Precision Threshold.
* @return $this
*/
public function setPrecisionThreshold($precision)
{
$this->precisionThreshold = $precision;
return $this;
}
/**
......@@ -85,10 +87,14 @@ class CardinalityAggregation extends AbstractAggregation
/**
* @param bool $rehash
*
* @return $this
*/
public function setRehash($rehash)
{
$this->rehash = $rehash;
return $this;
}
/**
......
......@@ -57,10 +57,14 @@ class ExtendedStatsAggregation extends AbstractAggregation
/**
* @param int $sigma
*
* @return $this
*/
public function setSigma($sigma)
{
$this->sigma = $sigma;
return $this;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment