From 1fccce61caceac6264781ffaaa6ecad1d19c3f78 Mon Sep 17 00:00:00 2001 From: michaelwenk Date: Wed, 23 Oct 2024 11:55:58 +0200 Subject: [PATCH] chore: improve search request speed by passing accession and score only --- api/openapi.yml | 6 +- api/schemas/SearchResult.yaml | 6 +- cmd/mb3server/api/openapi.yaml | 349 +----------------- cmd/mb3server/src/api-impl.go | 98 ++--- cmd/mb3server/src/api.go | 4 +- cmd/mb3server/src/api_default.go | 10 +- cmd/mb3server/src/api_default_service.go | 6 +- .../src/model_search_result_data_inner.go | 7 +- pkg/database/db_interface.go | 2 +- pkg/database/postgres.go | 16 +- .../routes/pages/content/ContentView.tsx | 17 +- .../routes/pages/search/SearchView.tsx | 14 +- web-frontend/src/types/SearchResult.d.ts | 4 +- web-frontend/src/types/SearchResultData.d.ts | 6 - 14 files changed, 74 insertions(+), 471 deletions(-) delete mode 100644 web-frontend/src/types/SearchResultData.d.ts diff --git a/api/openapi.yml b/api/openapi.yml index db61328..e0e7cf3 100644 --- a/api/openapi.yml +++ b/api/openapi.yml @@ -210,11 +210,11 @@ paths: $ref: "./schemas/FilterSchemas.yaml#/components/schemas/Substructure" required: false get: - summary: Get a list of records as a search result in a specific format (accession, title, peaks, smiles, similarity search result) - operationId: getSearchRecords + summary: Get a list of records as a search result in a specific format (accession, similarity score) + operationId: getSearchResults responses: "200": - description: "A list of simple records as a search result" + description: "A list of search results" content: application/json: schema: diff --git a/api/schemas/SearchResult.yaml b/api/schemas/SearchResult.yaml index 077375a..c113662 100644 --- a/api/schemas/SearchResult.yaml +++ b/api/schemas/SearchResult.yaml @@ -8,9 +8,9 @@ properties: items: type: object properties: - record: - description: MassBank record as a search result. - $ref: "./MBRecord.yaml" + accession: + description: The accession id of the record. + type: string score: description: Similarity score to the query spectrum. type: number diff --git a/cmd/mb3server/api/openapi.yaml b/cmd/mb3server/api/openapi.yaml index 9db1d76..4c17a42 100644 --- a/cmd/mb3server/api/openapi.yaml +++ b/cmd/mb3server/api/openapi.yaml @@ -143,7 +143,7 @@ paths: summary: Get a list of records /records/search: get: - operationId: getSearchRecords + operationId: getSearchResults parameters: - description: "Filter by a list of instrument type, which will be associated\ \ by OR." @@ -289,9 +289,9 @@ paths: application/json: schema: $ref: '#/components/schemas/SearchResult' - description: A list of simple records as a search result + description: A list of search results summary: "Get a list of records as a search result in a specific format (accession,\ - \ title, peaks, smiles, similarity search result)" + \ similarity score)" /records/{accession}: get: operationId: getRecord @@ -686,7 +686,7 @@ components: - title type: object PeakListThreshold: - default: 0.7 + default: 0.8 format: double maximum: 1.0 minimum: 0.0 @@ -697,229 +697,9 @@ components: example: data: - score: 0.8008281904610115 - record: - date: - created: 2000-01-23 - modified: 2000-01-23 - updated: 2000-01-23 - copyright: copyright - comments: - - MBRecord_comments_inner - - MBRecord_comments_inner - mass_spectrometry: - focused_ion: - - subtag: BASE_PEAK - value: value - - subtag: BASE_PEAK - value: value - data_processing: - - subtag: COMMENT - value: value - - subtag: COMMENT - value: value - deprecated: - date: 2000-01-23 - reason: reason - project: project - accession: accession - peak: - annotation: - values: - - - values - - values - - - values - - values - header: - - header - - header - peak: - values: - - intensity: 5.962133916683182 - rel: 563 - mz: 1.4658129805029452 - - intensity: 5.962133916683182 - rel: 563 - mz: 1.4658129805029452 - header: - - header - - header - splash: splash - numPeak: 1 - title: title - compound: - names: - - names - - names - inchi: inchi - smiles: smiles - classes: - - classes - - classes - mass: 0.8008281904610115 - link: - - identifier: identifier - database: CAS - - identifier: identifier - database: CAS - formula: formula - license: CC0 - species: - lineage: - - lineage - - lineage - name: name - link: - - identifier: identifier - database: CAS - - identifier: identifier - database: CAS - sample: - - sample - - sample - publication: publication - acquisition: - general: - - subtag: CONCENTRATION - value: value - - subtag: CONCENTRATION - value: value - ion_mobility: - - subtag: CCS - value: value - - subtag: CCS - value: value - mass_spectrometry: - ms_type: MS - subtags: - - subtag: MS_TYPE - value: value - - subtag: MS_TYPE - value: value - ion_mode: POSITIVE - chromatography: - - subtag: CARRIER_GAS - value: value - - subtag: CARRIER_GAS - value: value - instrument: instrument - instrument_type: instrument_type - authors: - - name: name - marc-relator: abr - - name: name - marc-relator: abr + accession: accession - score: 0.8008281904610115 - record: - date: - created: 2000-01-23 - modified: 2000-01-23 - updated: 2000-01-23 - copyright: copyright - comments: - - MBRecord_comments_inner - - MBRecord_comments_inner - mass_spectrometry: - focused_ion: - - subtag: BASE_PEAK - value: value - - subtag: BASE_PEAK - value: value - data_processing: - - subtag: COMMENT - value: value - - subtag: COMMENT - value: value - deprecated: - date: 2000-01-23 - reason: reason - project: project - accession: accession - peak: - annotation: - values: - - - values - - values - - - values - - values - header: - - header - - header - peak: - values: - - intensity: 5.962133916683182 - rel: 563 - mz: 1.4658129805029452 - - intensity: 5.962133916683182 - rel: 563 - mz: 1.4658129805029452 - header: - - header - - header - splash: splash - numPeak: 1 - title: title - compound: - names: - - names - - names - inchi: inchi - smiles: smiles - classes: - - classes - - classes - mass: 0.8008281904610115 - link: - - identifier: identifier - database: CAS - - identifier: identifier - database: CAS - formula: formula - license: CC0 - species: - lineage: - - lineage - - lineage - name: name - link: - - identifier: identifier - database: CAS - - identifier: identifier - database: CAS - sample: - - sample - - sample - publication: publication - acquisition: - general: - - subtag: CONCENTRATION - value: value - - subtag: CONCENTRATION - value: value - ion_mobility: - - subtag: CCS - value: value - - subtag: CCS - value: value - mass_spectrometry: - ms_type: MS - subtags: - - subtag: MS_TYPE - value: value - - subtag: MS_TYPE - value: value - ion_mode: POSITIVE - chromatography: - - subtag: CARRIER_GAS - value: value - - subtag: CARRIER_GAS - value: value - instrument: instrument - instrument_type: instrument_type - authors: - - name: name - marc-relator: abr - - name: name - marc-relator: abr + accession: accession properties: data: description: A list of records as a search result with similarity score @@ -1471,120 +1251,11 @@ components: SearchResult_data_inner: example: score: 0.8008281904610115 - record: - date: - created: 2000-01-23 - modified: 2000-01-23 - updated: 2000-01-23 - copyright: copyright - comments: - - MBRecord_comments_inner - - MBRecord_comments_inner - mass_spectrometry: - focused_ion: - - subtag: BASE_PEAK - value: value - - subtag: BASE_PEAK - value: value - data_processing: - - subtag: COMMENT - value: value - - subtag: COMMENT - value: value - deprecated: - date: 2000-01-23 - reason: reason - project: project - accession: accession - peak: - annotation: - values: - - - values - - values - - - values - - values - header: - - header - - header - peak: - values: - - intensity: 5.962133916683182 - rel: 563 - mz: 1.4658129805029452 - - intensity: 5.962133916683182 - rel: 563 - mz: 1.4658129805029452 - header: - - header - - header - splash: splash - numPeak: 1 - title: title - compound: - names: - - names - - names - inchi: inchi - smiles: smiles - classes: - - classes - - classes - mass: 0.8008281904610115 - link: - - identifier: identifier - database: CAS - - identifier: identifier - database: CAS - formula: formula - license: CC0 - species: - lineage: - - lineage - - lineage - name: name - link: - - identifier: identifier - database: CAS - - identifier: identifier - database: CAS - sample: - - sample - - sample - publication: publication - acquisition: - general: - - subtag: CONCENTRATION - value: value - - subtag: CONCENTRATION - value: value - ion_mobility: - - subtag: CCS - value: value - - subtag: CCS - value: value - mass_spectrometry: - ms_type: MS - subtags: - - subtag: MS_TYPE - value: value - - subtag: MS_TYPE - value: value - ion_mode: POSITIVE - chromatography: - - subtag: CARRIER_GAS - value: value - - subtag: CARRIER_GAS - value: value - instrument: instrument - instrument_type: instrument_type - authors: - - name: name - marc-relator: abr - - name: name - marc-relator: abr + accession: accession properties: - record: - $ref: '#/components/schemas/MBRecord' + accession: + description: The accession id of the record. + type: string score: description: Similarity score to the query spectrum. type: number diff --git a/cmd/mb3server/src/api-impl.go b/cmd/mb3server/src/api-impl.go index bdcc0d5..a2f5b38 100644 --- a/cmd/mb3server/src/api-impl.go +++ b/cmd/mb3server/src/api-impl.go @@ -491,7 +491,7 @@ func GetRecords(instrumentType []string, splash string, msType []string, ionMode -func GetSearchRecords(instrumentType []string, splash string, msType []string, ionMode string, compoundName string, exactMass string, massTolerance float64, formula string, peaks []string, intensity int32, peakDifferences []string, peakList []string, peakListThreshold float64, inchi string, inchiKey string, contributor []string, substructure string) (*SearchResult, error) { +func GetSearchResults(instrumentType []string, splash string, msType []string, ionMode string, compoundName string, exactMass string, massTolerance float64, formula string, peaks []string, intensity int32, peakDifferences []string, peakList []string, peakListThreshold float64, inchi string, inchiKey string, contributor []string, substructure string) (*SearchResult, error) { if err := initDB(); err != nil { return nil, err } @@ -567,13 +567,9 @@ func GetSearchRecords(instrumentType []string, splash string, msType []string, i if(checkSubstructure && checkSimilarity && checkFilters) { fmt.Println(" -> combined results (substructure + similarity + filters)") intersection := setSubstructureSearch.Intersect(setSimilaritySearch).Intersect(setFilterSearch) - for _, accession := range intersection.ToSlice() { - record, err := db.GetSimpleRecord(&accession) - if err != nil { - return nil, err - } + for _, accession := range intersection.ToSlice() { searchResultData := SearchResultDataInner{ - Record: *buildSimpleMbRecord(record), + Accession: accession, Score: similarityResultMap[accession], } results.Data = append(results.Data, searchResultData) @@ -584,13 +580,9 @@ func GetSearchRecords(instrumentType []string, splash string, msType []string, i } else if(checkSubstructure && checkSimilarity && !checkFilters) { fmt.Println(" -> combined results (substructure + similarity)") intersection := setSubstructureSearch.Intersect(setSimilaritySearch) - for _, accession := range intersection.ToSlice() { - record, err := db.GetSimpleRecord(&accession) - if err != nil { - return nil, err - } + for _, accession := range intersection.ToSlice() { searchResultData := SearchResultDataInner{ - Record: *buildSimpleMbRecord(record), + Accession: accession, Score: similarityResultMap[accession], } results.Data = append(results.Data, searchResultData) @@ -601,26 +593,18 @@ func GetSearchRecords(instrumentType []string, splash string, msType []string, i } else if(checkSubstructure && !checkSimilarity && checkFilters) { fmt.Println(" -> combined results (substructure + filters)") intersection := setSubstructureSearch.Intersect(setFilterSearch) - for _, accession := range intersection.ToSlice() { - record, err := db.GetSimpleRecord(&accession) - if err != nil { - return nil, err - } + for _, accession := range intersection.ToSlice() { searchResultData := SearchResultDataInner{ - Record: *buildSimpleMbRecord(record), + Accession: accession, } results.Data = append(results.Data, searchResultData) } } else if(!checkSubstructure && checkSimilarity && checkFilters) { fmt.Println(" -> combined results (similarity + filters)") intersection := setSimilaritySearch.Intersect(setFilterSearch) - for _, accession := range intersection.ToSlice() { - record, err := db.GetSimpleRecord(&accession) - if err != nil { - return nil, err - } + for _, accession := range intersection.ToSlice() { searchResultData := SearchResultDataInner{ - Record: *buildSimpleMbRecord(record), + Accession: accession, Score: similarityResultMap[accession], } results.Data = append(results.Data, searchResultData) @@ -631,36 +615,20 @@ func GetSearchRecords(instrumentType []string, splash string, msType []string, i } else { fmt.Println("no combined results found -> single results") if(checkSimilarity && !checkFilters && !checkSubstructure) { - for _, similarityResult := range similaritySearchResult.Data { - record, err := db.GetSimpleRecord(&similarityResult.Accession) - if err != nil { - return nil, err - } - searchResultData := SearchResultDataInner{ - Record: *buildSimpleMbRecord(record), - Score: similarityResult.Score, - } - results.Data = append(results.Data, searchResultData) + for _, similarityResult := range similaritySearchResult.Data { + results.Data = append(results.Data, SearchResultDataInner(similarityResult)) } } else if(checkFilters && !checkSimilarity && !checkSubstructure) { - for _, accession := range accessionsFilters { - record, err := db.GetSimpleRecord(&accession) - if err != nil { - return nil, err - } + for _, accession := range accessionsFilters { searchResultData := SearchResultDataInner{ - Record: *buildSimpleMbRecord(record), + Accession: accession, } results.Data = append(results.Data, searchResultData) } } else if(checkSubstructure && !checkSimilarity && !checkFilters) { - for _, accession := range accessionsSubstructureSearch { - record, err := db.GetSimpleRecord(&accession) - if err != nil { - return nil, err - } + for _, accession := range accessionsSubstructureSearch { searchResultData := SearchResultDataInner{ - Record: *buildSimpleMbRecord(record), + Accession: accession, } results.Data = append(results.Data, searchResultData) } @@ -679,28 +647,28 @@ func getEnv(name string, fallback string) string { return fallback } -func FilterBySubstructure(substructure string) (*SearchResult, error) { - if err := initDB(); err != nil { - return nil, err - } +// func FilterBySubstructure(substructure string) (*SearchResult, error) { +// if err := initDB(); err != nil { +// return nil, err +// } - result := SearchResult{} - result.Data = []SearchResultDataInner{} +// result := SearchResult{} +// result.Data = []SearchResultDataInner{} - records, err := db.GetRecordsBySubstructure(substructure) - if err != nil { - return nil, err - } +// records, err := db.GetRecordsBySubstructure(substructure) +// if err != nil { +// return nil, err +// } - for _, record := range *records { - searchResultData := SearchResultDataInner{ - Record: *buildSimpleMbRecord(&record), - } - result.Data = append(result.Data, searchResultData) - } +// for _, record := range *records { +// searchResultData := SearchResultDataInner{ +// Record: *buildSimpleMbRecord(&record), +// } +// result.Data = append(result.Data, searchResultData) +// } - return &result, nil -} +// return &result, nil +// } func GetSimilarity(peakList []string, referenceSpectraList []string, limit int32, threshold float64) (*SimilaritySearchResult, error) { sort.Slice(peakList, func(i, j int) bool { diff --git a/cmd/mb3server/src/api.go b/cmd/mb3server/src/api.go index b3d72a5..fee96ef 100644 --- a/cmd/mb3server/src/api.go +++ b/cmd/mb3server/src/api.go @@ -19,7 +19,7 @@ import ( // pass the data to a DefaultAPIServicer to perform the required actions, then write the service results to the http response. type DefaultAPIRouter interface { GetRecords(http.ResponseWriter, *http.Request) - GetSearchRecords(http.ResponseWriter, *http.Request) + GetSearchResults(http.ResponseWriter, *http.Request) GetRecord(http.ResponseWriter, *http.Request) GetSimpleRecord(http.ResponseWriter, *http.Request) GetCount(http.ResponseWriter, *http.Request) @@ -34,7 +34,7 @@ type DefaultAPIRouter interface { // and updated with the logic required for the API. type DefaultAPIServicer interface { GetRecords(context.Context, []string, string, []string, string, string, string, float64, string, []string, int32, []string, []string, string, string, []string) (ImplResponse, error) - GetSearchRecords(context.Context, []string, string, []string, string, string, string, float64, string, []string, int32, []string, []string, float64, string, string, []string, string) (ImplResponse, error) + GetSearchResults(context.Context, []string, string, []string, string, string, string, float64, string, []string, int32, []string, []string, float64, string, string, []string, string) (ImplResponse, error) GetRecord(context.Context, string) (ImplResponse, error) GetSimpleRecord(context.Context, string) (ImplResponse, error) GetCount(context.Context) (ImplResponse, error) diff --git a/cmd/mb3server/src/api_default.go b/cmd/mb3server/src/api_default.go index 5dc4df2..641e79d 100644 --- a/cmd/mb3server/src/api_default.go +++ b/cmd/mb3server/src/api_default.go @@ -56,10 +56,10 @@ func (c *DefaultAPIController) Routes() Routes { c.GetRecords, }, { - "GetSearchRecords", + "GetSearchResults", strings.ToUpper("Get"), "/v1/records/search", - c.GetSearchRecords, + c.GetSearchResults, }, { "GetRecord", @@ -137,8 +137,8 @@ func (c *DefaultAPIController) GetRecords(w http.ResponseWriter, r *http.Request } -// GetSearchRecords - Get a list of records as a search result in a specific format (accession, title, peaks, smiles, similarity search result) -func (c *DefaultAPIController) GetSearchRecords(w http.ResponseWriter, r *http.Request) { +// GetSearchResults - Get a list of records as a search result in a specific format (accession, similarity score) +func (c *DefaultAPIController) GetSearchResults(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() instrumentTypeParam := strings.Split(query.Get("instrument_type"), ",") splashParam := query.Get("splash") @@ -169,7 +169,7 @@ func (c *DefaultAPIController) GetSearchRecords(w http.ResponseWriter, r *http.R inchiKeyParam := query.Get("inchi_key") contributorParam := strings.Split(query.Get("contributor"), ",") substructureParam := query.Get("substructure") - result, err := c.service.GetSearchRecords(r.Context(), instrumentTypeParam, splashParam, msTypeParam, ionModeParam, compoundNameParam, exactMassParam, massToleranceParam, formulaParam, peaksParam, intensityParam, peakDifferencesParam, peakListParam, peakListThresholdParam, inchiParam, inchiKeyParam, contributorParam, substructureParam) + result, err := c.service.GetSearchResults(r.Context(), instrumentTypeParam, splashParam, msTypeParam, ionModeParam, compoundNameParam, exactMassParam, massToleranceParam, formulaParam, peaksParam, intensityParam, peakDifferencesParam, peakListParam, peakListThresholdParam, inchiParam, inchiKeyParam, contributorParam, substructureParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) diff --git a/cmd/mb3server/src/api_default_service.go b/cmd/mb3server/src/api_default_service.go index b6a0dfb..3aa5538 100644 --- a/cmd/mb3server/src/api_default_service.go +++ b/cmd/mb3server/src/api_default_service.go @@ -98,11 +98,11 @@ func (s *DefaultAPIService) GetSimpleRecord(ctx context.Context, accession strin } // GetSimpleRecords - Get a list of records -func (s *DefaultAPIService) GetSearchRecords(ctx context.Context, instrumentType []string, splash string, msType []string, ionMode string, compoundName string, exactMass string, massTolerance float64, formula string, peaks []string, intensity int32, peakDifferences []string, peakList []string, peakListThreshold float64, inchi string, inchiKey string, contributor []string, substructure string) (ImplResponse, error) { - result, err := GetSearchRecords(instrumentType, splash, msType, ionMode, compoundName, exactMass, massTolerance, formula, peaks, intensity, peakDifferences, peakList, peakListThreshold, inchi, inchiKey, contributor, substructure) +func (s *DefaultAPIService) GetSearchResults(ctx context.Context, instrumentType []string, splash string, msType []string, ionMode string, compoundName string, exactMass string, massTolerance float64, formula string, peaks []string, intensity int32, peakDifferences []string, peakList []string, peakListThreshold float64, inchi string, inchiKey string, contributor []string, substructure string) (ImplResponse, error) { + result, err := GetSearchResults(instrumentType, splash, msType, ionMode, compoundName, exactMass, massTolerance, formula, peaks, intensity, peakDifferences, peakList, peakListThreshold, inchi, inchiKey, contributor, substructure) if err != nil { return Response(http.StatusInternalServerError, nil), err } - return Response(200, result), nil + return Response(200, result), nil } diff --git a/cmd/mb3server/src/model_search_result_data_inner.go b/cmd/mb3server/src/model_search_result_data_inner.go index 39c981d..cf899c3 100644 --- a/cmd/mb3server/src/model_search_result_data_inner.go +++ b/cmd/mb3server/src/model_search_result_data_inner.go @@ -10,7 +10,9 @@ package mb3server type SearchResultDataInner struct { - Record MbRecord `json:"record,omitempty"` + + // The accession id of the record. + Accession string `json:"accession,omitempty"` // Similarity score to the query spectrum. Score float32 `json:"score,omitempty"` @@ -18,9 +20,6 @@ type SearchResultDataInner struct { // AssertSearchResultDataInnerRequired checks if the required fields are not zero-ed func AssertSearchResultDataInnerRequired(obj SearchResultDataInner) error { - if err := AssertMbRecordRequired(obj.Record); err != nil { - return err - } return nil } diff --git a/pkg/database/db_interface.go b/pkg/database/db_interface.go index e86d73f..0cd39a4 100644 --- a/pkg/database/db_interface.go +++ b/pkg/database/db_interface.go @@ -152,7 +152,7 @@ type MB3Database interface { // GetSimpleRecords Get an array of MassBank records by filtering // // Will return an empty list if the filter does not match any records. - GetSearchRecords(filters Filters) (*[]massbank.MassBank2, error) + GetSearchResults(filters Filters) (*[]string, error) // GetRecordsBySubstructure Get an array of MassBank accessions by filtering by substructure // diff --git a/pkg/database/postgres.go b/pkg/database/postgres.go index 31b6cea..a9af945 100644 --- a/pkg/database/postgres.go +++ b/pkg/database/postgres.go @@ -818,9 +818,8 @@ func (p *PostgresSQLDB) GetRecordsBySubstructure(substructure string) (*[]massba return &records, nil } - -// GetSimpleRecords see [MB3Database.GetSimpleRecords] -func (p *PostgresSQLDB) GetSearchRecords(filters Filters) (*[]massbank.MassBank2, error) { +// GetSearchResults see [MB3Database.GetSearchResults] +func (p *PostgresSQLDB) GetSearchResults(filters Filters) (*[]string, error) { if filters.MassEpsilon == nil { filters.MassEpsilon = &DefaultValues.MassEpsilon } @@ -833,16 +832,7 @@ func (p *PostgresSQLDB) GetSearchRecords(filters Filters) (*[]massbank.MassBank2 return nil, err } - records := []massbank.MassBank2{} - for _, accession := range accessions { - record, err := p.GetSimpleRecord(&accession) - if err != nil { - return nil, err - } - records = append(records, *record) - } - - return &records, nil + return &accessions, nil } // BuildSearchOptionsWhere to build the where clause within the browse_options table diff --git a/web-frontend/src/elements/routes/pages/content/ContentView.tsx b/web-frontend/src/elements/routes/pages/content/ContentView.tsx index fbce228..7770028 100644 --- a/web-frontend/src/elements/routes/pages/content/ContentView.tsx +++ b/web-frontend/src/elements/routes/pages/content/ContentView.tsx @@ -12,6 +12,9 @@ import ContentChart from './ContentChart'; import fetchData from '../../../../utils/fetchData'; import buildSearchParams from '../../../../utils/buildSearchParams'; import initFlags from '../../../../utils/initFlags'; +// import Hit from '../../../../types/Hit'; +// import SearchResult from '../../../../types/SearchResult'; +// import ResultPanel from '../../../result/ResultPanel'; function ContentView() { const ref = useRef(null); @@ -43,22 +46,12 @@ function ContentView() { const newContent = (await fetchData(url, searchParams)) as Content; // const url2 = import.meta.env.VITE_MB3_API_URL + '/v1/records/search'; - // const _records = (await fetchData(url2, searchParams)) as SearchResult; - - // const _hits: Hit[] = _records.data - // .map((res: SearchResultData) => res.record) - // .map((r: Record) => { - // const hit: Hit = { - // accession: r.accession, - // record: r, - // }; - // return hit; - // }); + // const result = (await fetchData(url2, searchParams)) as SearchResult; + // const _hits: Hit[] = result.data ? (result.data as Hit[]) : []; initFlags(newContent); setContent(newContent); setContent2({ ...newContent }); - // setHits(_hits); setIsRequesting(false); diff --git a/web-frontend/src/elements/routes/pages/search/SearchView.tsx b/web-frontend/src/elements/routes/pages/search/SearchView.tsx index 80e0e29..f385953 100644 --- a/web-frontend/src/elements/routes/pages/search/SearchView.tsx +++ b/web-frontend/src/elements/routes/pages/search/SearchView.tsx @@ -16,7 +16,6 @@ import buildSearchParams from '../../../../utils/buildSearchParams'; import initFlags from '../../../../utils/initFlags'; import axios from 'axios'; import SearchResult from '../../../../types/SearchResult'; -import SearchResultData from '../../../../types/SearchResultData'; import BasicSearchFilterOptions from '../../../../types/filterOptions/basicSearchFilterOptions'; import parsePeakListInputField from './searchPanel/utils/parsePeakListAndReferences'; import { Molecule } from 'openchemlib'; @@ -147,18 +146,7 @@ function SearchView() { const searchResult = (await fetchData(url, searchParams)) as SearchResult; console.log(searchResult); - const _hits: Hit[] = searchResult.data - ? searchResult.data.map((d: SearchResultData) => { - const hit: Hit = { - record: d.record, - accession: d.record.accession, - score: d.score, - }; - - return hit; - }) - : []; - + const _hits: Hit[] = searchResult.data ? (searchResult.data as Hit[]) : []; setHits(_hits); setIsRequesting(false); diff --git a/web-frontend/src/types/SearchResult.d.ts b/web-frontend/src/types/SearchResult.d.ts index dac4c7b..3ec778d 100644 --- a/web-frontend/src/types/SearchResult.d.ts +++ b/web-frontend/src/types/SearchResult.d.ts @@ -1,5 +1,5 @@ -import SearchResultData from './SearchResultData'; +import Hit from './Hit'; export default interface SearchResult { - data: SearchResultData[]; + data: Hit[]; } diff --git a/web-frontend/src/types/SearchResultData.d.ts b/web-frontend/src/types/SearchResultData.d.ts deleted file mode 100644 index 48c77c4..0000000 --- a/web-frontend/src/types/SearchResultData.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import Record from './Record'; - -export default interface SearchResultData { - record: Record; - score: number; -}