Skip to content

Commit

Permalink
Merge pull request #2932 from ehavener/bug/search-by-sex-multi-match
Browse files Browse the repository at this point in the history
Fixes search by sex not catching 'M' and 'F' in participants.tsv
  • Loading branch information
nellh authored Nov 1, 2023
2 parents cd48eef + c0c9f3a commit d0e6723
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
16 changes: 16 additions & 0 deletions packages/openneuro-app/src/scripts/search/es-query-builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ export const matchQuery = (
},
})

export const multiMatchQuery = (
field: string,
queryStrings: string[],
fuzziness?: string,
operator?: string,
) => {
return {
bool: {
should: queryStrings.map(queryString =>
matchQuery(field, queryString, fuzziness, operator),
),
minimum_should_match: 1,
},
}
}

export const rangeQuery = (
field,
gte?: number | string,
Expand Down
17 changes: 15 additions & 2 deletions packages/openneuro-app/src/scripts/search/use-search-results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BoolQuery,
simpleQueryString,
matchQuery,
multiMatchQuery,
rangeQuery,
rangeListLengthQuery,
sqsJoinWithAND,
Expand Down Expand Up @@ -239,11 +240,23 @@ export const useSearchResults = () => {
'3',
),
)
if (sex_selected !== 'All')
if (sex_selected !== 'All') {
// Possible values for this field are specified here:
// https://bids-specification.readthedocs.io/en/stable/glossary.html#objects.columns.sex
let queryStrings = []
if (sex_selected == 'Male') {
queryStrings = ['male', 'm', 'M', 'MALE', 'Male']
} else if (sex_selected == 'Female') {
queryStrings = ['female', 'f', 'F', 'FEMALE', 'Female']
}
boolQuery.addClause(
'filter',
matchQuery('latestSnapshot.summary.subjectMetadata.sex', sex_selected),
multiMatchQuery(
'latestSnapshot.summary.subjectMetadata.sex',
queryStrings,
),
)
}
if (date_selected !== 'All Time') {
let d: number
if (date_selected === 'Last 30 days') {
Expand Down

0 comments on commit d0e6723

Please sign in to comment.