Changeset 59034
- Timestamp:
- 09/17/2024 09:56:18 PM (2 weeks ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r58783 r59034 336 336 $args['post__not_in'] = array_merge( $args['post__not_in'], $sticky_posts ); 337 337 } 338 } 339 340 if ( 341 isset( $registered['search_semantics'], $request['search_semantics'] ) 342 && 'exact' === $request['search_semantics'] 343 ) { 344 $args['exact'] = true; 338 345 } 339 346 … … 2887 2894 } 2888 2895 2896 $query_params['search_semantics'] = array( 2897 'description' => __( 'How to interpret the search input.' ), 2898 'type' => 'string', 2899 'enum' => array( 'exact' ), 2900 ); 2901 2889 2902 $query_params['offset'] = array( 2890 2903 'description' => __( 'Offset the result set by a specific number of items.' ), -
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r58612 r59034 230 230 'search', 231 231 'search_columns', 232 'search_semantics', 232 233 'slug', 233 234 'status', -
trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php
r58326 r59034 86 86 'search', 87 87 'search_columns', 88 'search_semantics', 88 89 'slug', 89 90 'status', -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r58326 r59034 207 207 'search', 208 208 'search_columns', 209 'search_semantics', 209 210 'slug', 210 211 'status', … … 764 765 $this->assertNotEquals( $draft_id, $post['id'] ); 765 766 } 767 } 768 769 /** 770 * @ticket 56350 771 * 772 * @dataProvider data_get_items_exact_search 773 * 774 * @param string $search_term The search term. 775 * @param bool $exact_search Whether the search is an exact or general search. 776 * @param int $expected The expected number of matching posts. 777 */ 778 public function test_get_items_exact_search( $search_term, $exact_search, $expected ) { 779 self::factory()->post->create( 780 array( 781 'post_title' => 'Rye', 782 'post_content' => 'This is a post about Rye Bread', 783 ) 784 ); 785 786 self::factory()->post->create( 787 array( 788 'post_title' => 'Types of Bread', 789 'post_content' => 'Types of bread are White and Rye Bread', 790 ) 791 ); 792 793 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 794 $request['search'] = $search_term; 795 if ( $exact_search ) { 796 $request['search_semantics'] = 'exact'; 797 } 798 $response = rest_get_server()->dispatch( $request ); 799 $this->assertCount( $expected, $response->get_data() ); 800 } 801 802 /** 803 * Data provider for test_get_items_exact_search(). 804 * 805 * @return array[] 806 */ 807 public function data_get_items_exact_search() { 808 return array( 809 'general search, one exact match and one partial match' => array( 810 'search_term' => 'Rye', 811 'exact_search' => false, 812 'expected' => 2, 813 ), 814 'exact search, one exact match and one partial match' => array( 815 'search_term' => 'Rye', 816 'exact_search' => true, 817 'expected' => 1, 818 ), 819 'exact search, no match and one partial match' => array( 820 'search_term' => 'Rye Bread', 821 'exact_search' => true, 822 'expected' => 0, 823 ), 824 ); 766 825 } 767 826 -
trunk/tests/qunit/fixtures/wp-api-generated.js
r59032 r59034 363 363 "required": false 364 364 }, 365 "search_semantics": { 366 "description": "How to interpret the search input.", 367 "type": "string", 368 "enum": [ 369 "exact" 370 ], 371 "required": false 372 }, 365 373 "offset": { 366 374 "description": "Offset the result set by a specific number of items.", … … 1720 1728 "required": false 1721 1729 }, 1730 "search_semantics": { 1731 "description": "How to interpret the search input.", 1732 "type": "string", 1733 "enum": [ 1734 "exact" 1735 ], 1736 "required": false 1737 }, 1722 1738 "offset": { 1723 1739 "description": "Offset the result set by a specific number of items.", … … 2819 2835 }, 2820 2836 "default": [], 2837 "required": false 2838 }, 2839 "search_semantics": { 2840 "description": "How to interpret the search input.", 2841 "type": "string", 2842 "enum": [ 2843 "exact" 2844 ], 2821 2845 "required": false 2822 2846 }, … … 3572 3596 "required": false 3573 3597 }, 3598 "search_semantics": { 3599 "description": "How to interpret the search input.", 3600 "type": "string", 3601 "enum": [ 3602 "exact" 3603 ], 3604 "required": false 3605 }, 3574 3606 "offset": { 3575 3607 "description": "Offset the result set by a specific number of items.", … … 4383 4415 "required": false 4384 4416 }, 4417 "search_semantics": { 4418 "description": "How to interpret the search input.", 4419 "type": "string", 4420 "enum": [ 4421 "exact" 4422 ], 4423 "required": false 4424 }, 4385 4425 "offset": { 4386 4426 "description": "Offset the result set by a specific number of items.", … … 6996 7036 "required": false 6997 7037 }, 7038 "search_semantics": { 7039 "description": "How to interpret the search input.", 7040 "type": "string", 7041 "enum": [ 7042 "exact" 7043 ], 7044 "required": false 7045 }, 6998 7046 "offset": { 6999 7047 "description": "Offset the result set by a specific number of items.", … … 7813 7861 "required": false 7814 7862 }, 7863 "search_semantics": { 7864 "description": "How to interpret the search input.", 7865 "type": "string", 7866 "enum": [ 7867 "exact" 7868 ], 7869 "required": false 7870 }, 7815 7871 "offset": { 7816 7872 "description": "Offset the result set by a specific number of items.", … … 8016 8072 }, 8017 8073 "default": [], 8074 "required": false 8075 }, 8076 "search_semantics": { 8077 "description": "How to interpret the search input.", 8078 "type": "string", 8079 "enum": [ 8080 "exact" 8081 ], 8018 8082 "required": false 8019 8083 },
Note: See TracChangeset
for help on using the changeset viewer.