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 bfcfc59..2c6b274 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,7 +37,7 @@ public QueryParamPair generateFilterQuery(Filter filter, Pageable pageable) { clauses.add(""" ( SELECT - concept_node.concept_node_id + concept_node.concept_node_id, 0 as rank FROM concept_node LEFT JOIN concept_node_meta AS continuous_min ON concept_node.concept_node_id = continuous_min.concept_node_id AND continuous_min.KEY = 'min' @@ -62,6 +62,10 @@ public QueryParamPair generateFilterQuery(Filter filter, Pageable pageable) { .addValue("offset", pageable.getOffset()); } + String superQuery = """ + WITH q AS (%s) SELECT concept_node_id FROM q GROUP BY concept_node_id ORDER BY sum(rank) DESC" + """; + return new QueryParamPair(query, params); } @@ -71,7 +75,8 @@ private String createSearchFilter(String search, MapSqlParameterSource params) { return """ ( SELECT - concept_node.concept_node_id AS concept_node_id + concept_node.concept_node_id AS concept_node_id, + ts_rank(searchable_fields, (phraseto_tsquery(:search)::text || ':*')::tsquery) as rank FROM concept_node WHERE @@ -92,7 +97,7 @@ private List createFacetFilter(List facets, MapSqlParameterSource return """ ( SELECT - facet__concept_node.concept_node_id AS concept_node_id + facet__concept_node.concept_node_id AS concept_node_id , 0 as rank FROM facet LEFT JOIN facet__concept_node ON facet__concept_node.facet_id = facet.facet_id LEFT JOIN facet_category ON facet_category.facet_category_id = facet.facet_category_id