-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow exact search in REST API #3677
Conversation
$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' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What result do you get when you search Types of Bread
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much like /?s=Types+of+Bread&exact=1
, this will not return a match. This applies to any exact search in which the search term includes a space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we exact search the one word, it will return the posts matching exactly, but if there are multiple words to exact search, it doesn't work actually. so would it make sense to introduce sentence
as well in the REST api?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimothyBJacobs What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ironprogrammer @TimothyBJacobs What is your thoughts on #3677 (comment)? |
@@ -251,6 +251,7 @@ public function get_items( $request ) { | |||
'search' => 's', | |||
'slug' => 'post_name__in', | |||
'status' => 'post_status', | |||
'exact_search' => 'exact', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These appear to be organised alphabetically by key, so the new exact_search
key should be placed above exclude
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@costdev I have updated the placement for exact_search
now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mehulkaklotar!
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks good to me! we just need to regenerate wp-api-generated.js
Co-authored-by: Timothy Jacobs <[email protected]>
Hm, though looking at this, if we do want to add |
@TimothyBJacobs At this point, we'd probably only support the |
Yeah, I don't think this is bad as is. A |
@TimothyBJacobs Updated to use |
@@ -337,6 +337,13 @@ public function get_items( $request ) { | |||
} | |||
} | |||
|
|||
if ( | |||
isset( $registered['search_semantics'], $request['search_semantics'] ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't technically need the isset
check since the rest request object will just return null
in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair. I feel like it's okay keeping though for consistency. Maybe also a tiny bit safer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me.
Committed in https://core.trac.wordpress.org/changeset/59034 |
Trac ticket: https://core.trac.wordpress.org/ticket/56350
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.