Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed global search #498

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.mskcc.oncokb.curation.service;

import jakarta.persistence.criteria.JoinType;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import org.mskcc.oncokb.curation.domain.*; // for static metamodels
import org.mskcc.oncokb.curation.domain.Drug;
import org.mskcc.oncokb.curation.repository.DrugRepository;
Expand All @@ -10,6 +12,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -96,8 +99,13 @@ protected Specification<Drug> createSpecification(DrugCriteria criteria) {
if (criteria.getId() != null) {
specification = specification.or(buildRangeSpecification(criteria.getId(), Drug_.id));
}
if (criteria.getName() != null) {
specification = specification.or(buildStringSpecification(criteria.getName(), Drug_.name));
if (criteria.getName() != null && criteria.getName().getContains() != null) {
specification = specification.or((root, _ignore, cb) -> {
return cb.like(
cb.lower(root.get(Drug_.name).as(String.class)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MySQL LIKE operator should already compare ignoring case right? Does that mean we don't need cb.lower(root.get(Drug_.name).as(String.class)), instead we can trim to just root.get(Drug_.name).as(String.class)?

"%" + criteria.getName().getContains().toLowerCase() + "%"
);
});
}
if (criteria.getUuid() != null) {
specification = specification.or(buildStringSpecification(criteria.getUuid(), Drug_.uuid));
Expand Down
24 changes: 17 additions & 7 deletions src/main/webapp/app/shared/search/GeneralSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import axiosInstance from '../api/axiosInstance';
import { SearchControllerApi, SearchResultDTO } from '../api/generated/curation';
import DefaultTooltip from '../tooltip/DefaultTooltip';
import { SearchOption } from './SearchOptions';
import { notifyError } from 'app/oncokb-commons/components/util/NotificationUtils';

type AsyncSelectProps = Parameters<typeof AsyncSelect<SearchResultOption>>[0];
type AsyncSelectComponents = NonNullable<AsyncSelectProps['components']>;

export const SearchResultKeys: { [key in keyof SearchResultDTO]: SearchOptionType } = {
companionDiagnosticDevices: SearchOptionType.CDX,
Expand All @@ -20,12 +24,13 @@ export const SearchResultKeys: { [key in keyof SearchResultDTO]: SearchOptionTyp
};

type SearchResultOption = { value: unknown[]; type: SearchOptionType | undefined };
type SearchResultGroup = { label: SearchOptionType; options: SearchResultOption[] };

const getSearchResults = async (search: string) => {
if (search) {
const searchApiClient = new SearchControllerApi(undefined, '', axiosInstance);
const searchResults: SearchResultDTO = (await searchApiClient.search(search)).data;
const searchOptions: { label: SearchOptionType; options: SearchResultOption[] }[] = [
const searchOptions: SearchResultGroup[] = [
{ label: SearchOptionType.GENE, options: [] },
{ label: SearchOptionType.ALTERATION, options: [] },
{ label: SearchOptionType.ARTICLE, options: [] },
Expand All @@ -41,15 +46,20 @@ const getSearchResults = async (search: string) => {
});
}
return searchOptions;
} else {
return [];
}
};

const debouncedSearch = _.debounce((searchTerm, callback) => {
const debouncedSearch = _.debounce<NonNullable<AsyncSelectProps['loadOptions']>>((searchTerm, callback) => {
getSearchResults(searchTerm)
.then(result => {
return callback(result);
})
.catch((error: any) => callback(error, null));
.catch((error: Error) => {
notifyError(error, 'Error in global search');
return callback([]);
});
}, 500);

const SearchInfoIconOverlay: JSX.Element = (
Expand Down Expand Up @@ -79,17 +89,17 @@ const SearchInfoIconOverlay: JSX.Element = (
export const GeneralSearch = () => {
const [search, setSearch] = useState('');

const Option: React.FunctionComponent<any> = (optionProps: any) => {
const Option: AsyncSelectComponents['Option'] = optionProps => {
return (
<>
<components.Option {...optionProps}>
<SearchOption search={search} type={optionProps.data.type as SearchOptionType} data={optionProps.data.value} />
<SearchOption search={search} type={optionProps.data.type!} data={optionProps.data.value} />
</components.Option>
</>
);
};

const GroupHeading: React.FunctionComponent<any> = (groupHeadingProps: any) => {
const GroupHeading: AsyncSelectComponents['GroupHeading'] = groupHeadingProps => {
return (
<>
<components.GroupHeading {...groupHeadingProps}>
Expand All @@ -103,7 +113,7 @@ export const GeneralSearch = () => {
return (
<div style={{ display: 'flex' }}>
<div style={{ flex: 1 }}>
<AsyncSelect
<AsyncSelect<SearchResultOption>
placeholder={'Search Gene / Alteration / Article / Drug / CDx / Fda Submission'}
styles={{
input(styles) {
Expand Down