[wp-trac] [WordPress Trac] #56350: Allow exact search in REST API

WordPress Trac noreply at wordpress.org
Fri Aug 19 01:06:09 UTC 2022


#56350: Allow exact search in REST API
-------------------------------------------------+-------------------------
 Reporter:  jimmyh61                             |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  REST API                             |     Version:  4.7
 Severity:  normal                               |  Resolution:
 Keywords:  good-first-bug has-patch needs-      |     Focuses:  rest-api,
  testing has-unit-tests has-testing-info        |  performance
-------------------------------------------------+-------------------------
Changes (by ironprogrammer):

 * keywords:
     good-first-bug has-patch needs-testing needs-testing-info has-unit-
     tests
     => good-first-bug has-patch needs-testing has-unit-tests has-testing-
     info


Comment:

 == Test Report

 This [https://make.wordpress.org/test/handbook/test-reports/#feature-or-
 enhancement-combined-report-template combined test report] includes
 testing instructions and enhancement patch test results.

 Patch tested:
 https://core.trac.wordpress.org/attachment/ticket/56350/56350.diff

 LGTM 👍🏻 When it lands, it will need `needs-user-docs`.

 === Steps to Test
 ''(Exact post content is at tester's discretion; samples provided are from
 [https://core.trac.wordpress.org/attachment/ticket/56350/56350.tests.improved.diff
 the unit test]. Just ensure that each post's title is unique and that
 there is a shared keyword between the content.)''

 1. Create and publish a new post with title "Rye", and content "This is a
 post about Rye Bread".
 2. Create and publish a second post with title "Types of Bread", and
 content "Types of bread are White and Rye Bread". ''Note that the keyword
 "rye" is shared between the two posts.''
 3. **Regression Test:** In a browser load the following URL:
   `<your site>/wp-json/wp/v2/posts?search=rye`
 ''(The REST API `search` parameter corresponds to the `WP_Query` `s`
 parameter.)''
 4. ✅ The JSON results should contain at least two (2) results, more if
 you have other posts containing "rye" (a JSON viewer extension may be
 helpful to view the results here).
 5. **Enhancement Test:** In a browser load the following URL:
   `<your site>/wp-json/wp/v2/posts?search=rye&exact_search=true`
 ''(The patch's `exact_search` REST API parameter corresponds to the
 `WP_Query` `exact` parameter.)''
 6. ✅ The exact search JSON results should contain just one (1) result:
 the "Rye" post.

 === Expected Results
 - ✅ Querying the API without the new API parameter should return all
 posts containing the search keyword.
 - ✅ Querying the API with `exact_search` should only return the post name
 matching the search keyword.

 === Environment
 - OS: macOS 12.5
 - Browser: Safari 15.6
 - Browser: Google Chrome 104.0.5112.79
 - Server: nginx/1.23.1
 - PHP: 7.4.30
 - WordPress: 6.1-alpha-53344-src

 === Actual Results
 ''After applying patch...''
 - ✅ Querying the API without the new API parameter returned all posts
 containing the search keyword.
 - ✅ Querying the API with `exact_search` only returned the post name
 matching the search keyword.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56350#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list