zenaight commited on
Commit ·
762b66d
1
Parent(s): 582cc74
Enhance property search functionality by adding transaction type filtering
Browse files- Updated the extract_and_search_properties function to include transaction_type in the search filters, allowing users to specify whether they are looking to rent or buy properties.
- Modified the search_properties function to handle transaction_type filtering, ensuring appropriate price types are applied based on the user's selection.
- Added sample sale properties to the database setup for testing purposes, improving the robustness of property search functionality.
- ai_chat.py +4 -0
- database.py +15 -0
- supabase_setup.sql +49 -1
ai_chat.py
CHANGED
|
@@ -517,6 +517,10 @@ async def extract_and_search_properties(state):
|
|
| 517 |
if intent.get("size_preference_sqm") is not None:
|
| 518 |
filters["size_preference_sqm"] = intent["size_preference_sqm"]
|
| 519 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 520 |
# Search for properties with flexible ranges
|
| 521 |
print(f"DEBUG - Searching with filters: {filters}")
|
| 522 |
properties = await search_properties(filters)
|
|
|
|
| 517 |
if intent.get("size_preference_sqm") is not None:
|
| 518 |
filters["size_preference_sqm"] = intent["size_preference_sqm"]
|
| 519 |
|
| 520 |
+
# Add transaction type if set (rent vs buy)
|
| 521 |
+
if intent.get("transaction_type") is not None:
|
| 522 |
+
filters["transaction_type"] = intent["transaction_type"]
|
| 523 |
+
|
| 524 |
# Search for properties with flexible ranges
|
| 525 |
print(f"DEBUG - Searching with filters: {filters}")
|
| 526 |
properties = await search_properties(filters)
|
database.py
CHANGED
|
@@ -327,6 +327,21 @@ async def search_properties(filters: dict) -> list:
|
|
| 327 |
max_size = int(size * 1.5) # 50% above target
|
| 328 |
query = query.gte("size_sqm", min_size).lte("size_sqm", max_size)
|
| 329 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
# Note: Must-have features are removed from database search
|
| 331 |
# They will be handled by the LLM in the chat response
|
| 332 |
|
|
|
|
| 327 |
max_size = int(size * 1.5) # 50% above target
|
| 328 |
query = query.gte("size_sqm", min_size).lte("size_sqm", max_size)
|
| 329 |
|
| 330 |
+
# d. Transaction type (rent vs buy)
|
| 331 |
+
transaction_type = filters.get("transaction_type")
|
| 332 |
+
if transaction_type:
|
| 333 |
+
print(f"DEBUG - Filtering by transaction_type: {transaction_type}")
|
| 334 |
+
if transaction_type == "rent":
|
| 335 |
+
# For rent: filter by monthly, weekly, daily price types
|
| 336 |
+
query = query.in_("price_type", ["monthly", "weekly", "daily"])
|
| 337 |
+
print(f"DEBUG - Filtering for rental properties (monthly, weekly, daily)")
|
| 338 |
+
elif transaction_type == "buy":
|
| 339 |
+
# For buy: filter by sale, purchase price types
|
| 340 |
+
query = query.in_("price_type", ["sale", "purchase", "total"])
|
| 341 |
+
print(f"DEBUG - Filtering for sale properties (sale, purchase, total)")
|
| 342 |
+
else:
|
| 343 |
+
print(f"DEBUG - No transaction_type filter applied")
|
| 344 |
+
|
| 345 |
# Note: Must-have features are removed from database search
|
| 346 |
# They will be handled by the LLM in the chat response
|
| 347 |
|
supabase_setup.sql
CHANGED
|
@@ -224,4 +224,52 @@ INSERT INTO properties (title, description, location, city, address, size_sqm, p
|
|
| 224 |
TRUE,
|
| 225 |
FALSE
|
| 226 |
)
|
| 227 |
-
ON CONFLICT DO NOTHING;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
TRUE,
|
| 225 |
FALSE
|
| 226 |
)
|
| 227 |
+
ON CONFLICT DO NOTHING;
|
| 228 |
+
|
| 229 |
+
-- Add some sample sale properties for testing
|
| 230 |
+
INSERT INTO properties (title, description, location, city, address, size_sqm, price, price_type, listing_url, images, features, is_active, is_featured) VALUES
|
| 231 |
+
(
|
| 232 |
+
'Office Building for Sale in Sandton',
|
| 233 |
+
'Modern office building with excellent investment potential',
|
| 234 |
+
'Sandton',
|
| 235 |
+
'Johannesburg',
|
| 236 |
+
'1 Sandton Drive, Sandton, 2196, South Africa',
|
| 237 |
+
500,
|
| 238 |
+
2500000,
|
| 239 |
+
'sale',
|
| 240 |
+
'https://example.com/office-building-sale',
|
| 241 |
+
ARRAY['https://example.com/building1.jpg', 'https://example.com/building2.jpg'],
|
| 242 |
+
ARRAY['Elevator', 'Parking', 'Security', 'Reception'],
|
| 243 |
+
TRUE,
|
| 244 |
+
TRUE
|
| 245 |
+
),
|
| 246 |
+
(
|
| 247 |
+
'Warehouse for Sale in Midrand',
|
| 248 |
+
'Industrial warehouse with great location for logistics',
|
| 249 |
+
'Midrand',
|
| 250 |
+
'Johannesburg',
|
| 251 |
+
'New Road, Midrand, 1685, South Africa',
|
| 252 |
+
1000,
|
| 253 |
+
3200000,
|
| 254 |
+
'sale',
|
| 255 |
+
'https://example.com/warehouse-sale',
|
| 256 |
+
ARRAY['https://example.com/warehouse-sale1.jpg'],
|
| 257 |
+
ARRAY['Loading dock', 'High ceiling', '3 phase power', 'Truck access'],
|
| 258 |
+
TRUE,
|
| 259 |
+
FALSE
|
| 260 |
+
),
|
| 261 |
+
(
|
| 262 |
+
'Commercial Property for Sale in Cape Town',
|
| 263 |
+
'Prime commercial property in Cape Town CBD',
|
| 264 |
+
'CBD',
|
| 265 |
+
'Cape Town',
|
| 266 |
+
'Long Street, Cape Town, 8001, South Africa',
|
| 267 |
+
300,
|
| 268 |
+
1800000,
|
| 269 |
+
'sale',
|
| 270 |
+
'https://example.com/commercial-sale-ct',
|
| 271 |
+
ARRAY['https://example.com/commercial1.jpg'],
|
| 272 |
+
ARRAY['Street frontage', 'High foot traffic', 'Parking'],
|
| 273 |
+
TRUE,
|
| 274 |
+
FALSE
|
| 275 |
+
);
|