Skip to content
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

Search: migrate/add search rest API #21584

Merged
merged 45 commits into from
Nov 25, 2021
Merged

Search: migrate/add search rest API #21584

merged 45 commits into from
Nov 25, 2021

Conversation

kangzj
Copy link
Contributor

@kangzj kangzj commented Oct 29, 2021

Changes proposed in this Pull Request:

Add all necessary APIs for standalone and Jetpack the plugin except for the search_auto_config API and probably the API to deactivate expired search.

  1. Returns search plan: GET jetpack/v4/search/plan
{
  "search_subscriptions": [
    {
      "ID": "xxx",
      "user_id": "xxx",
      "blog_id": "xxx",
      "product_id": "2104",
      "expiry": "2025-05-17",
      "subscribed_date": "2021-05-17 05:34:09",
      "renew": "0",
      "auto_renew": "1",
      "ownership_id": "xxx",
      "most_recent_renew_date": "",
      "subscription_status": "active",
      "is_instant_search": true,
      "tier": "up_to_100_records",
      "product_name": "Jetpack Search"
    }
  ],
  "supports_instant_search": true,
  "supports_only_classic_search": false,
  "supports_search": true
}
  1. Returns search module settings: GET jetpack/v4/search/settings
{
  "module_active": true,
  "instant_search_enabled": false
}
  1. Update search module settings: POST jetpack/v4/search/settings

Request:

{
  "instant_search_enabled": false,
  "module_active": true
}

Response:

{
  "module_active": true,
  "instant_search_enabled": false
}
  1. Search endpoint for private sites (private Atomic sites atm): GET jetpack/v4/search

The format is exactly the same with public search API v1.3. Something like the following,

aggregations: []
corrected_query: false
page_handle: false
results: [{_score: 2,…}, {_score: 1.1753112,…}, {_score: 1.1753112,…}, {_score: 1.1753112,…},…]
suggestions: []
total: 6

Jetpack product discussion

n/a

Does this pull request change what data or activity we track or use?

no

Testing instructions:

  • Make sure tests pass ( cd projects/packages/search && composer phpunit )
  • Go to a site with search subscription
  • Set blog_public to -1 in the database
  • Ensure instant search calls http://yousite/wp-json/jetpack/v4/search for results and results / filters show correctly.
  • Test the APIs separately, I used Rest Client in VSCode. Requests are like the following. You'll need to replace the nonce and cookie which could be get from Chrome dev tools. If you have better ways to test, please let me know 😄
GET https://jasper.au.ngrok.io/wp-json/jetpack/v4/search/plan HTTP/1.1
x-wp-nonce: xxx
cookie: yyy
GET https://jasper.au.ngrok.io/wp-json/jetpack/v4/search/settings HTTP/1.1
x-wp-nonce: xxx
cookie: yyy
POST https://jasper.au.ngrok.io/wp-json/jetpack/v4/search/settings HTTP/1.1
Content-Type: application/json
x-wp-nonce: xxx
cookie: yyy

{
  "instant_search_enabled": false,
  "module_active": true
}
GET https://jasper.au.ngrok.io/wp-json/jetpack/v4/search HTTP/1.1
x-wp-nonce: xxx
cookie: yyy

@kangzj kangzj added [Status] In Progress [Feature] WP REST API [Feature] Search For all things related to Search Instant Search [Package] Search Contains core Search functionality for Jetpack and Search plugins labels Oct 29, 2021
@kangzj kangzj self-assigned this Oct 29, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 29, 2021

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ⚠️ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: December 7, 2021.
  • Scheduled code freeze: November 30, 2021.

@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Nov 1, 2021
@kangzj kangzj requested a review from a team November 2, 2021 01:58
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello kangzj! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D69399-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

jsnmoon
jsnmoon previously approved these changes Nov 8, 2021
Copy link
Member

@jsnmoon jsnmoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work. All the functionality described in the PR works as expected and the code changes look good, especially with the addition of unit tests.

(I'd still recommend smoke testing the changes for private atomic sites before rolling them out to WPCOM.)

@kangzj
Copy link
Contributor Author

kangzj commented Nov 10, 2021

  // TODO check Plan supports search.   @jsnmoon 

Hi @jsnmoon Thanks for catching this. Now a Plan class is introduced to solve it - and added more tests 😄 Would love another review if possible, thanks.

@kangzj kangzj force-pushed the add/search-rest-api branch 2 times, most recently from 17eca5d to a4f8388 Compare November 11, 2021 21:35
@kangzj kangzj requested a review from jsnmoon November 12, 2021 04:09
Copy link
Member

@jsnmoon jsnmoon left a 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 go 👍. I left some revision recommendations inline below.

IMPORTANT: I'll revert changes for Jetpack the plugin and only merge changes for search the package in the PR.

Is there a need for this with these changes? The only translated string ('You are not allowed to perform this action.') is shown only during 4xx API errors.

@kangzj
Copy link
Contributor Author

kangzj commented Nov 16, 2021

Is there a need for this with these changes? The only translated string ('You are not allowed to perform this action.') is shown only during 4xx API errors.

TBH I'm not 100% sure this is the best approach. But I just don't want the PR to touch any files synced with WPCOM - because we don't really want to sync these changes now, as 1. the package is not released to WPCOM yet 2. they might become irrelevant pretty soon - when we finish the package and everything will be in the package and barely nothing to sync from Jetpack the plugin to WPCOM (I guess we could abandon fusion, couldn't we?).

A lot of stacked changes on Jetpack the plugin and don't sync them, seems rather problematic to me. For example, if we have something urgent to fix, it would be pretty hard.

Also by doing so we would be able to consider it with WPCOM Search together, so that we might be able to figure out a better solution, like I mentioned above, getting rid of fusion, etc..

Last but not the least, we'd have more chances to test and discover issues, and less chances to break things.

-----EDIT-------

Will merge all changes as usual.

@kangzj kangzj added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] Needs Team Review [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Nov 17, 2021
@kangzj
Copy link
Contributor Author

kangzj commented Nov 23, 2021

Hi @jeherve @anomiex @sdixon194, can I please get a review on this PR please? thanks.

@kangzj
Copy link
Contributor Author

kangzj commented Nov 24, 2021

@Automattic/jetpack-crew Hi team, anyone have a look at this please? Thanks.

Copy link
Member

@jeherve jeherve left a 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. Let's merge this! 🚢

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Nov 25, 2021
@kangzj kangzj merged commit 2fb8179 into master Nov 25, 2021
@kangzj kangzj deleted the add/search-rest-api branch November 25, 2021 14:09
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Nov 25, 2021
@github-actions
Copy link
Contributor

Great news! One last step: head over to your WordPress.com diff, D69399-code, and commit it.
Once you've done so, come back to this PR and add a comment with your changeset ID.

Thank you!

@kangzj
Copy link
Contributor Author

kangzj commented Nov 25, 2021

These changes will be synced to WPCOM once the classic/instant search migration is complete.

@jsnmoon jsnmoon moved this from Review to Done in Jetpack Search - Standalone Dec 1, 2021
davidlonjon added a commit that referenced this pull request Dec 2, 2021
* master: (22 commits)
  Update storybook monorepo to v6.4.0 (#21897)
  Refresh the site's modules and settings after successful product activation (#21886)
  Plugin Install: Bump MC stat on success or fail. (#21893)
  Nav Unification: Use correct user capability for the Inbox menu item (#21882)
  Jetpack: Extend disconnection dialog component to handle multiple steps and accept more props (#21048)
  Disable CSSTidy property shorthand optimization in the editor or headstart (#21891)
  Connection UI: Update Composer instructions in README.md (#21890)
  Partner Compatibility: Adding a unique connection screen for customers who receive a coupon from a Jetpack partner (#21813)
  Search package: move search dashboard to package - the base (#21865)
  JITM: wrap CTA below text on small viewports (#21688)
  Licensing JS Package – fix icon positioning and width (#21878)
  JITM: new JS and CSS builder (#21874)
  Support site_intent for `/me/sites` endpoint (#21880)
  Don't render Critical CSS while generating CritCSS. (#21879)
  ConnectScreen: make button full width on small screens (#21683)
  Improve the copy of the license activation banner (#21876)
  Rename Webpack-built files back from `.min.js` and remove hashes (#21748)
  Search: Migrate more helper classes to package (#21751)
  Search: migrate/add search rest API (#21584)
  Add initial state to the connection package (#21864)
  ...
@kangzj
Copy link
Contributor Author

kangzj commented Mar 4, 2022

D69399-code is abandoned, because class-wpcom-rest-api-v2-endpoint-search.php is not in use on WPCOM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extra Sidebar Widgets [Feature] Search For all things related to Search [Feature] WP REST API [Package] Search Contains core Search functionality for Jetpack and Search plugins [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Touches WP.com Files
Development

Successfully merging this pull request may close these issues.

None yet

4 participants