zenaight commited on
Commit ·
2f6ba3c
1
Parent(s): d3f2812
Enhance logging in property search functionality
Browse files- Added logging statements in `search_properties` to provide insights into the number of properties in the database, search filters applied, and results obtained.
- Improved traceability by logging the execution flow, including city and location filter attempts, budget and size constraints, and must-have features during the property search process.
- database.py +15 -0
database.py
CHANGED
|
@@ -301,33 +301,48 @@ async def search_properties(filters: dict) -> list:
|
|
| 301 |
return []
|
| 302 |
|
| 303 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
query = supabase.table("properties").select("*").eq("is_active", True)
|
| 305 |
print("Base query created")
|
| 306 |
|
| 307 |
# a. Location: try city first, then location field
|
| 308 |
loc = filters.get("location_preference")
|
| 309 |
if loc:
|
|
|
|
| 310 |
query = query.ilike("city", f"%{loc}%")
|
|
|
|
| 311 |
resp = query.execute()
|
|
|
|
| 312 |
if not resp.data:
|
| 313 |
# fallback to suburb/area match
|
|
|
|
| 314 |
query = supabase.table("properties").select("*")\
|
| 315 |
.eq("is_active", True)\
|
| 316 |
.ilike("location", f"%{loc}%")
|
|
|
|
| 317 |
|
| 318 |
# b. Budget cap
|
| 319 |
budget = filters.get("budget")
|
| 320 |
if budget is not None:
|
|
|
|
| 321 |
query = query.lte("price", budget)
|
| 322 |
|
| 323 |
# c. Minimum size
|
| 324 |
size = filters.get("size_preference_sqm")
|
| 325 |
if size is not None:
|
|
|
|
| 326 |
query = query.gte("size_sqm", size)
|
| 327 |
|
| 328 |
# d. Must-have features
|
| 329 |
features = filters.get("must_have") or []
|
| 330 |
for feat in features:
|
|
|
|
| 331 |
query = query.contains("features", [feat])
|
| 332 |
|
| 333 |
# e. Order & limit
|
|
|
|
| 301 |
return []
|
| 302 |
|
| 303 |
try:
|
| 304 |
+
# First, let's see if there are any properties at all
|
| 305 |
+
test_query = supabase.table("properties").select("*").limit(5)
|
| 306 |
+
test_resp = test_query.execute()
|
| 307 |
+
print(f"Total properties in database: {len(test_resp.data) if test_resp.data else 0}")
|
| 308 |
+
if test_resp.data:
|
| 309 |
+
print(f"Sample properties: {test_resp.data}")
|
| 310 |
+
|
| 311 |
query = supabase.table("properties").select("*").eq("is_active", True)
|
| 312 |
print("Base query created")
|
| 313 |
|
| 314 |
# a. Location: try city first, then location field
|
| 315 |
loc = filters.get("location_preference")
|
| 316 |
if loc:
|
| 317 |
+
print(f"Searching for location: {loc}")
|
| 318 |
query = query.ilike("city", f"%{loc}%")
|
| 319 |
+
print(f"After city filter: {query}")
|
| 320 |
resp = query.execute()
|
| 321 |
+
print(f"City search result: {resp.data}")
|
| 322 |
if not resp.data:
|
| 323 |
# fallback to suburb/area match
|
| 324 |
+
print(f"No city matches, trying location field...")
|
| 325 |
query = supabase.table("properties").select("*")\
|
| 326 |
.eq("is_active", True)\
|
| 327 |
.ilike("location", f"%{loc}%")
|
| 328 |
+
print(f"After location filter: {query}")
|
| 329 |
|
| 330 |
# b. Budget cap
|
| 331 |
budget = filters.get("budget")
|
| 332 |
if budget is not None:
|
| 333 |
+
print(f"Adding budget filter: <= {budget}")
|
| 334 |
query = query.lte("price", budget)
|
| 335 |
|
| 336 |
# c. Minimum size
|
| 337 |
size = filters.get("size_preference_sqm")
|
| 338 |
if size is not None:
|
| 339 |
+
print(f"Adding size filter: >= {size}")
|
| 340 |
query = query.gte("size_sqm", size)
|
| 341 |
|
| 342 |
# d. Must-have features
|
| 343 |
features = filters.get("must_have") or []
|
| 344 |
for feat in features:
|
| 345 |
+
print(f"Adding feature filter: {feat}")
|
| 346 |
query = query.contains("features", [feat])
|
| 347 |
|
| 348 |
# e. Order & limit
|