From 27b0928e73d0aac061265b9e86e992236f0c7dce Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Tue, 15 Apr 2025 19:32:34 -0300 Subject: [PATCH] feat: title weight procedure --- services/search.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/services/search.py b/services/search.py index b8036644..7a185235 100644 --- a/services/search.py +++ b/services/search.py @@ -254,14 +254,18 @@ class SearchService: return try: + # Repeat title 3 times for higher keyword relevance + title_repeat = ". ".join(filter(None, [shout.title] * 3)) + # Combine all text fields - text = " ".join(filter(None, [ - shout.title or "", - shout.subtitle or "", - shout.lead or "", + text_parts = [ + title_repeat, + shout.subtitle or "", + shout.lead or "", shout.body or "", shout.media or "" - ])) + ] + text = " ".join(filter(None, text_parts)) if not text.strip(): logger.warning(f"No text content to index for shout {shout.id}") @@ -305,7 +309,12 @@ class SearchService: for shout in shouts: try: text_fields = [] - for field_name in ['title', 'subtitle', 'lead', 'body']: + + # Repeat title 3 times + title_repeat = ". ".join(filter(None, [getattr(shout, "title", None)] * 3)) + + text_fields = [title_repeat] + for field_name in ['subtitle', 'lead', 'body']: field_value = getattr(shout, field_name, None) if field_value and isinstance(field_value, str) and field_value.strip(): text_fields.append(field_value.strip())