Skip to content

Commit

Permalink
Search: add support for terminate_after option (#1168)
Browse files Browse the repository at this point in the history
* adds simple test for the option
* breaks out invalid option test into a separate test so that if the other options become invalid their exceptions will be detected
  • Loading branch information
gibrown authored and ruflin committed Sep 5, 2016
1 parent 8ce983b commit ccbd3df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
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

0 comments on commit ccbd3df

Please sign in to comment.