-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Post Meta and Generic Term Aggregations #56
Changes from all commits
3919d10
ea0fa1f
a58f909
a8ad346
1bd2e92
1edff69
b7176b4
ccaad04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* Elasticsearch Extensions: Post_Meta Aggregation Class | ||
* | ||
* @package Elasticsearch_Extensions | ||
*/ | ||
|
||
namespace Elasticsearch_Extensions\Aggregations; | ||
|
||
use Elasticsearch_Extensions\DSL; | ||
|
||
/** | ||
* Post_Meta aggregation class. Responsible for building the DSL and requests | ||
* for aggregations as well as holding the result of the aggregation after a | ||
* response was received. | ||
*/ | ||
class Post_Meta extends Term { | ||
|
||
/** | ||
* The postmeta key this aggregation is associated with. | ||
* | ||
* @var string | ||
*/ | ||
protected string $meta_key; | ||
|
||
/** | ||
* Configure the Post_Meta aggregation. | ||
* | ||
* @param DSL $dsl The DSL object, initialized with the map from the adapter. | ||
* @param array $args Optional. Additional arguments to pass to the aggregation. | ||
*/ | ||
public function __construct( DSL $dsl, array $args ) { | ||
if ( ! empty( $args['meta_key'] ) ) { | ||
$this->label = ucwords( str_replace( [ '-', '_' ], ' ', $args['meta_key'] ) ); | ||
$this->meta_key = $args['meta_key']; | ||
$this->query_var = 'post_meta_' . $args['meta_key']; | ||
$this->term_field = $dsl->map_meta_field( $args['meta_key'], $args['data_type'] ?? '' ); | ||
unset( $args['meta_key'] ); | ||
} | ||
|
||
parent::__construct( $dsl, $args ); | ||
} | ||
} | ||
Comment on lines
+1
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The public function __construct( DSL $dsl, array $args ) {
+ if ( empty( $args['meta_key'] ) ) {
+ throw new \InvalidArgumentException( 'The meta_key argument is required and cannot be empty.' );
+ }
if ( ! empty( $args['meta_key'] ) ) {
$this->label = ucwords( str_replace( [ '-', '_' ], ' ', $args['meta_key'] ) );
$this->meta_key = $args['meta_key'];
$this->query_var = 'post_meta_' . $args['meta_key'];
$this->term_field = $dsl->map_meta_field( $args['meta_key'], $args['data_type'] ?? '' );
unset( $args['meta_key'] );
}
parent::__construct( $dsl, $args );
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's important to expand the phpdoc here to document all the arguments the aggregation accepts (comment applies throughout)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, will do