-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add remote software to global search
- Loading branch information
1 parent
4f72df3
commit f33951c
Showing
6 changed files
with
305 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ | |
-- SPDX-FileCopyrightText: 2022 - 2023 Christian Meeßen (GFZ) <[email protected]> | ||
-- SPDX-FileCopyrightText: 2022 - 2023 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
-- SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
-- SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center | ||
-- SPDX-FileCopyrightText: 2023 - 2024 Dusan Mijatovic (Netherlands eScience Center) | ||
-- SPDX-FileCopyrightText: 2022 - 2025 Netherlands eScience Center | ||
-- SPDX-FileCopyrightText: 2023 - 2025 Dusan Mijatovic (Netherlands eScience Center) | ||
-- | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
@@ -829,135 +829,6 @@ $$ | |
$$; | ||
|
||
|
||
-- GLOBAL SEARCH | ||
CREATE FUNCTION global_search(query VARCHAR) RETURNS TABLE( | ||
slug VARCHAR, | ||
name VARCHAR, | ||
source TEXT, | ||
is_published BOOLEAN, | ||
rank INTEGER, | ||
index_found INTEGER | ||
) LANGUAGE sql STABLE AS | ||
$$ | ||
-- SOFTWARE search item | ||
SELECT | ||
software.slug, | ||
software.brand_name AS name, | ||
'software' AS "source", | ||
software.is_published, | ||
(CASE | ||
WHEN software.slug ILIKE query OR software.brand_name ILIKE query THEN 0 | ||
WHEN BOOL_OR(keyword.value ILIKE query) THEN 1 | ||
WHEN software.slug ILIKE CONCAT(query, '%') OR software.brand_name ILIKE CONCAT(query, '%') THEN 2 | ||
WHEN software.slug ILIKE CONCAT('%', query, '%') OR software.brand_name ILIKE CONCAT('%', query, '%') THEN 3 | ||
ELSE 4 | ||
END) AS rank, | ||
(CASE | ||
WHEN software.slug ILIKE query OR software.brand_name ILIKE query THEN 0 | ||
WHEN BOOL_OR(keyword.value ILIKE query) THEN 0 | ||
WHEN software.slug ILIKE CONCAT(query, '%') OR software.brand_name ILIKE CONCAT(query, '%') THEN 0 | ||
WHEN software.slug ILIKE CONCAT('%', query, '%') OR software.brand_name ILIKE CONCAT('%', query, '%') | ||
THEN LEAST(NULLIF(POSITION(query IN software.slug), 0), NULLIF(POSITION(query IN software.brand_name), 0)) | ||
ELSE 0 | ||
END) AS index_found | ||
FROM | ||
software | ||
LEFT JOIN keyword_for_software ON keyword_for_software.software = software.id | ||
LEFT JOIN keyword ON keyword.id = keyword_for_software.keyword | ||
GROUP BY software.id | ||
HAVING | ||
software.slug ILIKE CONCAT('%', query, '%') | ||
OR | ||
software.brand_name ILIKE CONCAT('%', query, '%') | ||
OR | ||
software.short_statement ILIKE CONCAT('%', query, '%') | ||
OR | ||
BOOL_OR(keyword.value ILIKE CONCAT('%', query, '%')) | ||
UNION ALL | ||
-- PROJECT search item | ||
SELECT | ||
project.slug, | ||
project.title AS name, | ||
'projects' AS "source", | ||
project.is_published, | ||
(CASE | ||
WHEN project.slug ILIKE query OR project.title ILIKE query THEN 0 | ||
WHEN BOOL_OR(keyword.value ILIKE query) THEN 1 | ||
WHEN project.slug ILIKE CONCAT(query, '%') OR project.title ILIKE CONCAT(query, '%') THEN 2 | ||
WHEN project.slug ILIKE CONCAT('%', query, '%') OR project.title ILIKE CONCAT('%', query, '%') THEN 3 | ||
ELSE 4 | ||
END) AS rank, | ||
(CASE | ||
WHEN project.slug ILIKE query OR project.title ILIKE query THEN 0 | ||
WHEN BOOL_OR(keyword.value ILIKE query) THEN 0 | ||
WHEN project.slug ILIKE CONCAT(query, '%') OR project.title ILIKE CONCAT(query, '%') THEN 0 | ||
WHEN project.slug ILIKE CONCAT('%', query, '%') OR project.title ILIKE CONCAT('%', query, '%') | ||
THEN LEAST(NULLIF(POSITION(query IN project.slug), 0), NULLIF(POSITION(query IN project.title), 0)) | ||
ELSE 0 | ||
END) AS index_found | ||
FROM | ||
project | ||
LEFT JOIN keyword_for_project ON keyword_for_project.project = project.id | ||
LEFT JOIN keyword ON keyword.id = keyword_for_project.keyword | ||
GROUP BY project.id | ||
HAVING | ||
project.slug ILIKE CONCAT('%', query, '%') | ||
OR | ||
project.title ILIKE CONCAT('%', query, '%') | ||
OR | ||
project.subtitle ILIKE CONCAT('%', query, '%') | ||
OR | ||
BOOL_OR(keyword.value ILIKE CONCAT('%', query, '%')) | ||
UNION ALL | ||
-- ORGANISATION search item | ||
SELECT | ||
organisation.slug, | ||
organisation."name", | ||
'organisations' AS "source", | ||
TRUE AS is_published, | ||
(CASE | ||
WHEN organisation.slug ILIKE query OR organisation."name" ILIKE query THEN 0 | ||
WHEN organisation.slug ILIKE CONCAT(query, '%') OR organisation."name" ILIKE CONCAT(query, '%') THEN 2 | ||
ELSE 3 | ||
END) AS rank, | ||
(CASE | ||
WHEN organisation.slug ILIKE query OR organisation."name" ILIKE query THEN 0 | ||
WHEN organisation.slug ILIKE CONCAT(query, '%') OR organisation."name" ILIKE CONCAT(query, '%') THEN 0 | ||
ELSE | ||
LEAST(NULLIF(POSITION(query IN organisation.slug), 0), NULLIF(POSITION(query IN organisation."name"), 0)) | ||
END) AS index_found | ||
FROM | ||
organisation | ||
WHERE | ||
-- ONLY TOP LEVEL ORGANISATIONS | ||
organisation.parent IS NULL | ||
AND | ||
(organisation.slug ILIKE CONCAT('%', query, '%') OR organisation."name" ILIKE CONCAT('%', query, '%')) | ||
UNION ALL | ||
-- COMMUNITY search item | ||
SELECT | ||
community.slug, | ||
community."name", | ||
'communities' AS "source", | ||
TRUE AS is_published, | ||
(CASE | ||
WHEN community.slug ILIKE query OR community."name" ILIKE query THEN 0 | ||
WHEN community.slug ILIKE CONCAT(query, '%') OR community."name" ILIKE CONCAT(query, '%') THEN 2 | ||
ELSE 3 | ||
END) AS rank, | ||
(CASE | ||
WHEN community.slug ILIKE query OR community."name" ILIKE query THEN 0 | ||
WHEN community.slug ILIKE CONCAT(query, '%') OR community."name" ILIKE CONCAT(query, '%') THEN 0 | ||
ELSE | ||
LEAST(NULLIF(POSITION(query IN community.slug), 0), NULLIF(POSITION(query IN community."name"), 0)) | ||
END) AS index_found | ||
FROM | ||
community | ||
WHERE | ||
community.slug ILIKE CONCAT('%', query, '%') OR community."name" ILIKE CONCAT('%', query, '%'); | ||
$$; | ||
|
||
|
||
-- Check whether user agreed on Terms of Service and read the Privacy Statement | ||
CREATE FUNCTION user_agreements_stored(account_id UUID) RETURNS BOOLEAN LANGUAGE sql STABLE AS | ||
$$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
-- SPDX-FileCopyrightText: 2025 Dusan Mijatovic (Netherlands eScience Center) | ||
-- SPDX-FileCopyrightText: 2025 Netherlands eScience Center | ||
-- | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
-- GLOBAL SEARCH | ||
-- depends on: aggregated_software_search | ||
CREATE FUNCTION global_search(query VARCHAR) RETURNS TABLE( | ||
slug VARCHAR, | ||
domain VARCHAR, | ||
name VARCHAR, | ||
source TEXT, | ||
is_published BOOLEAN, | ||
rank INTEGER, | ||
index_found INTEGER | ||
) LANGUAGE sql STABLE AS | ||
$$ | ||
-- AGGREGATED SOFTWARE search | ||
SELECT | ||
aggregated_software_search.slug, | ||
aggregated_software_search.domain, | ||
aggregated_software_search.brand_name AS name, | ||
'software' AS "source", | ||
aggregated_software_search.is_published, | ||
(CASE | ||
WHEN aggregated_software_search.slug ILIKE query OR aggregated_software_search.brand_name ILIKE query THEN 0 | ||
WHEN aggregated_software_search.keywords_text ILIKE CONCAT('%', query, '%') THEN 1 | ||
WHEN aggregated_software_search.slug ILIKE CONCAT(query, '%') OR aggregated_software_search.brand_name ILIKE CONCAT(query, '%') THEN 2 | ||
WHEN aggregated_software_search.slug ILIKE CONCAT('%', query, '%') OR aggregated_software_search.brand_name ILIKE CONCAT('%', query, '%') THEN 3 | ||
ELSE 4 | ||
END) AS rank, | ||
(CASE | ||
WHEN aggregated_software_search.slug ILIKE query OR aggregated_software_search.brand_name ILIKE query THEN 0 | ||
WHEN aggregated_software_search.keywords_text ILIKE CONCAT('%', query, '%') THEN 0 | ||
WHEN aggregated_software_search.slug ILIKE CONCAT(query, '%') OR aggregated_software_search.brand_name ILIKE CONCAT(query, '%') THEN 0 | ||
WHEN aggregated_software_search.slug ILIKE CONCAT('%', query, '%') OR aggregated_software_search.brand_name ILIKE CONCAT('%', query, '%') | ||
THEN LEAST(NULLIF(POSITION(query IN aggregated_software_search.slug), 0), NULLIF(POSITION(query IN aggregated_software_search.brand_name), 0)) | ||
ELSE 0 | ||
END) AS index_found | ||
FROM | ||
aggregated_software_search(query) | ||
UNION ALL | ||
-- PROJECT search | ||
SELECT | ||
project.slug, | ||
NULL AS domain, | ||
project.title AS name, | ||
'projects' AS "source", | ||
project.is_published, | ||
(CASE | ||
WHEN project.slug ILIKE query OR project.title ILIKE query THEN 0 | ||
WHEN BOOL_OR(keyword.value ILIKE query) THEN 1 | ||
WHEN project.slug ILIKE CONCAT(query, '%') OR project.title ILIKE CONCAT(query, '%') THEN 2 | ||
WHEN project.slug ILIKE CONCAT('%', query, '%') OR project.title ILIKE CONCAT('%', query, '%') THEN 3 | ||
ELSE 4 | ||
END) AS rank, | ||
(CASE | ||
WHEN project.slug ILIKE query OR project.title ILIKE query THEN 0 | ||
WHEN BOOL_OR(keyword.value ILIKE query) THEN 0 | ||
WHEN project.slug ILIKE CONCAT(query, '%') OR project.title ILIKE CONCAT(query, '%') THEN 0 | ||
WHEN project.slug ILIKE CONCAT('%', query, '%') OR project.title ILIKE CONCAT('%', query, '%') | ||
THEN LEAST(NULLIF(POSITION(query IN project.slug), 0), NULLIF(POSITION(query IN project.title), 0)) | ||
ELSE 0 | ||
END) AS index_found | ||
FROM | ||
project | ||
LEFT JOIN keyword_for_project ON keyword_for_project.project = project.id | ||
LEFT JOIN keyword ON keyword.id = keyword_for_project.keyword | ||
GROUP BY project.id | ||
HAVING | ||
project.slug ILIKE CONCAT('%', query, '%') | ||
OR | ||
project.title ILIKE CONCAT('%', query, '%') | ||
OR | ||
project.subtitle ILIKE CONCAT('%', query, '%') | ||
OR | ||
BOOL_OR(keyword.value ILIKE CONCAT('%', query, '%')) | ||
UNION ALL | ||
-- ORGANISATION search | ||
SELECT | ||
organisation.slug, | ||
NULL AS domain, | ||
organisation."name", | ||
'organisations' AS "source", | ||
TRUE AS is_published, | ||
(CASE | ||
WHEN organisation.slug ILIKE query OR organisation."name" ILIKE query THEN 0 | ||
WHEN organisation.slug ILIKE CONCAT(query, '%') OR organisation."name" ILIKE CONCAT(query, '%') THEN 2 | ||
ELSE 3 | ||
END) AS rank, | ||
(CASE | ||
WHEN organisation.slug ILIKE query OR organisation."name" ILIKE query THEN 0 | ||
WHEN organisation.slug ILIKE CONCAT(query, '%') OR organisation."name" ILIKE CONCAT(query, '%') THEN 0 | ||
ELSE | ||
LEAST(NULLIF(POSITION(query IN organisation.slug), 0), NULLIF(POSITION(query IN organisation."name"), 0)) | ||
END) AS index_found | ||
FROM | ||
organisation | ||
WHERE | ||
-- ONLY TOP LEVEL ORGANISATIONS | ||
organisation.parent IS NULL | ||
AND | ||
(organisation.slug ILIKE CONCAT('%', query, '%') OR organisation."name" ILIKE CONCAT('%', query, '%')) | ||
UNION ALL | ||
-- COMMUNITY search | ||
SELECT | ||
community.slug, | ||
NULL AS domain, | ||
community."name", | ||
'communities' AS "source", | ||
TRUE AS is_published, | ||
(CASE | ||
WHEN community.slug ILIKE query OR community."name" ILIKE query THEN 0 | ||
WHEN community.slug ILIKE CONCAT(query, '%') OR community."name" ILIKE CONCAT(query, '%') THEN 2 | ||
ELSE 3 | ||
END) AS rank, | ||
(CASE | ||
WHEN community.slug ILIKE query OR community."name" ILIKE query THEN 0 | ||
WHEN community.slug ILIKE CONCAT(query, '%') OR community."name" ILIKE CONCAT(query, '%') THEN 0 | ||
ELSE | ||
LEAST(NULLIF(POSITION(query IN community.slug), 0), NULLIF(POSITION(query IN community."name"), 0)) | ||
END) AS index_found | ||
FROM | ||
community | ||
WHERE | ||
community.slug ILIKE CONCAT('%', query, '%') OR community."name" ILIKE CONCAT('%', query, '%'); | ||
$$; |
5 changes: 3 additions & 2 deletions
5
frontend/components/GlobalSearchAutocomplete/globalSearchAutocomplete.api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) | ||
// SPDX-FileCopyrightText: 2023 dv4all | ||
// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) | ||
// SPDX-FileCopyrightText: 2024 - 2025 Dusan Mijatovic (Netherlands eScience Center) | ||
// SPDX-FileCopyrightText: 2024 - 2025 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import logger from '~/utils/logger' | ||
import {createJsonHeaders} from '~/utils/fetchHelpers' | ||
|
||
export type GlobalSearchResults = { | ||
domain: string | null | ||
slug: string, | ||
name: string, | ||
source: 'software' | 'projects' | 'organisations' | 'communities', | ||
|
Oops, something went wrong.