Skip to content

Commit

Permalink
boost "What is ..." questions in baseline search results
Browse files Browse the repository at this point in the history
  • Loading branch information
Aprillion committed Jul 29, 2023
1 parent 1bc5b68 commit 8101d25
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/hooks/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ export const baselineSearch = async (
fullRe: new RegExp(`\\b${token}\\b`),
prefixRe: new RegExp(`\\b${token}`),
}))
const totalWeight = matchers.reduce((acc, {weight}) => acc + weight, 0.1) // extra total to only approach 100%
const isDefinitionRe = /^what (?:is|are)/
const totalWeight = matchers.reduce((acc, {weight}) => acc + weight, 0.1) // extra total to avoid division by 0

const scoringFn = (questionNormalized: string) => {
let score = 0
let score = isDefinitionRe.exec(questionNormalized) ? 0.1 : 0 // small boost to "What is x?" questions if there are many search results
let prevPosition = -1
for (const {weight, fullRe, prefixRe} of matchers) {
const fullMatch = fullRe.exec(questionNormalized)
Expand Down

0 comments on commit 8101d25

Please sign in to comment.