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

Feature/search filter by rank and generate syllables only for compoundwords #216

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
21 changes: 17 additions & 4 deletions services/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
DEFAULT_SEARCH_SQL_LIMIT_VALUE,
DEFAULT_SRS,
DEFAULT_TRIGRAM_THRESHOLD,
DEFAULT_RANK_THRESHOLD,
LANGUAGES,
QUERY_PARAM_TYPE_NAMES,
)
Expand Down Expand Up @@ -212,6 +213,16 @@ def get(self, request):
else:
trigram_threshold = DEFAULT_TRIGRAM_THRESHOLD


if "rank_threshold" in params:
try:
rank_threshold = float(params.get("rank_threshold"))
except ValueError:
raise ParseError("'rank_threshold' need to be of type float.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo need --> needs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

else:
rank_threshold = DEFAULT_RANK_THRESHOLD


if "geometry" in params:
try:
show_geometry = strtobool(params["geometry"])
Expand Down Expand Up @@ -283,10 +294,12 @@ def get(self, request):
# This is ~100 times faster than using Djangos SearchRank and allows searching using wildard "|*"
# and by rankig gives better results, e.g. extra fields weight is counted.
sql = f"""
SELECT id, type_name, name_{language_short}, ts_rank_cd(search_column_{language_short}, search_query)
AS rank FROM search_view, to_tsquery('{config_language}','{search_query_str}') search_query
WHERE search_query @@ search_column_{language_short}
ORDER BY rank DESC LIMIT {sql_query_limit};
SELECT * from (
SELECT id, type_name, name_{language_short}, ts_rank_cd(search_column_{language_short}, search_query)
AS rank FROM search_view, to_tsquery('{config_language}','{search_query_str}') search_query
WHERE search_query @@ search_column_{language_short}
ORDER BY rank DESC LIMIT {sql_query_limit}
) AS sub_query where sub_query.rank >= {rank_threshold};
"""

cursor = connection.cursor()
Expand Down