Skip to content

Commit

Permalink
Merge remote-tracking branch '5.x' into 6.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
  • Loading branch information
Simonas Šerlinskas committed Mar 9, 2018
2 parents e4df29d + 170b7e6 commit a572978
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
41 changes: 40 additions & 1 deletion docs/Query/Span/SpanNear.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
Documentation in progress...
# Span Near Query

> More info about span near query is in the [official elasticsearch docs][1]
Matches spans which are near one another. One can specify slop, the maximum number of intervening unmatched positions, as well as whether matches are required to be in-order. The span near query maps to Lucene SpanNearQuery. Here is an example:

## Simple example

```JSON
{
"query": {
"span_near" : {
"clauses" : [
{ "span_term" : { "field" : "value1" } },
{ "span_term" : { "field" : "value2" } },
{ "span_term" : { "field" : "value3" } }
],
"slop" : 12,
"in_order" : false
}
}
}
```

In DSL:

```php
$search = new Search();
$spanNearQuery = new SpanNearQuery();
$spanNearQuery->addQuery(new SpanTermQuery('field', 'value1'));
$spanNearQuery->addQuery(new SpanTermQuery('field', 'value2'));
$spanNearQuery->addQuery(new SpanTermQuery('field', 'value3'));
$spanNearQuery->addParameter('slop', 12);
$spanNearQuery->addParameter('in_order', false);
$search->addQuery($spanNearQuery);

$queryArray = $search->toArray();
```

[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-near-query.html
2 changes: 1 addition & 1 deletion src/BuilderBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function add(BuilderInterface $builder)
if (method_exists($builder, 'getName')) {
$name = $builder->getName();
} else {
$name = uniqid();
$name = bin2hex(random_bytes(30));
}

$this->bag[$name] = $builder;
Expand Down
20 changes: 20 additions & 0 deletions src/Query/Joining/NestedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,24 @@ public function toArray()
)
];
}

/**
* Returns nested query object.
*
* @return BuilderInterface
*/
public function getQuery()
{
return $this->query;
}

/**
* Returns path this query is set for.
*
* @return string
*/
public function getPath()
{
return $this->path;
}
}
2 changes: 2 additions & 0 deletions src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,8 @@ public function addUriParam($name, $value)
'lenient',
'explain',
'_source',
'_source_exclude',
'_source_include',
'stored_fields',
'sort',
'track_scores',
Expand Down
2 changes: 1 addition & 1 deletion src/SearchEndpoint/AbstractSearchEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function add(BuilderInterface $builder, $key = null)
}

if (!$key) {
$key = uniqid();
$key = bin2hex(random_bytes(30));
}

$this->container[$key] = $builder;
Expand Down

0 comments on commit a572978

Please sign in to comment.