-
Notifications
You must be signed in to change notification settings - Fork 1
Filters
Allows the buckets for an aggregation to be filtered before they are displayed, which can allow for removing certain items, or changing labels, or changing the sort order of buckets.
Usage
apply_filters( 'elasticsearch_extensions_aggregation_buckets', Bucket[] $buckets, Aggregation $aggregation )
Parameters
$buckets
(Elasticsearch_Extensions\Aggregations\Bucket[]) The array of buckets to filter.
$aggregation
(Elasticsearch_Extensions\Aggregations\Aggregation) The aggregation that the buckets are associated with.
Example
add_filter(
'elasticsearch_extensions_aggregation_buckets',
function( $buckets, $aggregation ) {
if ( 'taxonomy_author' === $aggregation->get_query_var() ) {
return array_values(
array_filter(
$buckets,
function( $bucket ) {
return 'cap-alley' !== $bucket->key;
}
)
);
} else {
return $buckets;
}
},
10,
2
);
Source
lib/aggregations/class-aggregation.php
Filters the Elasticsearch date format string used in the date_histogram
aggregation.
Usage
apply_filters( 'elasticsearch_extensions_aggregation_date_format', string $format, string $interval, string $aggregation, string $mapped_field )
Parameters
$format
(string) The format to use.
$interval
(string) The interval to aggregate (year, month, etc).
$aggregation
(string) The aggregation slug to use for grouping.
$mapped_field
(string) The mapped field to use for the date aggregation.
Example
add_filter(
'elasticsearch_extensions_aggregation_date_format',
function( $format, $interval, $aggregation, $mapped_field ) {
return 'month';
},
10,
4
);
Source
Allows the label for a date aggregation to be filtered. For example, can be used to convert "2022-04" to "April 2022".
Usage
apply_filters( 'elasticsearch_extensions_aggregation_date_label', string $label )
Parameters
$label
(string) The label to use.
Example
add_filter(
'elasticsearch_extensions_aggregation_date_label',
function( $label ) {
return date( 'F Y', strtotime( $label ) );
}
);
Source
lib/aggregations/class-post-date.php
Filters the text to be indexed in the search suggestions field for a post.
Usage
apply_filters( 'elasticsearch_extensions_post_search_suggestions_text', string $text, int $post_id );
Parameters
$text
(string) Text to index. Default post title.
$post_id
(int) Post ID.
Example
add_filter(
'elasticsearch_extensions_post_search_suggestions_text',
function ( $text, $post_id ) {
$seo_title = get_post_meta( $post_id, '_seo_title', true );
if ( $seo_title ) {
$text = $seo_title;
}
return $text;
},
10,
2
);
Source
lib/adapters/class-vip-enterprise-search.php
Allows the label field for a post type aggregation to be filtered. For example, this filter could be used to use the plural form of the label instead of the singular.
Usage
apply_filters( 'elasticsearch_extensions_aggregation_post_type_label', string $label )
Parameters
$label
(string) The slug of the label to use. See get_post_type_labels() for a full list of options.
Example
add_filter(
'elasticsearch_extensions_aggregation_post_type_label',
function( $label ) {
return 'name';
}
);
Source
lib/aggregations/class-post-type.php
Allows the selected query values for an aggregation to be filtered before they are used, which can allow for modifying the format of a value (for example, changing a date from YYYY-MM-DD
to ISO-8601 to be compatible with the custom date range aggregation).
Usage
apply_filters( 'elasticsearch_extensions_aggregation_query_values', string[] $query_values, Aggregation $aggregation )
Parameters
$query_values
(string[]) The array of selected query values to filter.
$aggregation
(Elasticsearch_Extensions\Aggregations\Aggregation) The aggregation that the query values are associated with.
Example
add_filter(
'elasticsearch_extensions_aggregation_query_values',
function( $query_values, $aggregation ) {
// Remove 'custom' from the relative date aggregation.
if ( 'relative_date' === $query_var ) {
return array_values(
array_filter(
$query_values,
function ( $query_value ) {
return 'custom' !== $query_value;
}
)
);
} else {
return $query_values;
}
},
10,
2
);
Source
lib/aggregations/class-aggregation.php
Filters the unmapped field name used in a taxonomy aggregation. Defaults to term_slug
, but can be changed to use the term ID, for example.
Usage
apply_filters( 'elasticsearch_extensions_aggregation_taxonomy_field', string $field, WP_Taxonomy $taxonomy )
Parameters
$field
(string) The field to aggregate.
$taxonomy
(WP_Taxonomy) The taxonomy for this aggregation.
Example
add_filter(
'elasticsearch_extensions_aggregation_taxonomy_field',
function( $field, $taxonomy ) {
return 'post_tag' === $taxonomy->name ? 'term_id' : $field;
},
10,
2
);
Source
lib/aggregations/class-taxonomy.php
Allows the size
property of a terms aggregation to be filtered. By default, Elasticsearch Extensions will return up to 1000 different terms on a terms aggregation, but this value can be increased for completeness or decreased for performance.
Usage
apply_filters( 'elasticsearch_extensions_aggregation_term_size', int $size, string $aggregation )
Parameters
$size
(int) The maximum number of terms to return. Defaults to 1000.
$aggregation
(string) The unique aggregation slug.
Example
add_filter(
'elasticsearch_extensions_aggregation_term_size',
function( $size, $aggregation ) {
return 'taxonomy_post_tag' === $aggregation ? 100 : $size;
},
10,
2
);
Source
Filter the field value factor for fields in the Phrase Matching multi_match
query.
Usage
apply_filters( 'elasticsearch_extensions_phrase_match_multimatch_fields', string[] $default_multi_match_fields )
Parameters
$default_multi_match_fields
(string[]) A list of string fields to search against. Defaults to the post title at 3x priority, the post excerpt at 2x, the post content, the post author's display name and terms that match the author's name.
Example
add_filter(
'elasticsearch_extensions_phrase_match_multimatch_fields',
function( $default_multi_match_fields ) {
$default_multi_match_fields = [
'post_title^5',
'my.cool.custom-field^4',
'post_excerpt^2',
'post_content^2',
'post_author.display_name',
'terms.author.name',
];
return $default_multi_match_fields;
},
10,
2
);
Source
Filter the Elasticsearch fields to search in custom DSL written by the DSL class. The fields should already be mapped (use $dsl->map_field()
, $dsl->map_tax_field()
, or $dsl->map_meta_field()
to map a field).
Usage
apply_filters( 'elasticsearch_extensions_searchable_fields', string[] $fields, DSL $dsl )
Parameters
$fields
(string[]) A list of string fields to search against. Defaults to the post title at 3x priority, the post excerpt, the post content, the post author's display name, and the attachment's alt text (for attachments).
$dsl
(Elasticsearch_Extensions\DSL) The DSL object, which provides map_field
functionality.
Example
add_filter(
'elasticsearch_extensions_searchable_fields',
function( $fields, $dsl ) {
$fields[] = $dsl->map_tax_field( 'category', 'term_slug' );
return $fields;
},
10,
2
);
Source
Filters the list of searchable post types. Defaults to the list of searchable post type slugs from the adapter.
Usage
apply_filters( 'elasticsearch_extensions_searchable_post_types', string[] $post_types )
Parameters
$post_types
(string[]) An array of post type slugs to include in search.
Example
add_filter(
'elasticsearch_extensions_searchable_post_types',
function( $post_types ) {
$post_types[] = 'my-private-but-indexed-post-type';
return $post_types;
}
);
Source