From 8101d25c1c0128f33a88e7e94d4ef52266deb033 Mon Sep 17 00:00:00 2001 From: Aprillion Date: Sat, 29 Jul 2023 08:40:05 +0200 Subject: [PATCH] boost "What is ..." questions in baseline search results --- app/hooks/search.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/hooks/search.tsx b/app/hooks/search.tsx index a6af27f0..9b1e54b3 100644 --- a/app/hooks/search.tsx +++ b/app/hooks/search.tsx @@ -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)