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(algolia): add getAlgoliaFacetHits preset #451

Merged
merged 2 commits into from Feb 18, 2021

Conversation

francoischalifour
Copy link
Member

Description

The getAlgoliaFacetHits function is an additional search util to our @algolia/autocomplete-preset-algolia package.

We now have:

  • getAlgoliaHits
  • getAlgoliaResults
  • getAlgoliaFacetHits

This function is useful to search for facets in the Autocomplete panel. Later, it will be useful when using Autocomplete Tags to refine the query to a category as a first step of the flow.

Preview

image

Implementation

The getAlgoliaFacetHits function returns a similar format to React InstantSearch's facet hits from connectRefinementList. This allows to use highlighting utils (e.g., highlightHit) with facet hits.

[
  {
    "count": 507,
    "label": "Mobile phones",
    "_highlightResult": {
      "label": {
        "value": "Mobile <em>phone</em>s"
      }
    }
  },
  {
    "count": 63,
    "label": "Phone cases",
    "_highlightResult": {
      "label": {
        "value": "<em>Phone</em> cases"
      }
    }
  }
]

<div className="aa-ItemContent">
<div className="aa-ItemContentTitle">
{highlightHit<Hit<CategoryItem>>({
hit: item as any,
Copy link
Member Author

Choose a reason for hiding this comment

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

This any cast is needed for now because our typings require the hit to have objectID. I'll fix that in another PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in #452.

Copy link
Contributor

@Haroenv Haroenv 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 great! would love to see what you have in mind for merging requests (not as big of a deal for sffv of course, since that doesn't exist in a single request)

@francoischalifour
Copy link
Member Author

In 8c135a4 I added a test for the JS package.

@francoischalifour
Copy link
Member Author

would love to see what you have in mind for merging requests

I haven't spec-ed it yet but that will be the role of the Requester API. These getAlgolia* functions would be contained in an object that schedules the calls. But this API could be more powerful to handle asynchronous responses (e.g., to support Answers), filtering, etc.

@francoischalifour francoischalifour merged commit 8876fd3 into next Feb 18, 2021
@francoischalifour francoischalifour deleted the feat/getAlgoliaFacetHits branch February 18, 2021 17:36
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.

None yet

2 participants