diff --git a/baker/algolia/configureAlgolia.ts b/baker/algolia/configureAlgolia.ts index c2fd82757bf..abb42eab36a 100644 --- a/baker/algolia/configureAlgolia.ts +++ b/baker/algolia/configureAlgolia.ts @@ -175,10 +175,10 @@ export const configureAlgolia = async () => { ], ranking: ["typo", "words", "exact", "attribute", "custom", "proximity"], customRanking: [ + "desc(score)", // 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"], diff --git a/baker/algolia/indexExplorerViewsAndChartsToAlgolia.ts b/baker/algolia/indexExplorerViewsAndChartsToAlgolia.ts index 8d49784442a..1614d199d29 100644 --- a/baker/algolia/indexExplorerViewsAndChartsToAlgolia.ts +++ b/baker/algolia/indexExplorerViewsAndChartsToAlgolia.ts @@ -48,10 +48,14 @@ const indexExplorerViewsAndChartsToAlgolia = async () => { } }, db.TransactionCloseMode.Close) - // Scale grapher scores between 0 and 10000, and explorer scores between 0 and 500 - // (Except for the first view of each explorer, which we set to 10000) - // This is because Graphers are generally higher quality than Explorers - const scaledGrapherViews = scaleRecordScores(grapherViews) + // Scale grapher records and the default explorer views between 1000 and 10000, + // Scale the remaining explorer views between 0 and 1000. + // This is because Graphers are generally higher quality than Explorers and we don't want + // the data catalog to smother Grapher results with hundreds of low-quality Explorer results. + const scaledGrapherViews = scaleRecordScores( + grapherViews, + [1000, 10000] + ) const scaledExplorerViews = adaptExplorerViews(explorerViews) const records = [...scaledGrapherViews, ...scaledExplorerViews] diff --git a/baker/algolia/utils/explorerViews.ts b/baker/algolia/utils/explorerViews.ts index 2d1f74ff8b8..84c2037fd4f 100644 --- a/baker/algolia/utils/explorerViews.ts +++ b/baker/algolia/utils/explorerViews.ts @@ -79,7 +79,7 @@ export function explorerViewRecordToChartRecord( /** * Scale explorer record scores then convert them to ChartRecords. * Each explorer has a default view (whichever is defined first in the decision matrix) - * We scale these default view scores between 0 and MAX_SCORE, but the rest we scale between 0 and 500 + * We scale these default view scores between 0 and 10000, but the rest we scale between 0 and 1000 * to bury them under the (higher quality) grapher views in the data catalog. */ export function adaptExplorerViews( @@ -90,8 +90,8 @@ export function adaptExplorerViews( (view) => view.isFirstExplorerView ) return [ - ...scaleRecordScores(firstViews), - ...scaleRecordScores(rest, 500), + ...scaleRecordScores(firstViews, [1000, 10000]), + ...scaleRecordScores(rest, [0, 1000]), ].map(explorerViewRecordToChartRecord) } diff --git a/baker/algolia/utils/shared.ts b/baker/algolia/utils/shared.ts index 4b1f92a6669..0ebc1aef230 100644 --- a/baker/algolia/utils/shared.ts +++ b/baker/algolia/utils/shared.ts @@ -38,16 +38,15 @@ export const processAvailableEntities = ( ) } -export const MAX_SCORE = 10000 - /** - * Scale records' positive scores to be between 0 and MAX_SCORE. + * Scale records' positive scores to be between two numbers. */ export function scaleRecordScores( records: T[], - max = MAX_SCORE + range: [number, number] ): T[] { const scores = records.map((r) => r.score) + const [min, max] = range const maxScore = Math.max(...scores) return records.map((record): T => { // For ExplorerView records, we want to keep negative scores, @@ -55,7 +54,7 @@ export function scaleRecordScores( if (record.score < 0) return record // A value between 0 and 1 const normalized = record.score / maxScore - const scaled = Math.round(normalized * max) + const scaled = Math.round(normalized * (max - min) + min) return { ...record, score: scaled,