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: switch typesense sorting to presets #1458

Merged
merged 1 commit into from
Jun 28, 2024

Conversation

zacjones93
Copy link
Contributor

Since migrating to TypeSense, whenever a user inputs a search or clicks a filter the url is populated by the sorting that we need to do for the content that makes sense.

e.g. https://egghead.io/q?q=react&sortBy=content_production/sort/_eval([%20(type:playlist):4,%20(type:lesson):3,%20(type:podcast):2],%20(type:talk):1):desc,search_research_sort:asc,rank:asc

The first sorting function is particularly important as it rank sorts playlists to the top before other types of content.

The other way to do this is with presets but @Creeland and I were having a rough time actually setting a preset apart from initial load. Turns out that the TypeSense adapter has an updateConfiguration function that we can call when we want to switch to a different preset as recommended here.

I'm updating configuration in a select and calling instantsearches refresh to trigger another search.

gif

@zacjones93 zacjones93 requested a review from Creeland June 26, 2024 23:15
Copy link

vercel bot commented Jun 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
egghead-io-nextjs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2024 11:15pm

Comment on lines +171 to +181
onChange={(e) => {
typesenseAdapter.updateConfiguration({
...typsenseAdapterConfig,
additionalSearchParameters: {
query_by: 'title,description,_tags,instructor_name,contributors',
preset: e.target.value,
},
})

refresh()
}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

where the magic happens. updates configuration and triggers a search

Comment on lines +39 to +41
export const typesenseAdapter = typesenseInstantsearchAdapter()

const searchClient = typesenseAdapter.searchClient
Copy link
Contributor Author

Choose a reason for hiding this comment

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

need access to the typesenseAdapter to update configuration

@@ -1,34 +1,29 @@
import TypesenseInstantSearchAdapter from 'typesense-instantsearch-adapter'

export const typsenseAdapterConfig = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

stuffed the config in an object to spread when we update presets

@nicollguarnizo nicollguarnizo self-requested a review June 28, 2024 20:08
@zacjones93 zacjones93 merged commit 1cfce3d into main Jun 28, 2024
6 checks passed
@kodiakhq kodiakhq bot deleted the zj/switch-typesense-sorting-to-presets branch June 28, 2024 20:10
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