Skip to content

Latest commit

 

History

History
202 lines (155 loc) · 7.45 KB

File metadata and controls

202 lines (155 loc) · 7.45 KB

Enhanced Search Filters Documentation

Overview

This document describes the enhanced search filter functionality added to the Liberu Real Estate Laravel application. These enhancements enable users to filter properties based on energy efficiency, walkability, transit accessibility, bike-friendliness, featured status, and country location.

New Filter Features

1. Energy Rating Filter

  • Type: Dropdown selection (A-G)
  • Description: Filter properties by their energy efficiency rating
  • Usage: Select from A (most efficient) to G (least efficient)
  • Database Field: energy_rating (string)

2. Energy Score Filter

  • Type: Numeric input (0-100)
  • Description: Filter properties with a minimum energy score
  • Usage: Enter a number from 0 to 100
  • Database Field: energy_score (integer)

3. Walkability Score Filter

  • Type: Numeric input (0-100)
  • Description: Filter properties with a minimum walkability score
  • Usage: Higher scores indicate better pedestrian access to amenities
  • Database Field: walkability_score (tinyInteger)
  • Note: Scores are updated via WalkScore API integration

4. Transit Score Filter

  • Type: Numeric input (0-100)
  • Description: Filter properties with a minimum public transit accessibility score
  • Usage: Higher scores indicate better access to public transportation
  • Database Field: transit_score (tinyInteger)

5. Bike Score Filter

  • Type: Numeric input (0-100)
  • Description: Filter properties with a minimum bike-friendliness score
  • Usage: Higher scores indicate better cycling infrastructure
  • Database Field: bike_score (tinyInteger)

6. Country Filter

  • Type: Dropdown selection
  • Description: Filter properties by country
  • Usage: Select from available countries (UK, US, FR, DE, ES)
  • Database Field: country (string)
  • Note: Useful for international property listings

7. Featured Properties Filter

  • Type: Checkbox
  • Description: Show only featured/premium properties
  • Usage: Check to display only properties marked as featured
  • Database Field: is_featured (boolean)

Implementation Details

Query Scopes Added to Property Model

The following Eloquent query scopes were added to app/Models/Property.php:

// Filter by energy rating (A-G)
public function scopeEnergyRating(Builder $query, $rating): Builder

// Filter by minimum energy score
public function scopeMinEnergyScore(Builder $query, $minScore): Builder

// Filter by minimum walkability score
public function scopeWalkabilityScore(Builder $query, $minScore): Builder

// Filter by minimum transit score
public function scopeTransitScore(Builder $query, $minScore): Builder

// Filter by minimum bike score
public function scopeBikeScore(Builder $query, $minScore): Builder

// Filter featured properties only
public function scopeFeatured(Builder $query): Builder

// Filter by country
public function scopeCountry(Builder $query, $country): Builder

Livewire Components Updated

Both search components were enhanced with the new filters:

  1. PropertyList (app/Http/Livewire/PropertyList.php)

    • Added filter properties
    • Updated query logic to apply new filters
    • Added queryString parameters for URL persistence
  2. AdvancedPropertySearch (app/Http/Livewire/AdvancedPropertySearch.php)

    • Added filter properties
    • Updated query logic with conditional application
    • Added queryString parameters

View Updates

Enhanced the advanced search form (resources/views/livewire/advanced-property-search.blade.php) with:

  • Energy rating dropdown
  • Energy score numeric input
  • Walkability score numeric input
  • Transit score numeric input
  • Bike score numeric input
  • Country selection dropdown
  • Featured properties checkbox

Usage Examples

Example 1: Filter by Energy Efficiency

// Find properties with energy rating A or B and score > 70
Property::energyRating('A')
    ->minEnergyScore(70)
    ->get();

Example 2: Filter by Location Scores

// Find walkable properties with good transit access
Property::walkabilityScore(75)
    ->transitScore(70)
    ->get();

Example 3: Combined Filters

// Find featured UK properties that are energy efficient and walkable
Property::featured()
    ->country('UK')
    ->energyRating('A')
    ->walkabilityScore(80)
    ->priceRange(200000, 500000)
    ->get();

Example 4: URL Query String

Users can share searches via URL:

/properties/search?energyRating=A&minWalkabilityScore=75&featuredOnly=1&country=UK

Testing

Comprehensive unit tests were added to tests/Unit/PropertyTest.php:

  • test_energy_rating_scope() - Tests energy rating filtering
  • test_min_energy_score_scope() - Tests minimum energy score filtering
  • test_walkability_score_scope() - Tests walkability score filtering
  • test_transit_score_scope() - Tests transit score filtering
  • test_bike_score_scope() - Tests bike score filtering
  • test_featured_scope() - Tests featured properties filtering
  • test_country_scope() - Tests country filtering

Each test validates that the scope correctly filters properties based on the criteria.

Database Fields

All filter fields already existed in the database schema:

Field Type Nullable Migration
energy_rating string Yes 2023_12_01_000001_create_properties.php
energy_score integer Yes 2023_12_01_000001_create_properties.php
walkability_score tinyInteger Yes 2024_03_15_000000_add_walkability_scores_to_properties_table.php
transit_score tinyInteger Yes 2024_03_15_000000_add_walkability_scores_to_properties_table.php
bike_score tinyInteger Yes 2024_03_15_000000_add_walkability_scores_to_properties_table.php
is_featured boolean No 2023_12_01_000001_create_properties.php
country string Yes 2023_12_01_000001_create_properties.php

No database migrations were required - all fields were already present.

Benefits

  1. Enhanced User Experience: Users can now filter properties based on sustainability and lifestyle factors
  2. Better Property Discovery: More granular search options help users find properties that match their specific needs
  3. SEO-Friendly: URL query strings allow search parameters to be shared and bookmarked
  4. Minimal Changes: Implementation leveraged existing database fields and followed established patterns
  5. Fully Tested: All new scopes have unit test coverage
  6. Performance: Scopes use efficient database queries with proper indexing considerations

Future Enhancements

Potential improvements for future iterations:

  1. Add range sliders for score inputs (UX improvement)
  2. Display score badges on property cards
  3. Add sorting by walkability/transit/bike scores
  4. Implement smart home features filter (JSON field)
  5. Add energy rating to property cards
  6. Create saved search functionality for filter combinations
  7. Add filter analytics to track popular search criteria

Backward Compatibility

All changes are backward compatible:

  • New filters are optional
  • Default values maintain existing behavior
  • Existing queries continue to work unchanged
  • No breaking changes to API or data structures

Conclusion

The enhanced search filters provide users with powerful new ways to discover properties that match their sustainability and lifestyle preferences. The implementation follows Laravel best practices, maintains code quality, and includes comprehensive test coverage.