Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COPDS-1777: custom ranking on catalogue search #79

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading