Skip to content

Enable remote search in Themes if custom themes are supported #24262

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

Merged

Conversation

pmusolino
Copy link
Contributor

Fixes #23153

Dependent on this PR wordpress-mobile/WordPressKit-iOS#834

This PR partially improves the search functionality within the Theme by enhancing its capabilities. Previously, the search was limited to locally fetched themes and did not include elements that had not been paginated. Now, it works remotely for blogs that support custom themes. The endpoint used for this case supports search, whereas other endpoints, such as the one utilized by the getThemesForBlogId method, do not support remote search functionality.

However, the search is available for getWPThemesPage (which calls the v2.0/themes endpoint) only if at least 3 characters are added in the search bar. For this reason, this limitation has also been handled in the app. For all other endpoints where remote searching is not available, the search continues to work locally.

Keep in mind during your tests that searching through the API does not only look for matches in the title of the theme. Therefore, when you type a string, you may see other related themes as well.

To test:

Custom Themes not supported

  1. Create a new blog in WP.com.
  2. Navigate to Themes view.
  3. Try searching by a keyword. You should be able to search only through locally fetched themes.

Custom Themes supported

  1. Select a blog where Custom Themes are enabled.
  2. Navigate to Themes view.
  3. While typing, you can filter themes in both sections: uploaded themes and WordPress.com themes. Try to search specifically for a theme that does not appear in the first page of WordPress.com themes, like the one mentioned in the original issue: scrawl.

Regression Notes

  1. Potential unintended areas of impact

  2. What I did to test those areas of impact (or what existing automated tests I relied on)

  3. What automated tests I added (or what prevented me from doing so)

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Testing checklist:

  • WordPress.com sites and self-hosted Jetpack sites.
  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

…wift

- Apply immediate local search when search text changes
- Perform remote search for WordPress.com themes with 3+ characters
- Update predicates to include local search conditions for custom themes
- Refactor comments for clarity on search behavior and conditions
- Modify `ThemeBrowserViewController.swift` to include `resetRemoteSearch` method
- Integrate `resetRemoteSearch` in search logic to reset search state upon search text changes
- Adjust logic to handle shorter search queries that follow longer ones by resetting remote search
- Ensure local results reload consistently after search operations
- Update test to use nil instead of empty string for search in ThemeServiceTests.m
- Change `fileprivate` to `private` for several functions and variables in ThemeBrowserViewController.swift
- Simplify guard statement in `updateSearchName` function
- Update comment in `customThemesBrowsePredicate` function
@dangermattic
Copy link
Collaborator

dangermattic commented Mar 19, 2025

1 Warning
⚠️ This PR is assigned to the milestone 25.9. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 19, 2025

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr24262-69c5b90
Version25.8
Bundle IDorg.wordpress.alpha
Commit69c5b90
App Center BuildWPiOS - One-Offs #11757
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 19, 2025

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr24262-69c5b90
Version25.8
Bundle IDcom.jetpack.alpha
Commit69c5b90
App Center Buildjetpack-installable-builds #10783
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@kean
Copy link
Contributor

kean commented Mar 20, 2025

Hey, thanks for addressing it!

I tested the steps from the reported issue, and was able to find the theme:

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-03-20.at.09.29.39.mp4

For all other endpoints where remote searching is not available, the search continues to work locally.

Can we eliminate local search? What are the scenarios under which remote searching was not available?

We were in a similar situation with the search for your posts that was local and broken in the same way. It now searches exclusively using the search endpoint – no local results are ever shown.

I've noticed some minor glitches when searching. It would initially show "No matching results" but then, presumably when the app gets the response, it would show the results. Eliminating local search (for anything other than custom theme?) should address it.

Search term is less than 3 characters (we'll only search locally for short terms)

Does the endpoint support searching with fewer characters? I'd expect to be able to type a single character and return some results that start with it.

@@ -46,7 +46,7 @@ let package = Package(
.package(url: "https://github.com/wordpress-mobile/MediaEditor-iOS", branch: "task/spm-support"),
.package(url: "https://github.com/wordpress-mobile/NSObject-SafeExpectations", from: "0.0.6"),
.package(url: "https://github.com/wordpress-mobile/NSURL-IDN", branch: "trunk"),
.package(url: "https://github.com/wordpress-mobile/WordPressKit-iOS", branch: "wpios-edition"),
.package(url: "https://github.com/wordpress-mobile/WordPressKit-iOS", branch: "add-search-param-in-theme-service-remote"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make sure to update it to point to wpios-edition before merging.

@kean kean removed the Bug label Mar 20, 2025
@pmusolino
Copy link
Contributor Author

Thanks for testing it @kean!

Can we eliminate local search? What are the scenarios under which remote searching was not available?

The scenarios where remote searching is not available are:

  • Blog doesn't support custom themes (eg. free WP.com plans)
  • User's installed themes.

So, I think it's important to maintain local search for two reasons. First, while the user is searching remotely, we also display and search locally among the user's installed themes. Plus, if a user is on WP.com free plans, we should allow them to search among available themes, which currently number 170+ (around 4 pages of pagination).
It's not ideal, but it's probably definitely better than removing this functionality.

I've noticed some minor glitches when searching. It would initially show "No matching results" but then, presumably when the app gets the response, it would show the results. Eliminating local search (for anything other than custom theme?) should address it.

I was not able to replicate this issue, even when typing slowly. Keep in mind that remote searching uses its own logic and is not perfect in my experiments. For example, I tried searching for the final part of a text and the theme was not found, while typing the initials of the theme did yield results.

Does the endpoint support searching with fewer characters? I'd expect to be able to type a single character and return some results that start with it.

Unfortunately, no, but it's not documented anywhere, and indeed this case is handled. If we send the search with fewer than 3 characters to the API request, it always returns 0 results, which is far from ideal. Maybe this can be improved on the UX side by explicitly asking users to add at least 3 characters.

…153-cannot-search-for-themes-if-not-already-downloaded

# Conflicts:
#	WordPress.xcworkspace/xcshareddata/swiftpm/Package.resolved
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 28, 2025

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number26920
VersionPR #24262
Bundle IDcom.jetpack.alpha
Commit1d552f7
Installation URL1fc6to2gbp5e8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 28, 2025

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number26920
VersionPR #24262
Bundle IDorg.wordpress.alpha
Commit1d552f7
Installation URL5pot4107tb69o
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@pmusolino pmusolino requested a review from kean March 31, 2025 12:39
@pmusolino
Copy link
Contributor Author

@kean I requested a new review since now the PR is pointing to the right branch of WordPressKit


// For regular themes, add local search predicate if:
// 1. Not using custom themes feature, or
// 2. Search term is less than 3 characters (we'll only search locally for short terms)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting that it's an unfortunate limitation.

@pmusolino pmusolino added this pull request to the merge queue Mar 31, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 31, 2025
@kean kean added this pull request to the merge queue Mar 31, 2025
Merged via the queue into trunk with commit a28d224 Mar 31, 2025
25 checks passed
@kean kean deleted the issue/23153-cannot-search-for-themes-if-not-already-downloaded branch March 31, 2025 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot find Seedlet theme
4 participants