From d0bbf628ddf3b277394d5b9261bd6fb0c0c5748d Mon Sep 17 00:00:00 2001 From: Luke Sikina Date: Sat, 13 Jul 2024 12:18:17 -0400 Subject: [PATCH] 3 --- .../avillach/dictionary/filter/FilterQueryGenerator.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/filter/FilterQueryGenerator.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/filter/FilterQueryGenerator.java index abe03db..85f2c63 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/filter/FilterQueryGenerator.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/filter/FilterQueryGenerator.java @@ -37,9 +37,11 @@ public QueryParamPair generateFilterQuery(Filter filter, Pageable pageable) { String query = "(\n" + String.join("\n\tINTERSECT\n", clauses) + "\n)"; + String havingClause = ""; if (StringUtils.hasText(filter.search())) { String searchQuery = createSearchFilter(filter.search(), params); query = "(" + query + "\n\tUNION \n\t" + searchQuery + ")"; + havingClause = "HAVING max(rank) > 0\n"; } String superQuery = """ WITH q AS ( @@ -47,10 +49,9 @@ WITH q AS ( ) SELECT concept_node_id FROM q - GROUP BY concept_node_id - HAVING max(rank) > 0 + GROUP BY concept_node_id %s ORDER BY max(rank) DESC - """.formatted(query); + """.formatted(query, havingClause); if (pageable.isPaged()) { superQuery = superQuery + """ LIMIT :limit