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

feat(widgets): Implement queryRuleCustomData widget #222

Merged
merged 12 commits into from
Oct 18, 2024

Conversation

tharropoulos
Copy link
Contributor

Rationale

We're enhancing our search experience by introducing the ability to display dynamic content based on metadata from curation rules. This feature allows us to show personalized banners, promotions, or any custom content triggered by specific search queries.

Change Summary

Added Features:

  1. New method in SearchResponseAdapter.js:

    • _adaptUserData(metadata): Adapts the metadata from Typesense response to the format expected by InstantSearch.js.
  2. In app.js (testground):

    • Added queryRuleCustomData widget to display custom content based on metadata.

Code Changes:

  1. In SearchResponseAdapter.js:

    • Modified adapt() method to include appliedRules and userData when metadata is present in the Typesense response.
  2. In populateProductsIndex.js:

    • Added an override rule for "Samsung" queries to include metadata for promotional content.

Test Updates:

  1. In SearchResponseAdapter.test.js:

    • Added tests for _adaptUserData method to ensure correct formatting of metadata.
  2. In widgets.test.js:

    • Added tests for queryRuleCustomData widget to verify proper rendering of metadata-based content.

Documentation Updates:

  1. In index.html (testground):
    • Added a new <div> with id "banner" to display the custom content.
  2. In README.md:
    • Removed the queryRuleCustomData widget from the list of unsupported widgets.

Demo

To demonstrate the new feature, we've added a custom banner for Samsung phone promotions in our test environment. Here's how it works:

  1. When a user searches for "Samsung", it triggers a curation rule we've set up.
  2. This rule includes metadata with promotional content: "20% on all Samsung Phones!"
  3. The queryRuleCustomData widget detects this metadata and renders it in the "#banner" element.
  4. Users see a personalized banner with the promotion, enhancing their search experience.

This demo showcases how we can dynamically display relevant content based on user queries, opening up possibilities for targeted marketing, seasonal promotions, or any other context-sensitive information we want to present to our users.

PR Checklist

@tharropoulos
Copy link
Contributor Author

It seems as though updating to 27.1 (39b6d85) breaks the searchExperience test. Specifically on

await expect(page).toMatchElement("#stats", {
text: "250 results found",
});

When using 27.1 it returns 263 records as opposed to the test's 250

@jasonbosco
Copy link
Member

@tharropoulos Yeah, I've seen some minor differences in number of results fetched between versions as we changed the defaults for some of the search parameters. So feel free to update the count of results found in the tests

@tharropoulos
Copy link
Contributor Author

@tharropoulos Yeah, I've seen some minor differences in number of results fetched between versions as we changed the defaults for some of the search parameters. So feel free to update the count of results found in the tests

Resolved in 0f6fd6e

@jasonbosco jasonbosco merged commit 2d53950 into typesense:master Oct 18, 2024
1 check passed
@jasonbosco
Copy link
Member

Now available in v2.9.0-4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants