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

Merge pull request #269 from chyzas/patch-dsl-queries

DSL Span queries
parents 56339f68 c0b75cf1
No related branches found
No related tags found
No related merge requests found
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\DSL\Query\Span;
use ONGR\ElasticsearchBundle\DSL\ParametersTrait;
/**
* Elasticsearch span first query.
*/
class SpanFirstQuery implements SpanQueryInterface
{
use ParametersTrait;
/**
* @var SpanQueryInterface
*/
private $query;
/**
* @var int
*/
private $end;
/**
* @param SpanQueryInterface $query
* @param int $end
* @param array $parameters
*
* @throws \LogicException
*/
public function __construct(SpanQueryInterface $query, $end, array $parameters = [])
{
$this->query = $query;
$this->end = $end;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'span_first';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [];
$query['match'] = [$this->query->getType() => $this->query->toArray()];
$query['end'] = $this->end;
$output = $this->processArray($query);
return $output;
}
}
......@@ -9,37 +9,32 @@
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\DSL\Query;
namespace ONGR\ElasticsearchBundle\DSL\Query\Span;
use ONGR\ElasticsearchBundle\DSL\BuilderInterface;
use ONGR\ElasticsearchBundle\DSL\ParametersTrait;
/**
* Elasticsearch span_term query class.
* Elasticsearch span multi term query.
*/
class SpanTermQuery implements BuilderInterface
class SpanMultiTermQuery implements SpanQueryInterface
{
use ParametersTrait;
/**
* @var string
* @var BuilderInterface
*/
private $field;
private $query;
/**
* @var string
* Accepts one of fuzzy, prefix, term range, wildcard, regexp query.
*
* @param BuilderInterface $query
* @param array $parameters
*/
private $value;
/**
* @param string $field
* @param string $value
* @param array $parameters
*/
public function __construct($field, $value, array $parameters = [])
public function __construct(BuilderInterface $query, array $parameters = [])
{
$this->field = $field;
$this->value = $value;
$this->query = $query;
$this->setParameters($parameters);
}
......@@ -48,21 +43,18 @@ class SpanTermQuery implements BuilderInterface
*/
public function getType()
{
return 'span_term';
return 'span_multi';
}
/**
* {@inheritdoc}
*
* @throws \InvalidArgumentException
*/
public function toArray()
{
$query = [
'value' => $this->value,
];
$output = [
$this->field => $this->processArray($query),
];
$query['match'] = [$this->query->getType() => $this->query->toArray()];
$output = $this->processArray($query);
return $output;
}
......
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\DSL\Query\Span;
/**
* Elasticsearch span near query.
*/
class SpanNearQuery extends SpanOrQuery implements SpanQueryInterface
{
/**
* @var int
*/
private $slop;
/**
* @return int
*/
public function getSlop()
{
return $this->slop;
}
/**
* @param int $slop
*/
public function setSlop($slop)
{
$this->slop = $slop;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'span_near';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [];
foreach ($this->getQueries() as $type) {
$query['clauses'][] = [$type->getType() => $type->toArray()];
}
$query['slop'] = $this->getSlop();
$output = $this->processArray($query);
return $output;
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\DSL\Query\Span;
use ONGR\ElasticsearchBundle\DSL\ParametersTrait;
/**
* Elasticsearch Span not query.
*/
class SpanNotQuery implements SpanQueryInterface
{
use ParametersTrait;
/**
* @var SpanQueryInterface
*/
private $include;
/**
* @var SpanQueryInterface
*/
private $exclude;
/**
* @param SpanQueryInterface $include
* @param SpanQueryInterface $exclude
* @param array $parameters
*/
public function __construct(SpanQueryInterface $include, SpanQueryInterface $exclude, array $parameters = [])
{
$this->include = $include;
$this->exclude = $exclude;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'span_not';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [
'include' => [$this->include->getType() => $this->include->toArray()],
'exclude' => [$this->exclude->getType() => $this->exclude->toArray()],
];
return $query;
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\DSL\Query\Span;
use ONGR\ElasticsearchBundle\DSL\ParametersTrait;
/**
* Elasticsearch span or query.
*/
class SpanOrQuery implements SpanQueryInterface
{
use ParametersTrait;
/**
* @var SpanQueryInterface[]
*/
private $queries = [];
/**
* @param array $parameters
*/
public function __construct(array $parameters = [])
{
$this->setParameters($parameters);
}
/**
* Add span query.
*
* @param SpanQueryInterface $query
*
* @return $this
*/
public function addQuery(SpanQueryInterface $query)
{
$this->queries[] = $query;
return $this;
}
/**
* @return SpanQueryInterface[]
*/
public function getQueries()
{
return $this->queries;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'span_or';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [];
foreach ($this->queries as $type) {
$query['clauses'][] = [$type->getType() => $type->toArray()];
}
$output = $this->processArray($query);
return $output;
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\DSL\Query\Span;
use ONGR\ElasticsearchBundle\DSL\BuilderInterface;
/**
* Interface SpanQueryInterface to recognise span queries.
*/
interface SpanQueryInterface extends BuilderInterface
{
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\DSL\Query\Span;
use ONGR\ElasticsearchBundle\DSL\Query\TermQuery;
/**
* Elasticsearch span_term query class.
*/
class SpanTermQuery extends TermQuery implements SpanQueryInterface
{
/**
* {@inheritdoc}
*/
public function getType()
{
return 'span_term';
}
}
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