Skip to content

Inline Search: add Jetpack branding + Class Refactor #43330

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

Open
wants to merge 53 commits into
base: trunk
Choose a base branch
from

Conversation

anaemnesis
Copy link
Contributor

@anaemnesis anaemnesis commented May 1, 2025

Note

This PR is built on top of #43110, and will be merged after that is merged. That PR should be reviewed prior to this one as this PR includes both the present Jetpack Branding implementation, as well as highlighting. With that in mind, I'm opening this to review as well as eyes would still be helpful with respect to approach.

Proposed changes:

This PR aims to increase parity between Inline Search and Instant Search by adding Jetpack Branding to search results when Inline Search is active.

This PR takes the same JS injection approach as #42473. This will serve as the go-live basis and to demonstrate the implementation for any future iterations, e.g., moving from JS injection to a block-based approach.

Because this class, the search correction class, and the highlighter class use similar methods, I've opted to abstract shared methods to class-search-component.php. This then avoids quite a bit of duplicated code, though it may require some careful merge conflict resolution.

Per TwentyTwentyFive (TT5), the proposed implementation is shown below. I have some reservations about the amount of space between the final result and the branding, but this is a result of TT5 template markup and would require a change to the theme, so, this may be a limitation of the current approach.

CleanShot 2025-05-08 at 16 40 53

As with #42473, this change was tested with the top ~36 themes from Atomic. Please DM me on Slack for access to any of the non pub/ themes if you don't already have access to them for testing purposes.

astra
hello-elementor
tsubaki
pub/twentytwentyfour
Divi
pub/assembler
pub/hever
pub/twentytwentyfive
oceanwp
storefront
pub/dara
pub/twentytwentytwo
pub/twentytwenty
pub/twentytwentythree
pub/twentyseventeen
pub/creatio-2
kadence
pub/zoologist
Avada
hevor
pub/exford
pub/radcliffe-2
pub/attar
blocksy
pub/twentysixteen
neve
pub/maywood
pub/shawburn
pub/lodestar
pub/barnsbury
pub/morden
generatepress
pub/karuna
pub/baskerville-2

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

N/A

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

N/A

Testing instructions:

  • Either set add_filter( 'jetpack_search_replace_classic', '__return_true', 20 ); somewhere (e.g. using Code Snippets plugin) or add an early return true to should_replace_classic_search().
  • Disabled Instant Search via Jetpack --> Search in WP Admin.
  • You may need to run jp watch packages/search or build after checking out this branch.
  • Run any search. You should see a result like the screenshot above.
  • Try again with different themes from the list above. Each should display similarly to the above, with the Jetpack branding legible and below the final search result.
  • If you test with an unsupported theme, it would be a good opportunity to try the jetpack_search_colophon_selectors filter:
add_filter( 'jetpack_search_colophon_selectors', function( $selectors ) {
    $selectors[] = '.custom-colophon-selector';
    return $selectors;
} );

- Add two new methods, init_corrected_query_hooks() and update_search_options_with_correction()
  - These are likely to be changed

- Adjust search-results.jsx to (1) search against the correct query while (2) display informative text
  - This will be adjusted as the current functionality is to establish a foundation while ensuring things work

- Adds new styles for the "Did you mean?" line
- Add proper "Did you mean?" text
- Remove code from last week's testing
- Prep for turning the search suggestion into a link
- Update styling
- Rather than offering a "Did you mean?" choice, automatically try search suggestion
Restoring Instance Search changes back to trunk as our changes are going to apply to Inline Search only.
- Hook into pre_get_posts() for later displaying the corrected_query text
- Add a new setup_corrected_query_hooks() method which is to be modified in a future commit.
- Add a new maybe_use_corrected_query() method
- Add a new prepend_corrected_query_to_first_result() method to ensure that the corrected_query, if it's used, displays in the "Search results for:..." heading
- Add get_corrected_query_html() for outputting markup
- Add JS for injecting our new markup. This will be moved to its own file in a future commit.

Functionally:

- If a spelling error is corrected, and there is a result for the corrected spelling, the search form will return with two headings: (H1) "Search results for... { corrected_query }" followed by (H2) "No results found for... { original_query }"

- If a spelling error is discovered but there is no result for the corrected spelling, the search form will return with one headaing: (H1) "No results found for... { original_query }"
- Refactor output_corrected_query_script() method
- New get_title_selectors() method
- New enqueue_corrected_query_script() method
- Refactor output_corrected_query_html() method
- Moved JS to new ../inline-search/js file
- Add a new filter to allow users to specify their own search title selectors if their theme does not use
one of the three selectors specified. These were checked across themes Twenty Twenty Five going back to
Twenty Ten.
- Check $_GET['s'] with null coalescing instead of isset
- Favour an early return instead of the ! checks
- Change message language to 'No results for %s'
- Remove <strong> tags to avoid forcing bold

I also looked into an option like inserting <span> tags in case a user wanted to
style the $original_query word themselves, but I wasn't happy with the implications
of this for translators, and the word can always be styled with a bit of
fairly straightforward JS.
- Adds search result highlighting using the same <mark> tag approach as Instant Search.
- Splits up filter__pre_get_posts() with more discrete methods to avoid overloading filter__pre_get_posts() by giving it too much to do.
- Adds new filters and new methods as appropriate.
Split out search correction methods into their own class
- Leverage a similar approach to Search Correction to inject Search Branding
- Test against the 34 most popular Atomic themes
- Refactor existing classes to make use of abstraction due to similarity of methods between the colophone and search-correction classes
- Update webpack config
Copy link
Contributor

github-actions bot commented May 1, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the add/inline-search-branding branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/inline-search-branding

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added the [Package] Search Contains core Search functionality for Jetpack and Search plugins label May 1, 2025
Copy link
Contributor

github-actions bot commented May 1, 2025

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.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • 🔴 Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Search plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

Copy link

jp-launch-control bot commented May 1, 2025

Code Coverage Summary

Cannot generate coverage summary while tests are failing. 🤐

Please fix the tests, or re-run the Code coverage job if it was something being flaky.

Full summary · PHP report · JS report

Coverage check overridden by Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR .

@github-actions github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. labels May 8, 2025
@anaemnesis anaemnesis changed the title Inline Search: add Jetpack branding Inline Search: add Jetpack branding + Class Refactor May 8, 2025
@anaemnesis anaemnesis marked this pull request as ready for review May 9, 2025 09:58
@anaemnesis anaemnesis requested a review from trakos May 9, 2025 09:58
@anaemnesis anaemnesis added the Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR label May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR [Package] Search Contains core Search functionality for Jetpack and Search plugins [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Status] In Progress [Tests] Includes Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant