Skip to content

Commit

Permalink
enhance(algolia): rank by viewTitleIndexWithinExplorer
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Apr 2, 2024
1 parent 77be58b commit 3feb186
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 10 additions & 3 deletions baker/algolia/configureAlgolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,17 @@ export const configureAlgolia = async () => {
searchableAttributes: [
"unordered(viewTitle)",
"unordered(viewSettings)",
"unordered(explorerTitle)",
],
customRanking: ["desc(score)", "asc(viewIndexWithinExplorer)"],
attributeForDistinct: "viewTitleAndExplorerSlug",
distinct: true,
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(viewIndexWithinExplorer)",
],
attributeForDistinct: "explorerSlug",
distinct: 4,
minWordSizefor1Typo: 6,
})

Expand Down
9 changes: 6 additions & 3 deletions baker/algolia/indexExplorerViewsToAlgolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ const explorerChoiceToViewSettings = (
})
}

const computeScore = (record: Partial<ExplorerViewEntryWithExplorerInfo>) =>
const computeScore = (
record: Omit<ExplorerViewEntry, "viewTitleIndexWithinExplorer"> &
Partial<ExplorerViewEntryWithExplorerInfo>
) =>
(record.explorerViews_7d ?? 0) * 10 -
(record.numNonDefaultSettings ?? 0) * 50 -
(record.titleLength ?? 0)
record.numNonDefaultSettings * 50 -
record.titleLength

const getExplorerViewRecordsForExplorerSlug = async (
trx: db.KnexReadonlyTransaction,
Expand Down

0 comments on commit 3feb186

Please sign in to comment.