Skip to content

Commit

Permalink
fix: don't show empty cards on highlights search
Browse files Browse the repository at this point in the history
  • Loading branch information
ewan-escience committed Aug 7, 2024
1 parent e5a8cfc commit 217e789
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion database/104-software-views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ SELECT
software_highlight.position
FROM
software_search(search)
RIGHT JOIN
INNER JOIN
software_highlight ON software_search.id=software_highlight.software
;
$$;
Expand Down
33 changes: 21 additions & 12 deletions frontend/utils/postgrestUrl.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// SPDX-FileCopyrightText: 2021 - 2023 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2021 - 2023 dv4all
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all)
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <christian.meessen@gfz-potsdam.de>
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
//
// SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -182,7 +183,15 @@ export function paginationUrlParams({rows=12, page=0}:
* Provides basic url query string for postgrest endpoints
*/
export function baseQueryString(props: baseQueryStringProps) {
const {keywords,domains,prog_lang,licenses,organisations,project_status,order,limit,offset} = props
const {keywords,
domains,
prog_lang,
licenses,
organisations,
project_status,
order,
limit,
offset} = props
let query
// console.group('baseQueryString')
// console.log('keywords...', keywords)
Expand All @@ -192,7 +201,7 @@ export function baseQueryString(props: baseQueryStringProps) {
// console.log('limit...', limit)
// console.log('offset...', offset)
// filter on keywords using AND
if (typeof keywords !== 'undefined' &&
if (keywords !== undefined &&
keywords !== null &&
typeof keywords === 'object') {
// sort and convert keywords array to comma separated string
Expand All @@ -204,7 +213,7 @@ export function baseQueryString(props: baseQueryStringProps) {
// use cs. command to find
query = `keywords=cs.%7B${keywordsAll}%7D`
}
if (typeof domains !== 'undefined' &&
if (domains !== undefined &&
domains !== null &&
typeof domains === 'object') {
// sort and convert research domains array to comma separated string
Expand All @@ -217,7 +226,7 @@ export function baseQueryString(props: baseQueryStringProps) {
query = `research_domain=cs.%7B${domainsAll}%7D`
}
}
if (typeof prog_lang !== 'undefined' &&
if (prog_lang !== undefined &&
prog_lang !== null &&
typeof prog_lang === 'object') {
// sort and convert prog_lang array to comma separated string
Expand All @@ -233,7 +242,7 @@ export function baseQueryString(props: baseQueryStringProps) {
query = `prog_lang=cs.%7B${languagesAll}%7D`
}
}
if (typeof licenses !== 'undefined' &&
if (licenses !== undefined &&
licenses !== null &&
typeof licenses === 'object') {
// sort and convert array to comma separated string
Expand All @@ -245,7 +254,7 @@ export function baseQueryString(props: baseQueryStringProps) {
query = `licenses=cs.%7B${licensesAll}%7D`
}
}
if (typeof organisations !== 'undefined' &&
if (organisations !== undefined &&
organisations !== null &&
typeof organisations === 'object') {
// sort and convert array to comma separated string
Expand All @@ -258,7 +267,7 @@ export function baseQueryString(props: baseQueryStringProps) {
query = `participating_organisations=cs.%7B${organisationsAll}%7D`
}
}
if (typeof project_status !== 'undefined' &&
if (project_status !== undefined &&
project_status !== null) {
// show records with any of project_status values from the filter
const encodedStatus = encodeURIComponent(project_status)
Expand All @@ -278,9 +287,9 @@ export function baseQueryString(props: baseQueryStringProps) {
}
// add limit and offset
if (query) {
query += `&limit=${limit || rowsPerPageOptions[0]}&offset=${offset || 0}`
query += `&limit=${limit ?? rowsPerPageOptions[0]}&offset=${offset ?? 0}`
} else {
query = `limit=${limit || rowsPerPageOptions[0]}&offset=${offset || 0}`
query = `limit=${limit ?? rowsPerPageOptions[0]}&offset=${offset ?? 0}`
}
// console.log('query...', query)
// console.groupEnd()
Expand Down Expand Up @@ -316,9 +325,9 @@ export function highlightsListUrl(props: PostgrestParams) {
if (search) {
// console.log('softwareListUrl...keywords...', props.keywords)
const encodedSearch = encodeURIComponent(search)
// search query is performed in software_search RPC
// search query is performed in highlight_search RPC
// we search in title,subtitle,slug,keywords_text and prog_lang
// check rpc in 105-project-views.sql for exact filtering
// check rpc in 104-software-views.sql for exact filtering
query += `&search=${encodedSearch}`

const url = `${baseUrl}/rpc/highlight_search?${query}`
Expand Down

0 comments on commit 217e789

Please sign in to comment.