Skip to content

Commit a8566e1

Browse files
committed
Merge branch 'master' into php7-compatibility
2 parents 79541e6 + c2c95f6 commit a8566e1

32 files changed

+630
-446
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ indent_style = space
1919
[Vagrantfile]
2020
indent_size = 2
2121
indent_style = space
22+
23+
[Makefile]
24+
indent_size = 4
25+
indent_style = tab

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ env:
2020
- ES_COMPOSER_NODEV=no
2121
- ES_COMPOSER_NODEV=yes
2222

23+
before_insll:
24+
- pip install codecov
25+
2326
install:
2427
- /bin/bash ansible/provision.sh
2528

@@ -37,3 +40,6 @@ after_script:
3740
- cat build/logs/phpunit-tap.log
3841
- sudo composer require satooshi/php-coveralls --no-ansi --no-progress --no-interaction
3942
- php vendor/bin/coveralls -v
43+
44+
after_success:
45+
- codecov

changes.txt renamed to CHANGELOG.md

+148-149
Large diffs are not rendered by default.

README.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Contributing
1515
------------
1616
Help is very welcomed, but code contributions must be done in respect of [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md). More details on how to contribute and guidelines for [pull requests](http://elastica.io/contribute/pull-request.html) can be found [here](http://elastica.io/contribute/).
1717

18-
See [Coding guidelines](http://elastica.io/contribute/coding-guidelines.html) for tips on how to do so. All changes which are made to the project are added to the [changes.txt](https://github.com/ruflin/Elastica/blob/master/changes.txt).
18+
See [Coding guidelines](http://elastica.io/contribute/coding-guidelines.html) for tips on how to do so. All changes which are made to the project are added to the [CHANGELOG.md](https://github.com/ruflin/Elastica/blob/master/CHANGELOG.md).
1919

2020

2121
Dependencies

composer.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
"psr/log": "~1.0"
1717
},
1818
"require-dev": {
19-
"munkie/elasticsearch-thrift-php": "1.4.*",
20-
"phpunit/phpunit": "4.1.*",
21-
"fabpot/php-cs-fixer": "~1.4"
19+
"munkie/elasticsearch-thrift-php": "1.4.*"
2220
},
2321
"suggest": {
2422
"munkie/elasticsearch-thrift-php": "Allow using thrift transport",
@@ -34,7 +32,7 @@
3432
},
3533
"extra": {
3634
"branch-alias": {
37-
"dev-master": "1.4.x-dev"
35+
"dev-master": "2.0.x-dev"
3836
}
3937
}
4038
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace Elastica\Aggregation;
4+
5+
/**
6+
* Class AbstractTermsAggergation
7+
* @package Elastica\Aggregation
8+
*/
9+
abstract class AbstractTermsAggregation extends AbstractSimpleAggregation
10+
{
11+
12+
/**
13+
* Set the minimum number of documents in which a term must appear in order to be returned in a bucket
14+
* @param int $count
15+
* @return $this
16+
*/
17+
public function setMinimumDocumentCount($count)
18+
{
19+
return $this->setParam("min_doc_count", $count);
20+
}
21+
22+
/**
23+
* Filter documents to include based on a regular expression
24+
* @param string $pattern a regular expression
25+
* @param string $flags Java Pattern flags
26+
* @return $this
27+
*/
28+
public function setInclude($pattern, $flags = null)
29+
{
30+
if (is_null($flags)) {
31+
return $this->setParam("include", $pattern);
32+
}
33+
34+
return $this->setParam("include", array(
35+
"pattern" => $pattern,
36+
"flags" => $flags,
37+
));
38+
}
39+
40+
/**
41+
* Filter documents to exclude based on a regular expression
42+
* @param string $pattern a regular expression
43+
* @param string $flags Java Pattern flags
44+
* @return $this
45+
*/
46+
public function setExclude($pattern, $flags = null)
47+
{
48+
if (is_null($flags)) {
49+
return $this->setParam("exclude", $pattern);
50+
}
51+
52+
return $this->setParam("exclude", array(
53+
"pattern" => $pattern,
54+
"flags" => $flags,
55+
));
56+
}
57+
58+
/**
59+
* Sets the amount of terms to be returned.
60+
* @param int $size The amount of terms to be returned.
61+
* @return $this
62+
*/
63+
public function setSize($size)
64+
{
65+
return $this->setParam('size', $size);
66+
}
67+
68+
/**
69+
* Sets how many terms the coordinating node will request from each shard.
70+
* @param int $shard_size The amount of terms to be returned.
71+
* @return $this
72+
*/
73+
public function setShardSize($shard_size)
74+
{
75+
return $this->setParam('shard_size', $shard_size);
76+
}
77+
78+
/**
79+
* Instruct Elasticsearch to use direct field data or ordinals of the field values to execute this aggregation.
80+
* The execution hint will be ignored if it is not applicable.
81+
* @param string $hint map or ordinals
82+
* @return $this
83+
*/
84+
public function setExecutionHint($hint)
85+
{
86+
return $this->setParam("execution_hint", $hint);
87+
}
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Elastica\Aggregation;
4+
5+
use Elastica\Filter\AbstractFilter;
6+
7+
/**
8+
* Class SignificantTerms
9+
* @package Elastica\Aggregation
10+
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html
11+
*/
12+
class SignificantTerms extends AbstractTermsAggregation
13+
{
14+
15+
/**
16+
* The default source of statistical information for background term frequencies is the entire index and this scope can
17+
* be narrowed through the use of a background_filter to focus in on significant terms within a narrower context
18+
* @param AbstractFilter $filter
19+
* @return $this
20+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html#_custom_background_context
21+
*
22+
*/
23+
public function setBackgroundFilter(AbstractFilter $filter)
24+
{
25+
return $this->setParam("background_filter", $filter->toArray());
26+
}
27+
28+
}

lib/Elastica/Aggregation/Terms.php

+1-77
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @package Elastica\Aggregation
88
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
99
*/
10-
class Terms extends AbstractSimpleAggregation
10+
class Terms extends AbstractTermsAggregation
1111
{
1212
/**
1313
* Set the bucket sort order
@@ -20,80 +20,4 @@ public function setOrder($order, $direction)
2020
return $this->setParam("order", array($order => $direction));
2121
}
2222

23-
/**
24-
* Set the minimum number of documents in which a term must appear in order to be returned in a bucket
25-
* @param int $count
26-
* @return $this
27-
*/
28-
public function setMinimumDocumentCount($count)
29-
{
30-
return $this->setParam("min_doc_count", $count);
31-
}
32-
33-
/**
34-
* Filter documents to include based on a regular expression
35-
* @param string $pattern a regular expression
36-
* @param string $flags Java Pattern flags
37-
* @return $this
38-
*/
39-
public function setInclude($pattern, $flags = null)
40-
{
41-
if (is_null($flags)) {
42-
return $this->setParam("include", $pattern);
43-
}
44-
45-
return $this->setParam("include", array(
46-
"pattern" => $pattern,
47-
"flags" => $flags,
48-
));
49-
}
50-
51-
/**
52-
* Filter documents to exclude based on a regular expression
53-
* @param string $pattern a regular expression
54-
* @param string $flags Java Pattern flags
55-
* @return $this
56-
*/
57-
public function setExclude($pattern, $flags = null)
58-
{
59-
if (is_null($flags)) {
60-
return $this->setParam("exclude", $pattern);
61-
}
62-
63-
return $this->setParam("exclude", array(
64-
"pattern" => $pattern,
65-
"flags" => $flags,
66-
));
67-
}
68-
69-
/**
70-
* Sets the amount of terms to be returned.
71-
* @param int $size The amount of terms to be returned.
72-
* @return $this
73-
*/
74-
public function setSize($size)
75-
{
76-
return $this->setParam('size', $size);
77-
}
78-
79-
/**
80-
* Sets how many terms the coordinating node will request from each shard.
81-
* @param int $shard_size The amount of terms to be returned.
82-
* @return $this
83-
*/
84-
public function setShardSize($shard_size)
85-
{
86-
return $this->setParam('shard_size', $shard_size);
87-
}
88-
89-
/**
90-
* Instruct Elasticsearch to use direct field data or ordinals of the field values to execute this aggregation.
91-
* The execution hint will be ignored if it is not applicable.
92-
* @param string $hint map or ordinals
93-
* @return $this
94-
*/
95-
public function setExecutionHint($hint)
96-
{
97-
return $this->setParam("execution_hint", $hint);
98-
}
9923
}

lib/Elastica/Connection.php

+29
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ class Connection extends Param
3737
*/
3838
const TIMEOUT = 300;
3939

40+
/**
41+
* Number of seconds after a connection timeout occurs for every request during the connection phase.
42+
* @see Connection::setConnectTimeout();
43+
*/
44+
const CONNECT_TIMEOUT = 0;
45+
4046
/**
4147
* Creates a new connection object. A connection is enabled by default
4248
*
@@ -159,6 +165,29 @@ public function getTimeout()
159165
return (int) $this->hasParam('timeout') ? $this->getParam('timeout') : self::TIMEOUT;
160166
}
161167

168+
/**
169+
* Number of seconds after a connection timeout occurs for every request during the connection phase.
170+
* Use a small value if you need a fast fail in case of dead, unresponsive or unreachable servers (~5 sec).
171+
*
172+
* Set to zero to switch to the default built-in connection timeout (300 seconds in curl).
173+
* @see http://curl.haxx.se/libcurl/c/CURLOPT_CONNECTTIMEOUT.html
174+
*
175+
* @param int $timeout Connect timeout in seconds
176+
* @return $this
177+
*/
178+
public function setConnectTimeout($timeout)
179+
{
180+
return $this->setParam('connectTimeout', $timeout);
181+
}
182+
183+
/**
184+
* @return int Connection timeout in seconds
185+
*/
186+
public function getConnectTimeout()
187+
{
188+
return (int) $this->hasParam('connectTimeout') ? $this->getParam('connectTimeout') : self::CONNECT_TIMEOUT;
189+
}
190+
162191
/**
163192
* Enables a connection
164193
*

lib/Elastica/Query.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,23 @@ public function setSuggest(Suggest $suggest)
401401
/**
402402
* Add a Rescore
403403
*
404-
* @param \Elastica\Rescore\AbstractRescore $rescore suggestion object
404+
* @param mixed $rescore suggestion object
405405
* @return $this
406406
*/
407407
public function setRescore($rescore)
408408
{
409-
return $this->setParam('rescore', $rescore->toArray());
409+
if (is_array($rescore)) {
410+
$buffer = array();
411+
412+
foreach($rescore as $rescoreQuery) {
413+
$buffer []= $rescoreQuery->toArray();
414+
}
415+
}
416+
else {
417+
$buffer = $rescore->toArray();
418+
}
419+
420+
return $this->setParam('rescore', $buffer);
410421
}
411422

412423
/**

lib/Elastica/QueryBuilder/DSL/Aggregation.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Elastica\Aggregation\Stats;
2626
use Elastica\Aggregation\Sum;
2727
use Elastica\Aggregation\Terms;
28+
use Elastica\Aggregation\SignificantTerms;
2829
use Elastica\Aggregation\TopHits;
2930
use Elastica\Aggregation\ValueCount;
3031
use Elastica\Exception\NotImplementedException;
@@ -318,10 +319,11 @@ public function terms($name)
318319
*
319320
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html
320321
* @param string $name
322+
* @return SignificantTerms
321323
*/
322324
public function significant_terms($name)
323325
{
324-
throw new NotImplementedException();
326+
return new SignificantTerms($name);
325327
}
326328

327329
/**

lib/Elastica/Transport/Http.php

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ public function exec(Request $request, array $params)
7272
curl_setopt($conn, CURLOPT_TIMEOUT, $connection->getTimeout());
7373
curl_setopt($conn, CURLOPT_FORBID_REUSE, 0);
7474

75+
/* @see Connection::setConnectTimeout() */
76+
$connectTimeout = $connection->getConnectTimeout();
77+
if ($connectTimeout>0) {
78+
curl_setopt($conn, CURLOPT_CONNECTTIMEOUT, $connectTimeout);
79+
}
80+
7581
$proxy = $connection->getProxy();
7682

7783
// See: https://github.com/facebook/hhvm/issues/4875

0 commit comments

Comments
 (0)