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

Add WP CLI commands for saving and deleting the Instant Results template. #3150

Closed
JakePT opened this issue Nov 23, 2022 · 2 comments · Fixed by #3216
Closed

Add WP CLI commands for saving and deleting the Instant Results template. #3150

JakePT opened this issue Nov 23, 2022 · 2 comments · Fixed by #3216
Assignees
Labels
enhancement module:instant-results Issues related to the Instant Results functionality
Milestone

Comments

@JakePT
Copy link
Contributor

JakePT commented Nov 23, 2022

Is your enhancement related to a problem? Please describe.
The Instant Results feature requires a search template be saved to ElasticPress.io to help power the API. This template is saved when the feature is activated, on sync, or on a change to the weighting settings. It is deleted when the feature is deactivated.

There is currently no direct way to manually save and delete this template outside of the UI except for running a sync. Since these specific UIs are unavailable per-site when in network mode the only way to save this template is to run a sync. For simplicity and clarity a specific command for saving the template would be preferable to the sync command.

Describe the solution you'd like
Add WP CLI commands for getting, saving, and deleting the search template from ElasticPress.io, eg.

  • wp elasticpress get-search-template
  • wp elasticpress put-search-template
  • wp elasticpress delete-search-template

Methods for each of these already exist on the InstantResults feature class, they just need to be added as commands.

  • new InstantResults\InstantResults()->epio_get_search_template()
  • new InstantResults\InstantResults()->epio_save_search_template()
  • new InstantResults\InstantResults()->epio_delete_search_template()
@JakePT JakePT added enhancement module:instant-results Issues related to the Instant Results functionality labels Nov 23, 2022
@oscarssanchez oscarssanchez self-assigned this Nov 29, 2022
@oscarssanchez
Copy link
Contributor

oscarssanchez commented Nov 29, 2022

Couple questions I have:

  • Should we have a command also for getting the "local" version of the template? epio_get_search_template() gets the version that's hosted in EPIO. Not sure if it would be handy for let's say, compare what you generate locally vs saved version.
  • epio_save_search_template() and epio_delete_search_template() returns void, so the WP CLI command would only run that method, but it doesn't know if saving/deleting the template was successful or not. I think this is also an improvement we could make in general. Right now it seems there's no way to know if saving the search template was successful or not. Having it returning the response can help with displaying a notice in WP Admin as well

@oscarssanchez
Copy link
Contributor

Another thing I think we can address is better describe the methods, for example

/**
 * Save the search template to ElasticPress.io.
 *
 * @return void
 */
public function epio_save_search_template() {
	$endpoint = $this->get_template_endpoint();
	$template = $this->get_search_template();

	Elasticsearch::factory()->remote_request(
		$endpoint,
		[
			'blocking' => false,
			'body'     => $template,
			'method'   => 'PUT',
		]
	);

	/**
	 * Fires after the request is sent the search template API endpoint.
	 *
	 * @since 4.0.0
	 * @hook ep_instant_results_template_saved
	 * @param {string} $template The search template (JSON).
	 * @param {string} $index Index name.
	 */
	do_action( 'ep_instant_results_template_saved', $template, $this->index );
}

This method doc and name imply the template is saved to EPIO and while that is true it can be confusing for people who are not using EPIO. This method seems to achieve the same for both

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement module:instant-results Issues related to the Instant Results functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants