Skip to content

Commit 0f44570

Browse files
committed
allow updates to fewer fields for event updates; add fuzzy matching search
1 parent d2e1ac0 commit 0f44570

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

backend/apps/events/views.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def get_events(request):
100100
filtered_queryset = filterset.qs.distinct()
101101

102102
if search_term:
103+
import re
104+
103105
# Parse semicolon-separated filters (for OR query)
104106
search_terms = [
105107
term.strip() for term in search_term.split(";") if term.strip()
@@ -108,6 +110,7 @@ def get_events(request):
108110
# Build OR query: match any of the search terms in any field
109111
or_queries = Q()
110112
for term in search_terms:
113+
# Search with original term (exact/partial matches)
111114
term_query = (
112115
Q(title__icontains=term)
113116
| Q(location__icontains=term)
@@ -121,6 +124,23 @@ def get_events(request):
121124
| Q(tiktok_handle__icontains=term)
122125
| Q(fb_handle__icontains=term)
123126
)
127+
128+
# Search with normalized term
129+
normalized_term = re.sub(r'[^a-z0-9]', '', term.lower())
130+
if normalized_term and normalized_term != term.lower():
131+
term_query |= (
132+
Q(title__icontains=normalized_term)
133+
| Q(location__icontains=normalized_term)
134+
| Q(description__icontains=normalized_term)
135+
| Q(food__icontains=normalized_term)
136+
| Q(club_type__icontains=normalized_term)
137+
| Q(ig_handle__icontains=normalized_term)
138+
| Q(discord_handle__icontains=normalized_term)
139+
| Q(x_handle__icontains=normalized_term)
140+
| Q(tiktok_handle__icontains=normalized_term)
141+
| Q(fb_handle__icontains=normalized_term)
142+
)
143+
124144
or_queries |= term_query
125145

126146
filtered_queryset = filtered_queryset.filter(or_queries)

backend/utils/scraping_utils.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,10 @@ def insert_event_to_db(event_data, ig_handle, source_url, club_type=None):
8282
if has_match:
8383
# If event is from same club, update event info
8484
if matched_event and matched_event.ig_handle == ig_handle:
85-
logger.info(f"{log_prefix} Updating existing event '{matched_event.title}' (ID: {matched_event.id}) with new information")
85+
logger.info(f"{log_prefix} Updating existing event '{matched_event.title}' (ID: {matched_event.id}) with new date/time/location")
8686

87-
matched_event.title = title
87+
# Only update location, date, and time
8888
matched_event.location = location
89-
matched_event.description = description or None
90-
matched_event.price = price or None
91-
matched_event.food = food or None
92-
matched_event.registration = registration
93-
matched_event.source_image_url = source_image_url or None
94-
matched_event.categories = categories
9589
matched_event.source_url = source_url
9690
matched_event.added_at = timezone.now() # Bump to top
9791
matched_event.save()

0 commit comments

Comments
 (0)