Skip to content

Commit 18f0533

Browse files
committed
Add advanced aggregation, filter, and DSL output tests
Introduces comprehensive test coverage for advanced aggregations, filter context queries, and DSL output inspection. Adds new test files for aggregation (AggregationAdvancedTest), filter context (FilterWhereTest), and DSL output (DslOutputTest). Implements a trait (TestsWithIdStrategies) for conditional ID generation in tests. Updates Eloquent and Query builders to support time-based where clauses and new query methods. Removes legacy test models and test cases related to ID strategies, consolidating model usage.
1 parent 996fd54 commit 18f0533

74 files changed

Lines changed: 2631 additions & 5062 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.env
22
.env.*
3+
.cl*
34

45
#composer
56
vendor

_ide_helper.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/**
4+
* IDE Helper for Laravel version compatibility traits.
5+
*
6+
* This file helps IDEs understand the runtime trait switching.
7+
* Points to v12 implementations as the canonical reference.
8+
*
9+
* @see /src/Laravel/Compatibility/
10+
*/
11+
12+
namespace PDPhilip\Elasticsearch\Laravel\Compatibility\Schema {
13+
14+
use PDPhilip\Elasticsearch\Laravel\v12\Schema\BlueprintCompatibility as BlueprintCompat12;
15+
use PDPhilip\Elasticsearch\Laravel\v12\Schema\BuilderCompatibility as BuilderCompat12;
16+
use PDPhilip\Elasticsearch\Laravel\v12\Schema\GrammarCompatibility as GrammarCompat12;
17+
18+
trait BlueprintCompatibility
19+
{
20+
use BlueprintCompat12;
21+
}
22+
23+
trait BuilderCompatibility
24+
{
25+
use BuilderCompat12;
26+
}
27+
28+
trait GrammarCompatibility
29+
{
30+
use GrammarCompat12;
31+
}
32+
}
33+
34+
namespace PDPhilip\Elasticsearch\Laravel\Compatibility\Connection {
35+
36+
use PDPhilip\Elasticsearch\Laravel\v12\Connection\ConnectionCompatibility as ConnectionCompat12;
37+
38+
trait ConnectionCompatibility
39+
{
40+
use ConnectionCompat12;
41+
}
42+
}

src/Eloquent/Builder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Builder extends BaseEloquentBuilder
6666
'rawvalue',
6767
'tosql',
6868
'torawsql',
69+
'tocompiledquery',
6970

7071
// ES
7172
'todsl',

src/Eloquent/Docs/ModelDocs.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
* @method static $this orderByNestedDesc($column, $direction = 'asc', $mode = null)
180180
*-----------------------------------
181181
* @method static $this withSort($column, $key, $value)
182+
* @method static $this withRefresh($type)
182183
*===========================================
183184
* Executors
184185
*===========================================
@@ -189,8 +190,9 @@
189190
* @method static array getModels($columns = ['*'])
190191
* @method static ElasticCollection get($columns = ['*'])
191192
* @method static ElasticCollection insert($values, $returnData = null)
192-
* @method static self createOnly()
193-
* @method static self createOrFail(array $attributes)
193+
* @method static $this create(array $attributes)
194+
* @method static $this createOnly()
195+
* @method static $this createOrFail(array $attributes)
194196
*-----------------------------------
195197
* @method static array toDsl($columns = ['*'])
196198
* @method static array toSql($columns = ['*'])

src/Query/Builder.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,11 @@ public function orWhereDate($column, $operator, $value = null, array $options =
448448
*/
449449
protected function addDateBasedWhere($type, $column, $operator, $value, $boolean = 'and', array $options = [])
450450
{
451+
// Handle Time type specially since it compares multiple components
452+
if ($type === 'Time') {
453+
return $this->addTimeBasedWhere($column, $operator, $value, $boolean, $options);
454+
}
455+
451456
switch ($type) {
452457
case 'Year':
453458
$dateType = 'year';
@@ -480,6 +485,63 @@ protected function addDateBasedWhere($type, $column, $operator, $value, $boolean
480485
return $this;
481486
}
482487

488+
/**
489+
* Add a time-based where clause (whereTime) to the query.
490+
*
491+
* Handles time comparisons with various formats: HH:mm:ss, HH:mm, or HH
492+
*
493+
* @param string $column
494+
* @param string $operator
495+
* @param string $value
496+
* @param string $boolean
497+
* @param array $options
498+
* @return $this
499+
*/
500+
protected function addTimeBasedWhere($column, $operator, $value, $boolean = 'and', array $options = [])
501+
{
502+
$type = 'Script';
503+
504+
$operator = $operator == '=' ? '==' : $operator;
505+
$operator = $operator == '<>' ? '!=' : $operator;
506+
507+
// Parse time value - can be HH:mm:ss, HH:mm, or just HH
508+
$timeParts = explode(':', $value);
509+
$hour = (int) ($timeParts[0] ?? 0);
510+
$minute = isset($timeParts[1]) ? (int) $timeParts[1] : null;
511+
$second = isset($timeParts[2]) ? (int) $timeParts[2] : null;
512+
513+
// Build time comparison - convert to seconds since midnight for easier comparison
514+
$docTimeExpr = "doc.{$column}.value.hour * 3600 + doc.{$column}.value.minute * 60 + doc.{$column}.value.second";
515+
516+
// Build the target time value in seconds since midnight
517+
$targetSeconds = $hour * 3600;
518+
if ($minute !== null) {
519+
$targetSeconds += $minute * 60;
520+
if ($second !== null) {
521+
$targetSeconds += $second;
522+
}
523+
}
524+
525+
// For partial time matches (HH:mm or just HH), adjust the comparison
526+
if ($second === null && $minute === null) {
527+
// Just hour specified - compare only the hour part
528+
$docTimeExpr = "doc.{$column}.value.hour";
529+
$targetSeconds = $hour;
530+
} elseif ($second === null) {
531+
// Hour and minute specified - compare hour*60+minute
532+
$docTimeExpr = "doc.{$column}.value.hour * 60 + doc.{$column}.value.minute";
533+
$targetSeconds = $hour * 60 + $minute;
534+
}
535+
536+
$script = "doc.{$column}.size() > 0 && doc.{$column}.value != null && {$docTimeExpr} {$operator} params.value";
537+
538+
$options['params'] = ['value' => $targetSeconds];
539+
540+
$this->wheres[] = compact('script', 'options', 'type', 'boolean');
541+
542+
return $this;
543+
}
544+
483545
/**
484546
* {@inheritdoc}
485547
*/

0 commit comments

Comments
 (0)