Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elasticsearch DSL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Public
Elasticsearch DSL
Commits
e3d35016
Commit
e3d35016
authored
8 years ago
by
Mantas
Browse files
Options
Downloads
Patches
Plain Diff
added tests and documentation for the span within query
parent
5b1f88c4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
docs/Query/SpanWithin.md
+50
-0
50 additions, 0 deletions
docs/Query/SpanWithin.md
tests/Query/Span/SpanWithinQueryTest.php
+57
-0
57 additions, 0 deletions
tests/Query/Span/SpanWithinQueryTest.php
with
107 additions
and
0 deletions
docs/Query/SpanWithin.md
0 → 100644
+
50
−
0
View file @
e3d35016
# Span Within query
> More info about Boosting query is in the [official elasticsearch docs][1]
Returns matches which are enclosed inside another span query.
```
JSON
{
"span_within" : {
"little" : {
"span_term" : { "field1" : "foo" }
},
"big" : {
"span_near" : {
"clauses" : [
{ "span_term" : { "field1" : "bar" } },
{ "span_term" : { "field1" : "baz" } }
],
"slop" : 5,
"in_order" : true
}
}
}
}
```
And now the query via DSL:
```
php
$spanTermQuery
=
new
SpanTermQuery
(
'field1'
,
'foo'
);
$spanNearQuery
=
new
SpanNearQuery
();
$spanNearQuery
->
setSlop
(
5
);
$spanNearQuery
->
addParameter
(
'in_order'
,
true
);
$spanNearQuery
->
addQuery
(
new
SpanTermQuery
(
'field1'
,
'bar'
));
$spanNearQuery
->
addQuery
(
new
SpanTermQuery
(
'field1'
,
'baz'
));
$spanWithinQuery
=
new
SpanWithinQuery
(
$spanTermQuery
,
$spanNearQuery
);
$search
=
new
Search
();
$search
->
addQuery
(
$spanWithinQuery
);
$queryArray
=
$search
->
toArray
();
```
[
1
]:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-within-query.html
This diff is collapsed.
Click to expand it.
tests/Query/Span/SpanWithinQueryTest.php
0 → 100644
+
57
−
0
View file @
e3d35016
<?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\ElasticsearchDSL\Tests\Query\Span
;
use
ONGR\ElasticsearchDSL\Query\Span\SpanWithinQuery
;
/**
* Unit test for SpanWithinQuery.
*/
class
SpanWithinQueryTest
extends
\PHPUnit_Framework_TestCase
{
/**
* Tests for toArray().
*/
public
function
testToArray
()
{
$query
=
new
SpanWithinQuery
(
$this
->
getSpanQueryMock
(
'foo'
),
$this
->
getSpanQueryMock
(
'bar'
)
);
$result
=
[
'span_within'
=>
[
'little'
=>
[
'span_term'
=>
[
'user'
=>
'foo'
],
],
'big'
=>
[
'span_term'
=>
[
'user'
=>
'bar'
],
],
],
];
$this
->
assertEquals
(
$result
,
$query
->
toArray
());
}
/**
* @param string $value
*
* @returns \PHPUnit_Framework_MockObject_MockObject
*/
private
function
getSpanQueryMock
(
$value
)
{
$mock
=
$this
->
getMock
(
'ONGR\ElasticsearchDSL\Query\Span\SpanQueryInterface'
);
$mock
->
expects
(
$this
->
once
())
->
method
(
'toArray'
)
->
willReturn
([
'span_term'
=>
[
'user'
=>
$value
]]);
return
$mock
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment