Skip to content

Commit e8525c1

Browse files
committed
Specify key or calculate hash from content
- fixes multiple querycollections in elasticquery
1 parent 03958f4 commit e8525c1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Query/QueryCollection.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ class QueryCollection implements LeafQueryInterface
2121
*/
2222
private $mustNotCollection;
2323

24+
/**
25+
* @var int|string|null
26+
*/
27+
private $key;
28+
2429

2530
public function __construct(
2631
?\Spameri\ElasticQuery\Query\MustCollection $mustCollection = NULL
2732
, ?\Spameri\ElasticQuery\Query\ShouldCollection $shouldCollection = NULL
2833
, ?\Spameri\ElasticQuery\Query\MustNotCollection $mustNotCollection = NULL
34+
, $key = NULL
2935
)
3036
{
3137
if ( ! $mustCollection) {
@@ -43,6 +49,7 @@ public function __construct(
4349
$this->mustCollection = $mustCollection;
4450
$this->shouldCollection = $shouldCollection;
4551
$this->mustNotCollection = $mustNotCollection;
52+
$this->key = $key;
4653
}
4754

4855

@@ -84,7 +91,11 @@ public function addShouldQuery(\Spameri\ElasticQuery\Query\LeafQueryInterface $l
8491

8592
public function key() : string
8693
{
87-
return '';
94+
if ($this->key) {
95+
return $this->key;
96+
}
97+
98+
return \md5(\serialize($this->toArray()));
8899
}
89100

90101

0 commit comments

Comments
 (0)