Skip to content

Commit

Permalink
Hook docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tlovett1 committed Nov 14, 2019
1 parent 4efad65 commit c33434d
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions includes/classes/Feature/Search/Weighting.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public function get_weightable_fields_for_post_type( $post_type ) {
}
}

/**
* Filter weighting fields for a post type
*
* @hook ep_weighting_fields_for_post_type
* @param {array} $fields Current weighting fields
* @param {string} $post_type Current post type
* @return {array} New fields
*/
return apply_filters( 'ep_weighting_fields_for_post_type', $fields, $post_type );
}

Expand Down Expand Up @@ -133,6 +141,14 @@ public function get_post_type_default_settings( $post_type ) {
}
}

/**
* Filter weighting defaults for post type
*
* @hook ep_weighting_default_post_type_weights
* @param {array} $post_type_defaults Current weighting defaults
* @param {string} $post_type Current post type
* @return {array} New defaults
*/
return apply_filters( 'ep_weighting_default_post_type_weights', $post_type_defaults, $post_type );
}

Expand All @@ -142,6 +158,13 @@ public function get_post_type_default_settings( $post_type ) {
* @return array
*/
public function get_weighting_configuration() {
/**
* Filter weighting configuration
*
* @hook ep_weighting_configuration
* @param {array} $config Current configuration
* @return {array} New configuration
*/
return apply_filters( 'ep_weighting_configuration', get_option( 'elasticpress_weighting', [] ) );
}

Expand Down Expand Up @@ -414,8 +437,25 @@ public function recursively_inject_weights_to_fields( &$fieldset, $weights ) {
*/
public function post_type_has_fields( $post_type, $args = [] ) {
// define keys which are irrelevant for this consideration

/**
* Filter fields considered in weighting
*
* @hook ep_weighting_ignore_fields_in_consideration
* @param {array} $fields Current fields
* @return {array} New fields
*/
$ignore_keys = apply_filters( 'ep_weighting_ignore_fields_in_consideration', [ 'terms.ep_custom_result.name' => true ] );
$weight_config = $this->get_weighting_configuration();

/**
* Filter weighting configuration for search
*
* @hook ep_weighting_configuration_for_search
* @param {array} $weight_config Current weight config
* @param {array} $args WP Query arguments
* @return {array} New configutation
*/
$weight_config = apply_filters( 'ep_weighting_configuration_for_search', $weight_config, $args );

if ( ! isset( $weight_config[ $post_type ] ) ) {
Expand Down Expand Up @@ -454,6 +494,14 @@ public function do_weighting( $formatted_args, $args ) {

$weight_config = $this->get_weighting_configuration();

/**
* Filter weighting configuration for search
*
* @hook ep_weighting_configuration_for_search
* @param {array} $weight_config Current weight config
* @param {array} $args WP Query arguments
* @return {array} New configutation
*/
$weight_config = apply_filters( 'ep_weighting_configuration_for_search', $weight_config, $args );

if ( ! is_admin() && ! empty( $args['s'] ) ) {
Expand Down Expand Up @@ -497,6 +545,15 @@ public function do_weighting( $formatted_args, $args ) {
}
}

/**
* Filter weighting query for a post type
*
* @hook ep_weighted_query_for_post_type
* @param {array} $query Weighting query
* @param {string} $post_type Post type
* @param {array} $args WP Query arguments
* @return {array} New query
*/
$new_query['bool']['should'][] = apply_filters(
'ep_weighted_query_for_post_type',
[
Expand Down

0 comments on commit c33434d

Please sign in to comment.