Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search: add support for terminate_after option #1168

Merged
merged 5 commits into from
Sep 5, 2016
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ All notable changes to this project will be documented in this file based on the
- Elastica\Aggregation\GeoCentroid [#1150](https://github.com/ruflin/Elastica/pull/1150)
- [Multi value field](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_multi_values_fields) param for decay function.
- Elastica\Client::getVersion [#1152](https://github.com/ruflin/Elastica/pull/1152)
- Added support for terminate_after parameter in search queries [#1168](https://github.com/ruflin/Elastica/pull/1168)

### Improvements
- Set PHP 7.0 as default development version
Expand Down
2 changes: 2 additions & 0 deletions lib/Elastica/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Search
const OPTION_SCROLL = 'scroll';
const OPTION_SCROLL_ID = 'scroll_id';
const OPTION_QUERY_CACHE = 'query_cache';
const OPTION_TERMINATE_AFTER = 'terminate_after';

/*
* Search types
Expand Down Expand Up @@ -296,6 +297,7 @@ protected function _validateOption($key)
case self::OPTION_SEARCH_TYPE_SUGGEST:
case self::OPTION_SEARCH_IGNORE_UNAVAILABLE:
case self::OPTION_QUERY_CACHE:
case self::OPTION_TERMINATE_AFTER:
return true;
}

Expand Down
14 changes: 13 additions & 1 deletion test/lib/Elastica/Test/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ public function testLimitDefaultSearch()

/**
* @group functional
* @expectedException \Elastica\Exception\InvalidException
*/
public function testArrayConfigSearch()
{
Expand Down Expand Up @@ -418,6 +417,10 @@ public function testArrayConfigSearch()
$resultSet = $search->search('test', ['limit' => 5, 'routing' => 'r1,r2']);
$this->assertEquals(5, $resultSet->count());

//Array with terminate_after
$resultSet = $search->search('test', array('terminate_after' => 100));
$this->assertEquals(10, $resultSet->count());

//Search types
$resultSet = $search->search('test', ['limit' => 5, 'search_type' => 'count']);
$this->assertTrue(($resultSet->count() === 0) && $resultSet->getTotalHits() === 11);
Expand All @@ -435,7 +438,16 @@ public function testArrayConfigSearch()
$query->addScriptScoreFunction($script);
$resultSet = $search->search($query, ['timeout' => 50]);
$this->assertTrue($resultSet->hasTimedOut());
}

/**
* @group functional
* @expectedException \Elastica\Exception\InvalidException
*/
public function testInvalidConfigSearch()
{
$client = $this->_getClient();
$search = new Search($client);
// Throws InvalidException
$resultSet = $search->search('test', ['invalid_option' => 'invalid_option_value']);
}
Expand Down