Skip to content

Commit

Permalink
Rank search
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sikina committed Jul 8, 2024
1 parent 87e7f77 commit c2f3b02
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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);
}
Expand All @@ -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
Expand All @@ -92,7 +97,7 @@ private List<String> createFacetFilter(List<Facet> 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
Expand Down

0 comments on commit c2f3b02

Please sign in to comment.