From 149f87e1bfb64af1e2d7856539f6a57bcad0e9a7 Mon Sep 17 00:00:00 2001 From: Mehul Kaklotar Date: Thu, 24 Nov 2022 18:49:43 +0530 Subject: [PATCH 01/11] REST API: add exact search support in api --- .../class-wp-rest-posts-controller.php | 6 +++ .../rest-api/rest-attachments-controller.php | 1 + .../tests/rest-api/rest-pages-controller.php | 1 + .../tests/rest-api/rest-posts-controller.php | 43 +++++++++++++++++++ tests/qunit/fixtures/wp-api-generated.js | 30 +++++++++++++ 5 files changed, 81 insertions(+) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 571a2fd5f4bcf..91ea83e78be95 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -251,6 +251,7 @@ public function get_items( $request ) { 'search' => 's', 'slug' => 'post_name__in', 'status' => 'post_status', + 'exact_search' => 'exact', ); /* @@ -2834,6 +2835,11 @@ public function get_collection_params() { ); } + $query_params['exact_search'] = array( + 'description' => __( 'Use exact search instead of full search.' ), + 'type' => 'boolean', + ); + $query_params['offset'] = array( 'description' => __( 'Offset the result set by a specific number of items.' ), 'type' => 'integer', diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index 27519610e86f3..c46e584555137 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -216,6 +216,7 @@ public function test_registered_query_params() { 'author_exclude', 'before', 'context', + 'exact_search', 'exclude', 'include', 'media_type', diff --git a/tests/phpunit/tests/rest-api/rest-pages-controller.php b/tests/phpunit/tests/rest-api/rest-pages-controller.php index a6a9cfa3f46d5..1151c09e53cc6 100644 --- a/tests/phpunit/tests/rest-api/rest-pages-controller.php +++ b/tests/phpunit/tests/rest-api/rest-pages-controller.php @@ -73,6 +73,7 @@ public function test_registered_query_params() { 'author_exclude', 'before', 'context', + 'exact_search', 'exclude', 'include', 'menu_order', diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index b2a5512fbab63..0285457f13832 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -194,6 +194,7 @@ public function test_registered_query_params() { 'categories', 'categories_exclude', 'context', + 'exact_search', 'exclude', 'include', 'modified_after', @@ -749,6 +750,48 @@ public function test_get_items_status_without_permissions() { } } + /** + * @ticket 56350 + */ + public function test_get_items_exact_search() { + + self::factory()->post->create( + array( + 'post_title' => 'Rye', + 'post_content' => 'This is a post about Rye Bread', + 'post_status' => 'publish', + ) + ); + + self::factory()->post->create( + array( + 'post_title' => 'Types of Bread', + 'post_content' => 'Types of bread are White and Rye Bread', + 'post_status' => 'publish', + ) + ); + + $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); + + // General search. + $request->set_param( 'search', 'Rye' ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); + $this->assertCount( 2, $data, 'Querying the API without exact_search should return all posts containing the search keyword' ); + + // Exact search using same search param. + $request->set_param( 'exact_search', true ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); + $this->assertCount( 1, $data, 'Querying the API with exact_search should return posts matching the search keyword' ); + + // Note that "exact_search" is still true. + $request->set_param( 'search', 'Rye Bread' ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); + $this->assertCount( 0, $data, 'Querying the API with exact_search should return posts matching the search keyword' ); + } + public function test_get_items_order_and_orderby() { self::factory()->post->create( array( diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 896322ed48dfc..b31f3b1d8e1f4 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -362,6 +362,11 @@ mockedApiResponse.Schema = { "default": [], "required": false }, + "exact_search": { + "description": "Use exact search instead of full search.", + "type": "boolean", + "required": false + }, "offset": { "description": "Offset the result set by a specific number of items.", "type": "integer", @@ -1700,6 +1705,11 @@ mockedApiResponse.Schema = { "type": "integer", "required": false }, + "exact_search": { + "description": "Use exact search instead of full search.", + "type": "boolean", + "required": false + }, "offset": { "description": "Offset the result set by a specific number of items.", "type": "integer", @@ -2782,6 +2792,11 @@ mockedApiResponse.Schema = { "default": [], "required": false }, + "exact_search": { + "description": "Use exact search instead of full search.", + "type": "boolean", + "required": false + }, "offset": { "description": "Offset the result set by a specific number of items.", "type": "integer", @@ -3509,6 +3524,11 @@ mockedApiResponse.Schema = { "default": [], "required": false }, + "exact_search": { + "description": "Use exact search instead of full search.", + "type": "boolean", + "required": false + }, "offset": { "description": "Offset the result set by a specific number of items.", "type": "integer", @@ -4306,6 +4326,11 @@ mockedApiResponse.Schema = { "default": [], "required": false }, + "exact_search": { + "description": "Use exact search instead of full search.", + "type": "boolean", + "required": false + }, "offset": { "description": "Offset the result set by a specific number of items.", "type": "integer", @@ -6457,6 +6482,11 @@ mockedApiResponse.Schema = { "default": [], "required": false }, + "exact_search": { + "description": "Use exact search instead of full search.", + "type": "boolean", + "required": false + }, "offset": { "description": "Offset the result set by a specific number of items.", "type": "integer", From 0928d17b236c5f0e61c14ebd6a6f6b302a6611da Mon Sep 17 00:00:00 2001 From: Mehul Kaklotar Date: Mon, 28 Nov 2022 11:33:55 +0530 Subject: [PATCH 02/11] REST API: data provider for tests changes --- .../tests/rest-api/rest-posts-controller.php | 82 ++++++++++++------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 0285457f13832..d09ece8902964 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -75,6 +75,23 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { ) ); } + + // Set up posts for the exact search tests. + self::$post_ids[] = $factory->post->create( + array( + 'post_title' => 'Rye', + 'post_content' => 'This is a post about Rye Bread', + 'post_status' => 'publish', + ) + ); + + self::$post_ids[] = $factory->post->create( + array( + 'post_title' => 'Types of Bread', + 'post_content' => 'Types of bread are White and Rye Bread', + 'post_status' => 'publish', + ) + ); } public static function wpTearDownAfterClass() { @@ -751,45 +768,48 @@ public function test_get_items_status_without_permissions() { } /** - * @ticket 56350 + * Data provider for test_get_items_exact_search(). + * + * @return array[] */ - public function test_get_items_exact_search() { - - self::factory()->post->create( - array( - 'post_title' => 'Rye', - 'post_content' => 'This is a post about Rye Bread', - 'post_status' => 'publish', - ) - ); - - self::factory()->post->create( - array( - 'post_title' => 'Types of Bread', - 'post_content' => 'Types of bread are White and Rye Bread', - 'post_status' => 'publish', - ) + public function data_get_items_exact_search() { + return array( + 'general search, one exact match and one partial match' => array( + 'search_term' => 'Rye', + 'exact_search' => false, + 'expected' => 2, + ), + 'exact search, one exact match and one partial match' => array( + 'search_term' => 'Rye', + 'exact_search' => true, + 'expected' => 1, + ), + 'exact search, no match and one partial match' => array( + 'search_term' => 'Rye Bread', + 'exact_search' => true, + 'expected' => 0, + ), ); + } + /** + * @ticket 56350 + * + * @dataProvider data_get_items_exact_search + * + * @param string $search_term The search term. + * @param bool $exact_search Whether the search is an exact or general search. + * @param int $expected The expected number of matching posts. + */ + public function test_get_items_exact_search( $search_term, $exact_search, $expected ) { $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); - // General search. - $request->set_param( 'search', 'Rye' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - $this->assertCount( 2, $data, 'Querying the API without exact_search should return all posts containing the search keyword' ); + $request->set_param( 'search', $search_term ); + $request->set_param( 'exact_search', $exact_search ); - // Exact search using same search param. - $request->set_param( 'exact_search', true ); $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - $this->assertCount( 1, $data, 'Querying the API with exact_search should return posts matching the search keyword' ); - // Note that "exact_search" is still true. - $request->set_param( 'search', 'Rye Bread' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - $this->assertCount( 0, $data, 'Querying the API with exact_search should return posts matching the search keyword' ); + $this->assertCount( $expected, $response->get_data() ); } public function test_get_items_order_and_orderby() { From c26114d7687a33ae1658ae93aae568dc97563a3f Mon Sep 17 00:00:00 2001 From: Mehul Kaklotar Date: Mon, 28 Nov 2022 11:39:58 +0530 Subject: [PATCH 03/11] REST API: data provider for tests changes lint fixes --- tests/phpunit/tests/rest-api/rest-posts-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index d09ece8902964..bc07ac33ec5c0 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -779,12 +779,12 @@ public function data_get_items_exact_search() { 'exact_search' => false, 'expected' => 2, ), - 'exact search, one exact match and one partial match' => array( + 'exact search, one exact match and one partial match' => array( 'search_term' => 'Rye', 'exact_search' => true, 'expected' => 1, ), - 'exact search, no match and one partial match' => array( + 'exact search, no match and one partial match' => array( 'search_term' => 'Rye Bread', 'exact_search' => true, 'expected' => 0, From fbae724f2e88f8eb5d58f3c79604d76fb667a9f0 Mon Sep 17 00:00:00 2001 From: Mehul Kaklotar Date: Mon, 28 Nov 2022 12:46:39 +0530 Subject: [PATCH 04/11] REST API: data provider for tests changes test fixes --- .../tests/rest-api/rest-posts-controller.php | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index bc07ac33ec5c0..e7b408b584a74 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -75,23 +75,6 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { ) ); } - - // Set up posts for the exact search tests. - self::$post_ids[] = $factory->post->create( - array( - 'post_title' => 'Rye', - 'post_content' => 'This is a post about Rye Bread', - 'post_status' => 'publish', - ) - ); - - self::$post_ids[] = $factory->post->create( - array( - 'post_title' => 'Types of Bread', - 'post_content' => 'Types of bread are White and Rye Bread', - 'post_status' => 'publish', - ) - ); } public static function wpTearDownAfterClass() { @@ -802,13 +785,24 @@ public function data_get_items_exact_search() { * @param int $expected The expected number of matching posts. */ public function test_get_items_exact_search( $search_term, $exact_search, $expected ) { - $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); + self::factory()->post->create( + array( + 'post_title' => 'Rye', + 'post_content' => 'This is a post about Rye Bread', + ) + ); + self::factory()->post->create( + array( + 'post_title' => 'Types of Bread', + 'post_content' => 'Types of bread are White and Rye Bread', + ) + ); + + $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); $request->set_param( 'search', $search_term ); $request->set_param( 'exact_search', $exact_search ); - $response = rest_get_server()->dispatch( $request ); - $this->assertCount( $expected, $response->get_data() ); } From e0306483f66d568b8e3466fbcd96fb30751b6c89 Mon Sep 17 00:00:00 2001 From: Mehul Kaklotar Date: Tue, 29 Nov 2022 23:26:00 +0530 Subject: [PATCH 05/11] REST API: change placement of data provider for tests --- .../tests/rest-api/rest-posts-controller.php | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index e7b408b584a74..4f304fff61068 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -750,31 +750,6 @@ public function test_get_items_status_without_permissions() { } } - /** - * Data provider for test_get_items_exact_search(). - * - * @return array[] - */ - public function data_get_items_exact_search() { - return array( - 'general search, one exact match and one partial match' => array( - 'search_term' => 'Rye', - 'exact_search' => false, - 'expected' => 2, - ), - 'exact search, one exact match and one partial match' => array( - 'search_term' => 'Rye', - 'exact_search' => true, - 'expected' => 1, - ), - 'exact search, no match and one partial match' => array( - 'search_term' => 'Rye Bread', - 'exact_search' => true, - 'expected' => 0, - ), - ); - } - /** * @ticket 56350 * @@ -806,6 +781,31 @@ public function test_get_items_exact_search( $search_term, $exact_search, $expec $this->assertCount( $expected, $response->get_data() ); } + /** + * Data provider for test_get_items_exact_search(). + * + * @return array[] + */ + public function data_get_items_exact_search() { + return array( + 'general search, one exact match and one partial match' => array( + 'search_term' => 'Rye', + 'exact_search' => false, + 'expected' => 2, + ), + 'exact search, one exact match and one partial match' => array( + 'search_term' => 'Rye', + 'exact_search' => true, + 'expected' => 1, + ), + 'exact search, no match and one partial match' => array( + 'search_term' => 'Rye Bread', + 'exact_search' => true, + 'expected' => 0, + ), + ); + } + public function test_get_items_order_and_orderby() { self::factory()->post->create( array( From 6085f441f0b947b55c5e984e48897400a70d8da3 Mon Sep 17 00:00:00 2001 From: Mehul Kaklotar Date: Tue, 6 Dec 2022 16:36:39 +0530 Subject: [PATCH 06/11] REST API: placement of exact search in parameter mappings fixed --- .../rest-api/endpoints/class-wp-rest-posts-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index a02a692c4ba43..ab9e3b28b5aea 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -239,6 +239,7 @@ public function get_items( $request ) { $parameter_mappings = array( 'author' => 'author__in', 'author_exclude' => 'author__not_in', + 'exact_search' => 'exact', 'exclude' => 'post__not_in', 'include' => 'post__in', 'menu_order' => 'menu_order', @@ -251,7 +252,6 @@ public function get_items( $request ) { 'search' => 's', 'slug' => 'post_name__in', 'status' => 'post_status', - 'exact_search' => 'exact', ); /* From 22b3c3775f5522251532f831f773ea7cd814c9fb Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 17 Sep 2024 10:27:35 -0700 Subject: [PATCH 07/11] Update wp-api-generated.js. --- tests/qunit/fixtures/wp-api-generated.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 914733989a66e..4d7ce1b99f2ef 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -7842,6 +7842,11 @@ mockedApiResponse.Schema = { "default": [], "required": false }, + "exact_search": { + "description": "Use exact search instead of full search.", + "type": "boolean", + "required": false + }, "offset": { "description": "Offset the result set by a specific number of items.", "type": "integer", @@ -8047,6 +8052,11 @@ mockedApiResponse.Schema = { "default": [], "required": false }, + "exact_search": { + "description": "Use exact search instead of full search.", + "type": "boolean", + "required": false + }, "offset": { "description": "Offset the result set by a specific number of items.", "type": "integer", From 808c1f872982f4bcfe5f968a6c61aef508c8d6d5 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 17 Sep 2024 10:30:36 -0700 Subject: [PATCH 08/11] Use array syntax to set REST params. Co-authored-by: Timothy Jacobs --- tests/phpunit/tests/rest-api/rest-posts-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 3a466106c2f22..d8a383cb54563 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -791,8 +791,8 @@ public function test_get_items_exact_search( $search_term, $exact_search, $expec ); $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); - $request->set_param( 'search', $search_term ); - $request->set_param( 'exact_search', $exact_search ); + $request['search'] = $search_term; + $request['exact_search'] = $exact_search; $response = rest_get_server()->dispatch( $request ); $this->assertCount( $expected, $response->get_data() ); } From 95db6ff316dfaf5fed2251984d3c5b67a6ec822d Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 17 Sep 2024 10:32:09 -0700 Subject: [PATCH 09/11] Fix indentation. --- tests/phpunit/tests/rest-api/rest-posts-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index d8a383cb54563..85a574ab07127 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -790,8 +790,8 @@ public function test_get_items_exact_search( $search_term, $exact_search, $expec ) ); - $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); - $request['search'] = $search_term; + $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); + $request['search'] = $search_term; $request['exact_search'] = $exact_search; $response = rest_get_server()->dispatch( $request ); $this->assertCount( $expected, $response->get_data() ); From 9bc728724ff6ea44677d23634da7642d574c9d9b Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 17 Sep 2024 10:56:37 -0700 Subject: [PATCH 10/11] Fix indentation. --- tests/phpunit/tests/rest-api/rest-posts-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 85a574ab07127..26201a21fce08 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -793,7 +793,7 @@ public function test_get_items_exact_search( $search_term, $exact_search, $expec $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); $request['search'] = $search_term; $request['exact_search'] = $exact_search; - $response = rest_get_server()->dispatch( $request ); + $response = rest_get_server()->dispatch( $request ); $this->assertCount( $expected, $response->get_data() ); } From 15ee6825f31f62c61fe4b148e85c81b1988ff4a7 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 17 Sep 2024 13:45:42 -0700 Subject: [PATCH 11/11] Use search_semantics enum parameter instead of exact_search boolean parameter. --- .../class-wp-rest-posts-controller.php | 15 ++-- .../rest-api/rest-attachments-controller.php | 2 +- .../tests/rest-api/rest-pages-controller.php | 2 +- .../tests/rest-api/rest-posts-controller.php | 12 ++-- tests/qunit/fixtures/wp-api-generated.js | 72 ++++++++++++------- 5 files changed, 68 insertions(+), 35 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 28750c47424bd..11bc499fc6720 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -245,7 +245,6 @@ public function get_items( $request ) { $parameter_mappings = array( 'author' => 'author__in', 'author_exclude' => 'author__not_in', - 'exact_search' => 'exact', 'exclude' => 'post__not_in', 'include' => 'post__in', 'menu_order' => 'menu_order', @@ -338,6 +337,13 @@ public function get_items( $request ) { } } + 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. @@ -2887,9 +2893,10 @@ public function get_collection_params() { ); } - $query_params['exact_search'] = array( - 'description' => __( 'Use exact search instead of full search.' ), - 'type' => 'boolean', + $query_params['search_semantics'] = array( + 'description' => __( 'How to interpret the search input.' ), + 'type' => 'string', + 'enum' => array( 'exact' ), ); $query_params['offset'] = array( diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index 500c4ef20201d..55ea686d22f25 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -214,7 +214,6 @@ public function test_registered_query_params() { 'author_exclude', 'before', 'context', - 'exact_search', 'exclude', 'include', 'media_type', @@ -230,6 +229,7 @@ public function test_registered_query_params() { 'per_page', 'search', 'search_columns', + 'search_semantics', 'slug', 'status', ), diff --git a/tests/phpunit/tests/rest-api/rest-pages-controller.php b/tests/phpunit/tests/rest-api/rest-pages-controller.php index a5a613b897ee2..9717a7fcda1c6 100644 --- a/tests/phpunit/tests/rest-api/rest-pages-controller.php +++ b/tests/phpunit/tests/rest-api/rest-pages-controller.php @@ -71,7 +71,6 @@ public function test_registered_query_params() { 'author_exclude', 'before', 'context', - 'exact_search', 'exclude', 'include', 'menu_order', @@ -86,6 +85,7 @@ public function test_registered_query_params() { 'per_page', 'search', 'search_columns', + 'search_semantics', 'slug', 'status', ), diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 26201a21fce08..3085d066fc6ae 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -195,7 +195,6 @@ public function test_registered_query_params() { 'categories', 'categories_exclude', 'context', - 'exact_search', 'exclude', 'include', 'modified_after', @@ -207,6 +206,7 @@ public function test_registered_query_params() { 'per_page', 'search', 'search_columns', + 'search_semantics', 'slug', 'status', 'sticky', @@ -790,10 +790,12 @@ public function test_get_items_exact_search( $search_term, $exact_search, $expec ) ); - $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); - $request['search'] = $search_term; - $request['exact_search'] = $exact_search; - $response = rest_get_server()->dispatch( $request ); + $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); + $request['search'] = $search_term; + if ( $exact_search ) { + $request['search_semantics'] = 'exact'; + } + $response = rest_get_server()->dispatch( $request ); $this->assertCount( $expected, $response->get_data() ); } diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 4d7ce1b99f2ef..e674a12b4ea08 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -362,9 +362,12 @@ mockedApiResponse.Schema = { "default": [], "required": false }, - "exact_search": { - "description": "Use exact search instead of full search.", - "type": "boolean", + "search_semantics": { + "description": "How to interpret the search input.", + "type": "string", + "enum": [ + "exact" + ], "required": false }, "offset": { @@ -1724,9 +1727,12 @@ mockedApiResponse.Schema = { "type": "integer", "required": false }, - "exact_search": { - "description": "Use exact search instead of full search.", - "type": "boolean", + "search_semantics": { + "description": "How to interpret the search input.", + "type": "string", + "enum": [ + "exact" + ], "required": false }, "offset": { @@ -2830,9 +2836,12 @@ mockedApiResponse.Schema = { "default": [], "required": false }, - "exact_search": { - "description": "Use exact search instead of full search.", - "type": "boolean", + "search_semantics": { + "description": "How to interpret the search input.", + "type": "string", + "enum": [ + "exact" + ], "required": false }, "offset": { @@ -3586,9 +3595,12 @@ mockedApiResponse.Schema = { "default": [], "required": false }, - "exact_search": { - "description": "Use exact search instead of full search.", - "type": "boolean", + "search_semantics": { + "description": "How to interpret the search input.", + "type": "string", + "enum": [ + "exact" + ], "required": false }, "offset": { @@ -4402,9 +4414,12 @@ mockedApiResponse.Schema = { "default": [], "required": false }, - "exact_search": { - "description": "Use exact search instead of full search.", - "type": "boolean", + "search_semantics": { + "description": "How to interpret the search input.", + "type": "string", + "enum": [ + "exact" + ], "required": false }, "offset": { @@ -7020,9 +7035,12 @@ mockedApiResponse.Schema = { "default": [], "required": false }, - "exact_search": { - "description": "Use exact search instead of full search.", - "type": "boolean", + "search_semantics": { + "description": "How to interpret the search input.", + "type": "string", + "enum": [ + "exact" + ], "required": false }, "offset": { @@ -7842,9 +7860,12 @@ mockedApiResponse.Schema = { "default": [], "required": false }, - "exact_search": { - "description": "Use exact search instead of full search.", - "type": "boolean", + "search_semantics": { + "description": "How to interpret the search input.", + "type": "string", + "enum": [ + "exact" + ], "required": false }, "offset": { @@ -8052,9 +8073,12 @@ mockedApiResponse.Schema = { "default": [], "required": false }, - "exact_search": { - "description": "Use exact search instead of full search.", - "type": "boolean", + "search_semantics": { + "description": "How to interpret the search input.", + "type": "string", + "enum": [ + "exact" + ], "required": false }, "offset": {