Skip to content

Commit

Permalink
feat(search): surface explorer views in autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Mar 18, 2024
1 parent 59a0df6 commit 84a9479
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions site/search/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ const getItemUrl: AutocompleteSource<BaseItem>["getItemUrl"] = ({ item }) =>
const prependSubdirectoryToAlgoliaItemUrl = (item: BaseItem): string => {
const indexName = parseIndexName(item.__autocomplete_indexName as string)
const subdirectory = indexNameToSubdirectoryMap[indexName]
return `${subdirectory}/${item.slug}`
switch (indexName) {
case SearchIndexName.ExplorerViews:
return `${subdirectory}/${item.explorerSlug}${item.viewQueryParams}`
default:
return `${subdirectory}/${item.slug}`
}
}

const FeaturedSearchesSource: AutocompleteSource<BaseItem> = {
Expand Down Expand Up @@ -130,6 +135,14 @@ const AlgoliaSource: AutocompleteSource<BaseItem> = {
distinct: true,
},
},
{
indexName: getIndexName(SearchIndexName.ExplorerViews),
query,
params: {
hitsPerPage: 1,
distinct: true,
},
},
{
indexName: getIndexName(SearchIndexName.Explorers),
query,
Expand All @@ -149,11 +162,20 @@ const AlgoliaSource: AutocompleteSource<BaseItem> = {
item.__autocomplete_indexName as string
)
const indexLabel =
index === SearchIndexName.Charts
? "Chart"
: index === SearchIndexName.Explorers
? "Explorer"
: pageTypeDisplayNames[item.type as PageType]
index === SearchIndexName.Charts ? (
"Chart"
) : index === SearchIndexName.Explorers ? (
"Explorer"
) : index === SearchIndexName.ExplorerViews ? (
<>
in <em>{item.explorerTitle} Data Explorer</em>
</>
) : (
pageTypeDisplayNames[item.type as PageType]
)

const mainAttribute =
index === SearchIndexName.ExplorerViews ? "viewTitle" : "title"

return (
<div
Expand All @@ -164,7 +186,7 @@ const AlgoliaSource: AutocompleteSource<BaseItem> = {
<span>
<components.Highlight
hit={item}
attribute="title"
attribute={mainAttribute}
tagName="strong"
/>
</span>
Expand Down

0 comments on commit 84a9479

Please sign in to comment.