Skip to content
GitLab
Explore
Sign in
Register
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
a87b1905
Commit
a87b1905
authored
9 years ago
by
Mantas Urnieža
Browse files
Options
Downloads
Patches
Plain Diff
Adding timout and terminate_after parameters to Search object.
parent
913be5ff
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
src/Search.php
+40
-0
40 additions, 0 deletions
src/Search.php
tests/SearchTest.php
+79
-0
79 additions, 0 deletions
tests/SearchTest.php
with
119 additions
and
0 deletions
src/Search.php
+
40
−
0
View file @
a87b1905
...
...
@@ -43,6 +43,16 @@ class Search
*/
private
$from
;
/**
* @var string
*/
private
$timeout
;
/**
* @var int
*/
private
$terminateAfter
;
/**
* @var string|null
*/
...
...
@@ -400,6 +410,34 @@ class Search
return
$this
;
}
/**
* Sets timeout for query execution.
*
* @param $timeout
*
* @return $this
*/
public
function
setTimeout
(
$timeout
)
{
$this
->
timeout
=
$timeout
;
return
$this
;
}
/**
* Sets maximum number of documents per shard.
*
* @param $terminateAfter
*
* @return $this
*/
public
function
setTerminateAfter
(
$terminateAfter
)
{
$this
->
terminateAfter
=
$terminateAfter
;
return
$this
;
}
/**
* Returns results offset value.
*
...
...
@@ -674,6 +712,8 @@ class Search
'stats'
=>
'stats'
,
'minScore'
=>
'min_score'
,
'source'
=>
'_source'
,
'timeout'
=>
'timeout'
,
'terminateAfter'
=>
'terminate_after'
,
];
foreach
(
$params
as
$field
=>
$param
)
{
...
...
This diff is collapsed.
Click to expand it.
tests/SearchTest.php
+
79
−
0
View file @
a87b1905
...
...
@@ -25,4 +25,83 @@ class SearchTest extends \PHPUnit_Framework_TestCase
{
$this
->
assertInstanceOf
(
'ONGR\ElasticsearchDSL\Search'
,
new
Search
());
}
/**
* Data provider for test testSettingParams()
*
* @return array
*/
public
function
getTestSettingParamsData
()
{
$cases
=
[];
$search
=
new
Search
();
$search
->
setSize
(
3
);
$cases
[
'Only size is set'
]
=
[
$search
,
[
'size'
=>
3
,
],
];
$search
=
new
Search
();
$search
->
setFrom
(
4
);
$cases
[
'Only from is set'
]
=
[
$search
,
[
'from'
=>
4
,
],
];
$search
=
new
Search
();
$search
->
setTimeout
(
'2s'
);
$cases
[
'Only timeout is set'
]
=
[
$search
,
[
'timeout'
=>
'2s'
,
],
];
$search
=
new
Search
();
$search
->
setTerminateAfter
(
100
);
$cases
[
'Only terminate_after is set'
]
=
[
$search
,
[
'terminate_after'
=>
100
,
],
];
$search
=
new
Search
();
$search
->
setSize
(
3
);
$search
->
setFrom
(
4
);
$search
->
setTimeout
(
'2s'
);
$search
->
setTerminateAfter
(
100
);
$cases
[
'Multiple parameters are set'
]
=
[
$search
,
[
'size'
=>
3
,
'from'
=>
4
,
'timeout'
=>
'2s'
,
'terminate_after'
=>
100
,
],
];
return
$cases
;
}
/**
* This test checks if parameters are correctly set into Search object.
*
* @dataProvider getTestSettingParamsData()
*
* @param Search $search
* @param array $expected
*/
public
function
testSettingParams
(
$search
,
$expected
)
{
$this
->
assertEquals
(
$expected
,
$search
->
toArray
()
);
}
}
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