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