Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions DSL/Query/Span/SpanFirstQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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;
}
}
61 changes: 61 additions & 0 deletions DSL/Query/Span/SpanMultiTermQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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;
use ONGR\ElasticsearchBundle\DSL\ParametersTrait;

/**
* Elasticsearch span multi term query.
*/
class SpanMultiTermQuery implements SpanQueryInterface
{
use ParametersTrait;

/**
* @var BuilderInterface
*/
private $query;

/**
* Accepts one of fuzzy, prefix, term range, wildcard, regexp query.
*
* @param BuilderInterface $query
* @param array $parameters
*/
public function __construct(BuilderInterface $query, array $parameters = [])
{
$this->query = $query;
$this->setParameters($parameters);
}

/**
* {@inheritdoc}
*/
public function getType()
{
return 'span_multi';
}

/**
* {@inheritdoc}
*
* @throws \InvalidArgumentException
*/
public function toArray()
{
$query['match'] = [$this->query->getType() => $this->query->toArray()];
$output = $this->processArray($query);

return $output;
}
}
62 changes: 62 additions & 0 deletions DSL/Query/Span/SpanNearQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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;
}
}
65 changes: 65 additions & 0 deletions DSL/Query/Span/SpanNotQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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;
}
}
79 changes: 79 additions & 0 deletions DSL/Query/Span/SpanOrQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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;
}
}
21 changes: 21 additions & 0 deletions DSL/Query/Span/SpanQueryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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
{
}
28 changes: 28 additions & 0 deletions DSL/Query/Span/SpanTermQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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';
}
}
Loading