Skip to content

Commit ae80d34

Browse files
deguifruflin
authored andcommitted
Add total hits relation in ResultSelt (#1694)
1 parent e62898f commit ae80d34

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

CHANGELOG.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ All notable changes to this project will be documented in this file based on the
55

66
### Backward Compatibility Breaks
77

8+
* The class `\Elastica\QueryBuilder\Version\Version240` has been moved to `\Elastica\QueryBuilder\Version\Version700` [#1693](https://github.com/ruflin/Elastica/pull/1693)
9+
810
### Bugfixes
911

12+
* The `\Elastica\Query\GeoPolygon::count()` method now returns the count of points passed to the filter [#1696](https://github.com/ruflin/Elastica/pull/1696)
13+
1014
### Added
15+
16+
* Added `\Elastica\ResultSet::getTotalHitsRelation()` to get relation for total hits [#1694](https://github.com/ruflin/Elastica/pull/1694)
1117
* Added `Sampler` aggregation [#1688](https://github.com/ruflin/Elastica/pull/1688)
1218

1319
### Improvements
@@ -19,7 +25,6 @@ All notable changes to this project will be documented in this file based on the
1925

2026
### Backward Compatibility Breaks
2127
* The class `\Elastica\Type\Mapping` has been moved to `\Elastica\Mapping` [#1666](https://github.com/ruflin/Elastica/pull/1666)
22-
* The class `\Elastica\QueryBuilder\Version\Version240` has been moved to `\Elastica\QueryBuilder\Version\Version700` and type query was removed [#1693](https://github.com/ruflin/Elastica/pull/1693)
2328
* The `\Elastica\Query::$_suggest` property has been renamed to `$hasSuggest` and is now private, it should not be used from extending classes [#1679](https://github.com/ruflin/Elastica/pull/1679)
2429
* `\Elastica\Document` expects a string as ID, not an int [#1672](https://github.com/ruflin/Elastica/pull/1672).
2530
* Removed `\Elastica\Query\GeohashCell` query, use `\Elastica\Query\GeoBoundingBox` instead [#1672](https://github.com/ruflin/Elastica/pull/1672).
@@ -50,7 +55,6 @@ All notable changes to this project will be documented in this file based on the
5055

5156
### Bugfixes
5257

53-
* The `\Elastica\Query\GeoPolygon::count()` method now returns the count of points passed to the filter [#1696](https://github.com/ruflin/Elastica/pull/1696)
5458
* Always set the Guzzle `base_uri` to support connecting to multiple ES hosts. [#1618](https://github.com/ruflin/Elastica/pull/1618)
5559
* Properly handle underscore prefixes in options and bulk request metadata ([cf upstream](https://github.com/elastic/elasticsearch/issues/26886). [#1621](https://github.com/ruflin/Elastica/pull/1621)
5660
* Preserve zeros while doing float serialization to JSON. [#1635](https://github.com/ruflin/Elastica/pull/1635)

lib/Elastica/ResultSet.php

+10
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ public function getTotalHits()
160160
return (int) ($data['hits']['total']['value'] ?? 0);
161161
}
162162

163+
/**
164+
* Returns the total number relation of found hits.
165+
*/
166+
public function getTotalHitsRelation(): string
167+
{
168+
$data = $this->_response->getData();
169+
170+
return $data['hits']['total']['relation'] ?? 'eq';
171+
}
172+
163173
/**
164174
* Returns the max score of the results found.
165175
*

test/Elastica/QueryTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -572,13 +572,16 @@ public function testSetTrackTotalHits()
572572

573573
$resultSet = $index->search($query);
574574
$this->assertEquals(50, $resultSet->getTotalHits());
575+
$this->assertEquals('eq', $resultSet->getTotalHitsRelation());
575576

576577
$query->setTrackTotalHits(false);
577578
$resultSet = $index->search($query);
578579
$this->assertEquals(0, $resultSet->getTotalHits());
580+
$this->assertEquals('eq', $resultSet->getTotalHitsRelation());
579581

580582
$query->setTrackTotalHits(25);
581583
$resultSet = $index->search($query);
582584
$this->assertEquals(25, $resultSet->getTotalHits());
585+
$this->assertEquals('gte', $resultSet->getTotalHitsRelation());
583586
}
584587
}

test/Elastica/ResultSetTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function testGetters()
2727

2828
$this->assertInstanceOf(ResultSet::class, $resultSet);
2929
$this->assertEquals(3, $resultSet->getTotalHits());
30+
$this->assertEquals('eq', $resultSet->getTotalHitsRelation());
3031
$this->assertGreaterThan(0, $resultSet->getMaxScore());
3132
$this->assertNotTrue($resultSet->hasTimedOut());
3233
$this->assertNotTrue($resultSet->hasAggregations());

0 commit comments

Comments
 (0)