Skip to content
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

Weighting: Add ep_enable_do_weighting to check for request type and re-factor with apply_weighting() into do_weighting() #2857

Merged
merged 3 commits into from
Jun 30, 2022
Merged

Weighting: Add ep_enable_do_weighting to check for request type and re-factor with apply_weighting() into do_weighting() #2857

merged 3 commits into from
Jun 30, 2022

Conversation

rebeccahum
Copy link
Contributor

@rebeccahum rebeccahum commented Jun 23, 2022

Description of the Change

This PR does two things:

  1. Adds the filter ep_enable_do_weighting, which combines the logic of checking for an integrated request (that way one can customize it to their liking as well, if they wanted to change the integrated request types allowed)
  2. Re-factors the logic to apply weighting into its own function apply_weighting()

Alternate Designs

For point 2, it would be possible to just filter out the request types itself, but not sure if that's worth adding yet another filter on top of things already.

Possible Drawbacks

N/A

Verification Process

  1. Set up EP with search weighting added by UI (pick whatever values)
  2. Verify post weighting is still being added as expected on a front-end search for "bar"
  3. Add filter to only disable post weighting for searches of "foo":
// Enable weighting only for searches of "foo"
// Enable weighting only for searches of "foo"
add_filter( 'ep_enable_do_weighting', function( $enable_do_weighting, $weight_config, $args, $formatted_arg ) {
   $enable_do_weighting = ElasticPress\Utils\is_integrated_request( 'weighting', [ 'public', 'rest' ] ) && $args['s'] === 'foo';

   return $enable_do_weighting;
}, 10, 4 );

  1. Verify post weighting is no longer being added on a search query for "foo"

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Added: Adds ep_enable_do_weighting filter and re-factors with new function apply_weighting

Credits

Props @felipeelia @rebeccahum

@rebeccahum rebeccahum changed the title Weighting: Change ep_disable_do_weighting to check for request type and re-factor with apply_weighting() into do_weighting() Weighting: Add ep_enable_do_weighting to check for request type and re-factor with apply_weighting() into do_weighting() Jun 30, 2022
@felipeelia felipeelia added this to the 4.3.0 milestone Jun 30, 2022
@felipeelia felipeelia merged commit ad3a7a2 into 10up:develop Jun 30, 2022
@rebeccahum rebeccahum deleted the add/weighting_change_disable_weighting_filter branch June 30, 2022 19:28
rebeccahum added a commit to Automattic/ElasticPress that referenced this pull request Jun 30, 2022
rebeccahum added a commit to Automattic/ElasticPress that referenced this pull request Jun 30, 2022
rebeccahum added a commit to Automattic/ElasticPress that referenced this pull request Jun 30, 2022
@felipeelia felipeelia modified the milestones: 4.3.0, 4.2.2 Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants