REST API: Support exact search in the REST API posts endpoint.

This changeset adds support for a new `search_semantics` enum query parameter that can be passed alongside the `search` string parameter. At this point, it only supports "exact" as possible value, but an enum is used for forward compatibility with potential enhancements like "sentence" search support. If `search_semantics=exact` is passed, it will look for an exact match rather than do a full text search, which for some use-cases is more appropriate and more performant.

Props mehulkaklotar, timothyblynjacobs, jimmyh61, ironprogrammer, johnregan3, mukesh27, costdev.
Fixes #56350.

Built from https://develop.svn.wordpress.org/trunk@59034


git-svn-id: http://core.svn.wordpress.org/trunk@58430 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Felix Arntz 2024-09-17 21:58:14 +00:00
parent 90d4f10e74
commit 1da67e31b5
2 changed files with 14 additions and 1 deletions

View File

@ -337,6 +337,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
}
}
if (
isset( $registered['search_semantics'], $request['search_semantics'] )
&& 'exact' === $request['search_semantics']
) {
$args['exact'] = true;
}
$args = $this->prepare_tax_query( $args, $request );
// Force the post_type argument, since it's not a user input variable.
@ -2886,6 +2893,12 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
);
}
$query_params['search_semantics'] = array(
'description' => __( 'How to interpret the search input.' ),
'type' => 'string',
'enum' => array( 'exact' ),
);
$query_params['offset'] = array(
'description' => __( 'Offset the result set by a specific number of items.' ),
'type' => 'integer',

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.7-alpha-59033';
$wp_version = '6.7-alpha-59034';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.