Skip to content

Commit

Permalink
feat(website): Case insentive regex for authors (#2491)
Browse files Browse the repository at this point in the history
* add search

* Update _siloDatabaseConfig.tpl

* Function name improvement

* Automated code formatting

---------

Co-authored-by: Cornelius Roemer <cornelius.roemer@gmail.com>
Co-authored-by: Loculus bot <bot@loculus.org>
  • Loading branch information
3 people committed Aug 21, 2024
1 parent d4be3c3 commit 1a955fd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions kubernetes/loculus/templates/_siloDatabaseConfig.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
{{- if .generateIndex }}
generateIndex: {{ .generateIndex }}
{{- end }}
{{- if .lapisAllowsRegexSearch }}
lapisAllowsRegexSearch: {{ .lapisAllowsRegexSearch }}
{{- if eq .type "authors" }}
lapisAllowsRegexSearch: true
{{- end }}
{{- end }}

Expand Down
1 change: 0 additions & 1 deletion kubernetes/loculus/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ defaultOrganismConfig: &defaultOrganismConfig
header: Authors
truncateColumnDisplayTo: 15
ingest: ncbi_submitter_names
lapisAllowsRegexSearch: true
- name: author_affiliations
displayName: Author affiliations
generateIndex: true
Expand Down
4 changes: 2 additions & 2 deletions website/src/components/SearchPage/SearchFullUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ export const InnerSearchFullUI = ({
const detailsHook = hooks.useDetails({}, {});

const lapisSearchParameters = useMemo(() => {
return getLapisSearchParameters(fieldValues, referenceGenomesSequenceNames);
}, [fieldValues, referenceGenomesSequenceNames]);
return getLapisSearchParameters(fieldValues, referenceGenomesSequenceNames, schema);
}, [fieldValues, referenceGenomesSequenceNames, schema]);

useEffect(() => {
aggregatedHook.mutate({
Expand Down
16 changes: 16 additions & 0 deletions website/src/utils/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,29 @@ const textAccessionsToList = (text: string): string[] => {
return accessions;
};

const makeCaseInsensitiveLiteralSubstringRegex = (s: string): string => {
// takes raw string and escapes all special characters and prefixes (?i) for case insensitivity
return `(?i)${s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`;
};

export const getLapisSearchParameters = (
fieldValues: Record<string, any>,
referenceGenomesSequenceNames: ReferenceGenomesSequenceNames,
schema: Schema,
): Record<string, any> => {
const expandedSchema = getMetadataSchemaWithExpandedRanges(schema.metadata);

const sequenceFilters = Object.fromEntries(
Object.entries(fieldValues).filter(([, value]) => value !== undefined && value !== ''),
);
for (const field of expandedSchema) {
if (field.type === 'authors' && sequenceFilters[field.name] !== undefined) {
sequenceFilters[field.name.concat('$regex')] = makeCaseInsensitiveLiteralSubstringRegex(
sequenceFilters[field.name],
);
delete sequenceFilters[field.name];
}
}

if (sequenceFilters.accession !== '' && sequenceFilters.accession !== undefined) {
sequenceFilters.accession = textAccessionsToList(sequenceFilters.accession);
Expand Down
2 changes: 1 addition & 1 deletion website/src/utils/serversideSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const performLapisSearchQueries = async (
organism: string,
): Promise<SearchResponse> => {
const fieldValues = getFieldValuesFromQuery(state, hiddenFieldValues, schema);
const lapisSearchParameters = getLapisSearchParameters(fieldValues, referenceGenomesSequenceNames);
const lapisSearchParameters = getLapisSearchParameters(fieldValues, referenceGenomesSequenceNames, schema);

const orderByField = ORDER_KEY in state ? state[ORDER_KEY] : schema.defaultOrderBy;
const orderDirection = state[ORDER_DIRECTION_KEY] ?? schema.defaultOrder;
Expand Down

0 comments on commit 1a955fd

Please sign in to comment.