Skip to content

Commit

Permalink
🎉 add config for ExplorerViewsAndCharts index
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Nov 5, 2024
1 parent 2965fb6 commit 79166fa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
34 changes: 34 additions & 0 deletions baker/algolia/configureAlgolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,40 @@ export const configureAlgolia = async () => {
],
})

const explorerViewsAndChartsIndex = client.initIndex(
getIndexName(SearchIndexName.ExplorerViewsAndCharts)
)

await explorerViewsAndChartsIndex.setSettings({
...baseSettings,
searchableAttributes: [
"unordered(title)",
"unordered(slug)",
"unordered(variantName)",
"unordered(subtitle)",
"unordered(tags)",
"unordered(availableEntities)",
],
ranking: ["typo", "words", "exact", "attribute", "custom", "proximity"],
customRanking: [
// For multiple explorer views with the same title, we want to avoid surfacing duplicates.
// So, rank a result with viewTitleIndexWithinExplorer=0 way more highly than one with 1, 2, etc.
"asc(viewTitleIndexWithinExplorer)",
"desc(score)",
"asc(titleLength)",
],
attributesToSnippet: ["subtitle:24"],
attributeForDistinct: "id",
optionalWords: ["vs"],

// These lines below essentially demote matches in the `subtitle` and `availableEntities` fields:
// If we find a match (only) there, then it doesn't count towards `exact`, and is therefore ranked lower.
// We also disable prefix matching and typo tolerance on these.
disableExactOnAttributes: ["tags", "subtitle", "availableEntities"],
disableTypoToleranceOnAttributes: ["subtitle", "availableEntities"],
disablePrefixOnAttributes: ["subtitle"],
})

const synonyms = [
["owid", "our world in data"],
["kids", "children"],
Expand Down
5 changes: 4 additions & 1 deletion baker/algolia/indexExplorerViewsAndChartsToAlgolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import {

function explorerViewRecordToChartRecord(
e: ExplorerViewFinalRecord
): ChartRecord {
): ChartRecord & {
viewTitleIndexWithinExplorer: number
} {
return {
type: ChartRecordType.ExplorerView,
objectID: e.objectID!,
Expand All @@ -37,6 +39,7 @@ function explorerViewRecordToChartRecord(
titleLength: e.titleLength,
numRelatedArticles: 0,
views_7d: e.explorerViews_7d,
viewTitleIndexWithinExplorer: e.viewTitleIndexWithinExplorer,
score: e.score,
}
}
Expand Down

0 comments on commit 79166fa

Please sign in to comment.