Skip to content

Commit 6150be2

Browse files
committed
Resolve changes.txt issue
2 parents af6dbba + 5e19bfc commit 6150be2

22 files changed

+472
-100
lines changed

changes.txt

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
CHANGES
22

3+
2014-12-30
4+
- Added: Filter\Range::setExecution, Filter\Terms::setExecution, Filter\Missing::setExistence, Filter\Missing::setNullValue, Filter\HasChild::setMinumumChildrenCount, Filter\HasChild::Filter\HasChild::setMaximumChildrenCount, Filter\Indices::addIndex
5+
- Filter\HasChild::setType, Filter\HasParent::setType now support Type instance as argument
6+
- Filter\Indices::setIndices, Filter\Indices::addIndex now support Index instance as argument
7+
- (BC break) Removed as added by mistake: Filter\HasChild::setScope, Filter\HasParent::setScope, Filter\Nested::setScoreMode, Filter\Bool::setBoost
8+
39
2014-12-14
410
- Added fluent interface to Elastica\Query::setRescore #733
511

lib/Elastica/Filter/Bool.php

+1-20
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@
1010
* @category Xodoa
1111
* @package Elastica
1212
* @author Nicolas Ruflin <[email protected]>
13-
* @link http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html
13+
* @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-filter.html
1414
*/
1515
class Bool extends AbstractFilter
1616
{
17-
/**
18-
* @var float
19-
*/
20-
protected $_boost = 1.0;
21-
2217
/**
2318
* Must
2419
*
@@ -133,18 +128,4 @@ public function toArray()
133128

134129
return $args;
135130
}
136-
137-
/**
138-
* Sets the boost value for this filter
139-
*
140-
* @param float $boost Boost
141-
* @return \Elastica\Filter\Bool Current object
142-
*/
143-
public function setBoost($boost)
144-
{
145-
$this->_boost = $boost;
146-
147-
return $this;
148-
}
149-
150131
}

lib/Elastica/Filter/GeoDistance.php

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class GeoDistance extends AbstractGeoDistance
1414
{
1515
const DISTANCE_TYPE_ARC = 'arc';
1616
const DISTANCE_TYPE_PLANE = 'plane';
17+
const DISTANCE_TYPE_SLOPPY_ARC = 'sloppy_arc';
1718

1819
const OPTIMIZE_BBOX_MEMORY = 'memory';
1920
const OPTIMIZE_BBOX_INDEXED = 'indexed';

lib/Elastica/Filter/HasChild.php

+25-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class HasChild extends AbstractFilter
1616
* Construct HasChild filter
1717
*
1818
* @param string|\Elastica\Query|\Elastica\Filter\AbstractFilter $query Query string or a Elastica\Query object or a filter
19-
* @param string $type Parent document type
19+
* @param string|\Elastica\Type $type Child document type
2020
*/
2121
public function __construct($query, $type = null)
2222
{
@@ -50,29 +50,41 @@ public function setQuery($query)
5050
*/
5151
public function setFilter($filter)
5252
{
53-
$data = $filter->toArray();
54-
return $this->setParam('filter', $data);
53+
return $this->setParam('filter', $filter->toArray());
5554
}
5655

5756
/**
58-
* Set type of the parent document
57+
* Set type of the child document
5958
*
60-
* @param string $type Parent document type
61-
* @return \Elastica\Filter\HasChild Current object
59+
* @param string|\Elastica\Type $type Child document type
60+
* @return \Elastica\Filter\HasParent Current object
6261
*/
6362
public function setType($type)
6463
{
65-
return $this->setParam('type', $type);
64+
if ($type instanceof \Elastica\Type) {
65+
$type = $type->getName();
66+
}
67+
68+
return $this->setParam('type', (string) $type);
6669
}
6770

6871
/**
69-
* Sets the scope
70-
*
71-
* @param string $scope Scope
72-
* @return \Elastica\Filter\HasChild Current object
72+
* Set minimum number of children are required to match for the parent doc to be considered a match
73+
* @param int $count
74+
* @return \Elastica\Filter\HasChild
75+
*/
76+
public function setMinimumChildrenCount($count)
77+
{
78+
return $this->setParam('min_children', (int) $count);
79+
}
80+
81+
/**
82+
* Set maximum number of children are required to match for the parent doc to be considered a match
83+
* @param int $count
84+
* @return \Elastica\Filter\HasChild
7385
*/
74-
public function setScope($scope)
86+
public function setMaximumChildrenCount($count)
7587
{
76-
return $this->setParam('_scope', $scope);
88+
return $this->setParam('max_children', (int) $count);
7789
}
7890
}

lib/Elastica/Filter/HasParent.php

+9-17
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class HasParent extends AbstractFilter
1515
* Construct HasParent filter
1616
*
1717
* @param string|\Elastica\Query|\Elastica\Filter\AbstractFilter $query Query string or a Query object or a filter
18-
* @param string $type Parent document type
18+
* @param string|\Elastica\Type $type Parent document type
1919
*/
2020
public function __construct($query, $type)
2121
{
@@ -42,36 +42,28 @@ public function setQuery($query)
4242
}
4343

4444
/**
45-
* Sets query object
45+
* Sets filter object
4646
*
4747
* @param \Elastica\Filter\AbstractFilter $filter
4848
* @return \Elastica\Filter\HasParent Current object
4949
*/
5050
public function setFilter($filter)
5151
{
52-
$data = $filter->toArray();
53-
return $this->setParam('filter', $data);
52+
return $this->setParam('filter', $filter->toArray());
5453
}
5554

5655
/**
5756
* Set type of the parent document
5857
*
59-
* @param string $type Parent document type
60-
* @return \Elastica\Filter\HasParent Current object
58+
* @param string|\Elastica\Type $type Parent document type
59+
* @return \Elastica\Filter\HasParent Current object
6160
*/
6261
public function setType($type)
6362
{
64-
return $this->setParam('type', $type);
65-
}
63+
if ($type instanceof \Elastica\Type) {
64+
$type = $type->getName();
65+
}
6666

67-
/**
68-
* Sets the scope
69-
*
70-
* @param string $scope Scope
71-
* @return \Elastica\Filter\HasParent Current object
72-
*/
73-
public function setScope($scope)
74-
{
75-
return $this->setParam('_scope', $scope);
67+
return $this->setParam('type', (string) $type);
7668
}
7769
}

lib/Elastica/Filter/Indices.php

+23-5
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,49 @@
22

33
namespace Elastica\Filter;
44

5+
use Elastica\Index as ElasticaIndex;
56

67
/**
78
* Class Indices
89
* @package Elastica\Filter
9-
* @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/query-dsl-indices-filter.html
10+
* @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-indices-filter.html
1011
*/
1112
class Indices extends AbstractFilter
1213
{
1314
/**
1415
* @param AbstractFilter $filter filter which will be applied to docs in the specified indices
15-
* @param string[] $indices
16+
* @param mixed[] $indices
1617
*/
1718
public function __construct(AbstractFilter $filter, array $indices)
1819
{
1920
$this->setIndices($indices)->setFilter($filter);
2021
}
2122

2223
/**
23-
* Set the names of the indices on which this filter should be applied
24-
* @param string[] $indices
24+
* Set the indices on which this filter should be applied
25+
* @param mixed[] $indices
2526
* @return Indices
2627
*/
2728
public function setIndices(array $indices)
2829
{
29-
return $this->setParam('indices', $indices);
30+
$this->setParam('indices', array());
31+
foreach ($indices as $index) {
32+
$this->addIndex($index);
33+
}
34+
return $this;
35+
}
36+
37+
/**
38+
* Adds one more index on which this filter should be applied
39+
* @param string|\Elastica\Index $index
40+
* @return Indices
41+
*/
42+
public function addIndex($index)
43+
{
44+
if ($index instanceof ElasticaIndex) {
45+
$index = $index->getName();
46+
}
47+
return $this->addParam('indices', (string) $index);
3048
}
3149

3250
/**

lib/Elastica/Filter/Missing.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,31 @@ public function __construct($field = '')
2727
/**
2828
* Set field
2929
*
30-
* @param string $field
30+
* @param string $field
3131
* @return \Elastica\Filter\Missing
3232
*/
3333
public function setField($field)
3434
{
3535
return $this->setParam('field', (string) $field);
3636
}
37+
38+
/**
39+
* Set "existence" parameter
40+
* @param bool $existence
41+
* @return \Elastica\Filter\Missing
42+
*/
43+
public function setExistence($existence)
44+
{
45+
return $this->setParam('existence', (bool) $existence);
46+
}
47+
48+
/**
49+
* Set "null_value" parameter
50+
* @param bool $nullValue
51+
* @return \Elastica\Filter\Missing
52+
*/
53+
public function setNullValue($nullValue)
54+
{
55+
return $this->setParam('null_value', (bool) $nullValue);
56+
}
3757
}

lib/Elastica/Filter/Nested.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public function setFilter(AbstractFilter $filter)
4848
}
4949

5050
/**
51-
* Set score mode
51+
* Set join option
5252
*
53-
* @param string $scoreMode Options: avg, total, max and none.
53+
* @param bool $join
5454
* @return \Elastica\Filter\Nested
5555
*/
56-
public function setScoreMode($scoreMode)
56+
public function setJoin($join)
5757
{
58-
return $this->setParam('score_mode', $scoreMode);
58+
return $this->setParam('join', (bool) $join);
5959
}
6060
}

lib/Elastica/Filter/Range.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class Range extends AbstractFilter
2222
/**
2323
* Construct range filter
2424
*
25-
* @param string|bool $fieldName Field name
26-
* @param array $args Field arguments
25+
* @param string $fieldName Field name
26+
* @param array $args Field arguments
2727
*/
28-
public function __construct($fieldName = false, array $args = array())
28+
public function __construct($fieldName = '', array $args = array())
2929
{
3030
if ($fieldName) {
3131
$this->addField($fieldName, $args);
@@ -46,6 +46,17 @@ public function addField($fieldName, array $args)
4646
return $this;
4747
}
4848

49+
/**
50+
* Set execution mode
51+
*
52+
* @param string $execution Options: "index" or "fielddata"
53+
* @return \Elastica\Filter\Range
54+
*/
55+
public function setExecution($execution)
56+
{
57+
return $this->setParam('execution', (string) $execution);
58+
}
59+
4960
/**
5061
* Converts object to array
5162
*

lib/Elastica/Filter/Terms.php

+11
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,15 @@ public function toArray()
129129

130130
return array('terms' => $this->_params);
131131
}
132+
133+
/**
134+
* Set execution mode
135+
*
136+
* @param string $execution Options: "bool", "and", "or", "plain" or "fielddata"
137+
* @return \Elastica\Filter\Terms
138+
*/
139+
public function setExecution($execution)
140+
{
141+
return $this->setParam('execution', (string) $execution);
142+
}
132143
}

test/lib/Elastica/Test/Filter/BoolTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,31 @@ public function testBoolFilter()
145145

146146
$index->delete();
147147
}
148+
149+
/**
150+
* @expectedException \Elastica\Exception\InvalidException
151+
*/
152+
public function testAddMustInvalidException()
153+
{
154+
$filter = new Bool();
155+
$filter->addMust('fail!');
156+
}
157+
158+
/**
159+
* @expectedException \Elastica\Exception\InvalidException
160+
*/
161+
public function testAddMustNotInvalidException()
162+
{
163+
$filter = new Bool();
164+
$filter->addMustNot('fail!');
165+
}
166+
167+
/**
168+
* @expectedException \Elastica\Exception\InvalidException
169+
*/
170+
public function testAddShouldInvalidException()
171+
{
172+
$filter = new Bool();
173+
$filter->addShould('fail!');
174+
}
148175
}

0 commit comments

Comments
 (0)