Skip to content
Snippets Groups Projects
Commit 752a57f1 authored by Mantas Jonušas's avatar Mantas Jonušas
Browse files

DSL Span queries

parent b59f8def
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;
use ONGR\ElasticsearchBundle\DSL\ParametersTrait;
/**
* Elasticsearch span near query.
*/
class SpanNearQuery implements SpanQueryInterface
{
use ParametersTrait;
/**
* @var int
*/
private $slop;
/**
* @var SpanQueryInterface[]
*/
private $queries = [];
/**
* @param int $slop
* @param SpanQueryInterface[] $queries
* @param array $parameters
*
* @throws \LogicException
*/
public function __construct($slop, array $queries = [], array $parameters = [])
{
$this->slop = $slop;
$this->queries = $queries;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'span_near';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [];
foreach ($this->queries as $type) {
$data = [$type->getType() => $type->toArray()];
$query['clauses'][] = $data;
}
$query['slop'] = $this->slop;
$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 SpanQueryInterface[] $queries
* @param array $parameters
*/
public function __construct(array $queries = [], array $parameters = [])
{
foreach ($queries as $query) {
$this->queries[] = $query;
}
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'span_or';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [];
foreach ($this->queries as $type) {
$data = [$type->getType() => $type->toArray()];
$query['clauses'][] = $data;
}
$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