Skip to content
Snippets Groups Projects
Commit 481336a0 authored by Mantas Var's avatar Mantas Var
Browse files

Merge pull request #61 from mvar/update_to_array_structure

Include query type in query's toArray() response
parents 5ee3f67f 4934515e
No related branches found
No related tags found
No related merge requests found
Showing
with 43 additions and 43 deletions
......@@ -60,13 +60,11 @@ class HasChildQuery implements BuilderInterface
{
$query = [
'type' => $this->type,
'query' => [
$this->query->getType() => $this->query->toArray(),
],
'query' => $this->query->toArray(),
];
$output = $this->processArray($query);
return $output;
return [$this->getType() => $output];
}
}
......@@ -60,13 +60,11 @@ class HasParentQuery implements BuilderInterface
{
$query = [
'parent_type' => $this->parentType,
'query' => [
$this->query->getType() => $this->query->toArray(),
],
'query' => $this->query->toArray(),
];
$output = $this->processArray($query);
return $output;
return [$this->getType() => $output];
}
}
......@@ -57,6 +57,6 @@ class IdsQuery implements BuilderInterface
$output = $this->processArray($query);
return $output;
return [$this->getType() => $output];
}
}
......@@ -66,16 +66,16 @@ class IndicesQuery implements BuilderInterface
$output = ['index' => $this->indices[0]];
}
$output['query'] = [$this->query->getType() => $this->query->toArray()];
$output['query'] = $this->query->toArray();
if ($this->noMatchQuery !== null) {
if (is_a($this->noMatchQuery, 'ONGR\ElasticsearchDSL\BuilderInterface')) {
$output['no_match_query'] = [$this->noMatchQuery->getType() => $this->noMatchQuery->toArray()];
$output['no_match_query'] = $this->noMatchQuery->toArray();
} else {
$output['no_match_query'] = $this->noMatchQuery;
}
}
return $output;
return [$this->getType() => $output];
}
}
......@@ -47,7 +47,9 @@ class LimitQuery implements BuilderInterface
public function toArray()
{
return [
'value' => $this->value,
$this->getType() => [
'value' => $this->value,
],
];
}
}
......@@ -15,7 +15,7 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Represents Elasticsearch "bool" query.
* Represents Elasticsearch "match_all" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html
*/
......@@ -44,10 +44,6 @@ class MatchAllQuery implements BuilderInterface
*/
public function toArray()
{
if (count($this->getParameters()) > 0) {
return $this->getParameters();
}
return [];
return [$this->getType() => $this->getParameters()];
}
}
......@@ -64,6 +64,6 @@ class MatchQuery implements BuilderInterface
$this->field => $this->processArray($query),
];
return $output;
return [$this->getType() => $output];
}
}
......@@ -56,6 +56,6 @@ class MissingQuery implements BuilderInterface
$query = ['field' => $this->field];
$output = $this->processArray($query);
return $output;
return [$this->getType() => $output];
}
}
......@@ -57,6 +57,6 @@ class MoreLikeThisQuery implements BuilderInterface
$output = $this->processArray($query);
return $output;
return [$this->getType() => $output];
}
}
......@@ -63,6 +63,6 @@ class MultiMatchQuery implements BuilderInterface
$output = $this->processArray($query);
return $output;
return [$this->getType() => $output];
}
}
......@@ -58,13 +58,13 @@ class NestedQuery implements BuilderInterface
*/
public function toArray()
{
return $this->processArray(
[
'path' => $this->path,
'query' => [
$this->query->getType() => $this->query->toArray(),
],
]
);
return [
$this->getType() => $this->processArray(
[
'path' => $this->path,
'query' => $this->query->toArray(),
]
)
];
}
}
......@@ -66,6 +66,6 @@ class PrefixQuery implements BuilderInterface
$this->field => $this->processArray($query),
];
return $output;
return [$this->getType() => $output];
}
}
......@@ -55,6 +55,6 @@ class QueryStringQuery implements BuilderInterface
$output = $this->processArray($query);
return $output;
return [$this->getType() => $output];
}
}
......@@ -70,6 +70,6 @@ class RangeQuery implements BuilderInterface
$this->field => $this->getParameters(),
];
return $output;
return [$this->getType() => $output];
}
}
......@@ -66,6 +66,6 @@ class RegexpQuery implements BuilderInterface
$this->field => $this->processArray($query),
];
return $output;
return [$this->getType() => $output];
}
}
......@@ -54,6 +54,6 @@ class ScriptQuery implements BuilderInterface
$query = ['inline' => $this->script];
$output = $this->processArray($query);
return ['script' => $output];
return [$this->getType() => ['script' => $output]];
}
}
......@@ -55,6 +55,6 @@ class SimpleQueryStringQuery implements BuilderInterface
$output = $this->processArray($query);
return $output;
return [$this->getType() => $output];
}
}
......@@ -15,6 +15,8 @@ use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch span first query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html
*/
class SpanFirstQuery implements SpanQueryInterface
{
......@@ -58,10 +60,10 @@ class SpanFirstQuery implements SpanQueryInterface
public function toArray()
{
$query = [];
$query['match'] = [$this->query->getType() => $this->query->toArray()];
$query['match'] = $this->query->toArray();
$query['end'] = $this->end;
$output = $this->processArray($query);
return $output;
return [$this->getType() => $output];
}
}
......@@ -16,6 +16,8 @@ use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch span multi term query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-multi-term-query.html
*/
class SpanMultiTermQuery implements SpanQueryInterface
{
......@@ -54,9 +56,9 @@ class SpanMultiTermQuery implements SpanQueryInterface
public function toArray()
{
$query = [];
$query['match'] = [$this->query->getType() => $this->query->toArray()];
$query['match'] = $this->query->toArray();
$output = $this->processArray($query);
return $output;
return [$this->getType() => $output];
}
}
......@@ -13,6 +13,8 @@ namespace ONGR\ElasticsearchDSL\Query\Span;
/**
* Elasticsearch span near query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-near-query.html
*/
class SpanNearQuery extends SpanOrQuery implements SpanQueryInterface
{
......@@ -52,11 +54,11 @@ class SpanNearQuery extends SpanOrQuery implements SpanQueryInterface
{
$query = [];
foreach ($this->getQueries() as $type) {
$query['clauses'][] = [$type->getType() => $type->toArray()];
$query['clauses'][] = $type->toArray();
}
$query['slop'] = $this->getSlop();
$output = $this->processArray($query);
return $output;
return [$this->getType() => $output];
}
}
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