Skip to content

Commit

Permalink
add alternate phrasings to base search #321
Browse files Browse the repository at this point in the history
  • Loading branch information
Aprillion committed Sep 23, 2023
1 parent c077070 commit 0b902a6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/hooks/search.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {useState, useEffect, useRef, MutableRefObject} from 'react'
import {Question} from '~/server-utils/stampy'

export type Question = {
export type SearchResult = {
pageid: string
title: string
}
export type SearchResult = Question & {
score: number
model: string
url?: string
Expand Down Expand Up @@ -76,8 +75,8 @@ export const baselineSearch = async (
}

return questions
.map(({pageid, title}) => {
const normalized = normalize(title)
.map(({pageid, title, alternatePhrasings = ''}) => {
const normalized = normalize(`${title}\n${alternatePhrasings}`)
return {
pageid,
title,
Expand All @@ -97,7 +96,9 @@ export const baselineSearch = async (
const normalize = (question: string) =>
question
.toLowerCase()
.replace(/\n/g, ' ')
.replace(/[^\w ]|\b(?:an?|the?)\b/g, '')
.replace(/ies\b/g, 'y')
.replace(/(\w{2})s\b/g, '$1') // cannot use lookbehind (?<=...) because not supported on Safari
.replace(/\s+|_|&\s*/g, ' ')
.trim()
Expand Down
4 changes: 4 additions & 0 deletions app/root.css
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,10 @@ footer > *:not(:last-child) {
margin-top: 10px;
}

.dropdown {
min-height: 65px;
}

.dropdown div {
color: var(--colorText);
background-color: var(--bgColorQuestionAnswer);
Expand Down
2 changes: 2 additions & 0 deletions app/server-utils/stampy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export type Question = {
banners: Banner[]
status?: QuestionStatus
updatedAt?: string
alternatePhrasings?: string
}
export type PageId = Question['pageid']
export type NewQuestion = {
Expand Down Expand Up @@ -280,6 +281,7 @@ const convertToQuestion = ({name, values, updatedAt} = {} as AnswersRow): Questi
: [],
status: values['Status']?.name as QuestionStatus,
updatedAt,
alternatePhrasings: extractText(values['Alternate Phrasings']),
})

export const loadQuestionDetail = withCache('questionDetail', async (question: string) => {
Expand Down

0 comments on commit 0b902a6

Please sign in to comment.