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

Add support for queryRuleContext widget #223

Merged
merged 9 commits into from
Oct 18, 2024

Conversation

tharropoulos
Copy link
Contributor

Rationale

Introduce the queryRuleContext widget to enhance the search experience by allowing dynamic application of rules based on the current search context. This feature will enable more targeted and relevant search results by transforming rule contexts into override tags. By doing so, we're bridging the gap between Algolia's query rules and Typesense's overrides, making it easier for developers to migrate their applications while maintaining advanced search functionalities.

Changes

Added Features:

  1. New Transformation Logic in src/SearchRequestAdapter.js:
    • Add functionality to transform rule contexts into override tags for Typesense.

Code Changes:

  1. In src/SearchRequestAdapter.js:
    • Update the adapt method to include logic for transforming ruleContexts to override tags.
    • Implement a new method to convert rule contexts into a format compatible with Typesense overrides.

Test Updates:

  1. In test/queryRuleContext.test.js:

    • Add new test cases to verify the correct transformation of rule contexts to override tags.
    • Include tests for various scenarios of rule context usage and their expected outcomes in Typesense queries.
  2. In test/support/populateProductsIndex.js:

    • Add logic to create an override with a tag on the products test collection, supporting the new queryRuleContext tests.
  3. In test/widgets.test.js:

  • Add tests for the queryRuleContext widget.

Documentation Updates:

  1. In README.md or relevant documentation file:
    • Update the list of supported InstantSearch.js widgets to include queryRuleContext.

Demo

import { queryRuleContext } from 'instantsearch.js/es/widgets';

const search = instantsearch({
  // ... other configuration
});

search.addWidgets([
  queryRuleContext({
    trackedFilters: {
      brand: () => ['Apple', 'Samsung'],
    },
  }),
  // ... other widgets
]);

In this example, when a user searches for products and the brand filter includes 'Apple' or 'Samsung', the corresponding context rule will be applied. This context is then transformed into an override tag in the Typesense query, allowing for more specific and relevant search results based on the current context. This way, the overrides aren't automatically applied, but specifically triggered only when the tracked filters are applied

PR Checklist

@jasonbosco jasonbosco merged commit 96e2d64 into typesense:master Oct 18, 2024
1 check passed
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