Skip to content

Commit

Permalink
Merge pull request #288 from StampyAI/search-what-is
Browse files Browse the repository at this point in the history
boost "What is ..." questions in baseline search results
  • Loading branch information
Aprillion authored Jul 29, 2023
2 parents 1bc5b68 + 8101d25 commit a1e8cb9
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 a1e8cb9

Please sign in to comment.