Skip to content

Commit

Permalink
Merge pull request #79 from ecmwf-projects/copds-1777-fts
Browse files Browse the repository at this point in the history
COPDS-1777: custom ranking on catalogue search
  • Loading branch information
alex75 authored Jul 2, 2024
2 parents ad516e5 + 6e7f4ae commit a6ae678
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions cads_catalogue_api_service/search_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
WEIGHT_HIGH_PRIORITY_TERMS = 1.0
WEIGHT_TITLE = 0.8
WEIGHT_DESCRIPTION = 0.5
WEIGHT_FULLTEXT = 0.3
WEIGHT_FULLTEXT = 0.03


def split_by_category(keywords: list) -> list:
Expand Down Expand Up @@ -60,7 +60,7 @@ def generate_ts_query(q: str = ""):
def fulltext_order_by(q: str):
"""Generate the full text search order by clause."""
tsquery = generate_ts_query(q)
return sa.func.ts_rank(
return sa.func.ts_rank2(
"{%s,%s,%s,%s}"
% (
# NOTE: order of weights follows {D,C,B,A} labelling of 'search_field' of table resources
Expand All @@ -70,7 +70,9 @@ def fulltext_order_by(q: str):
WEIGHT_TITLE,
),
cads_catalogue.database.Resource.search_field,
cads_catalogue.database.Resource.fts,
tsquery,
sa.func.coalesce(cads_catalogue.database.Resource.popularity, 1),
).desc()


Expand Down
2 changes: 1 addition & 1 deletion tests/test_10_sorting_paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_apply_sorting() -> None:

assert search.limit == 10
assert search.offset == 0
assert search.order_by.element.name == "ts_rank"
assert search.order_by.element.name == "ts_rank2"


def test_get_next_prev_links() -> None:
Expand Down

0 comments on commit a6ae678

Please sign in to comment.