Skip to content

Commit

Permalink
Fix fuzziness to 1 LD, change default to group studies, add just stud…
Browse files Browse the repository at this point in the history
…y_name to subsearch index (remove study_id)
  • Loading branch information
frostyfan109 committed Aug 1, 2024
1 parent 3bc5839 commit 947b9e7
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const VariableViewProvider = ({ children }: VariableViewProviderProps) =>
const [subsearch, setSubsearch] = useState<string>("")
const [sortOption, setSortOption] = useState<string>("score")
const [sortOrderOption, setSortOrderOption] = useState<string>("descending")
const [collapseIntoVariables, setCollapseIntoVariables] = useState<boolean>(true)
const [collapseIntoVariables, setCollapseIntoVariables] = useState<boolean>(false)

const [variableIdMap, studyIdMap] = useMemo<[Map<string, VariableResult>, Map<string, StudyResult>]>(() => {
const variableMap = new Map()
Expand Down Expand Up @@ -198,14 +198,16 @@ export const VariableViewProvider = ({ children }: VariableViewProviderProps) =>
docs: variableDocs,
index: {
ref: "id",
fields: ["id", "name", "description"]
fields: ["id", "name", "description", "study_name"]
}
}), [variableDocs])

const { index, lexicalSearch } = useLunrSearch(lunrConfig)

const [filteredVariables, highlightTokens] = useMemo<[VariableResult[], string[]]>(() => {
const { hits, tokens } = lexicalSearch(subsearch)
const { hits, tokens } = lexicalSearch(subsearch, {
fuzziness: (term: string) => 1
})
const matchedVariables = hits.reduce((acc, { ref: id }) => (acc.add(id), acc), new Set())
const highlightTokens = subsearch.length > 3 ? tokens.map((token) => token.toString()) : []

Expand Down

0 comments on commit 947b9e7

Please sign in to comment.