Enhancing Property Search: Reactive Facets and Grouping in Inmotech-Backend

Searching for properties can often be a frustrating experience. Stiff search interfaces that don't dynamically adapt to your choices or provide relevant groupings can quickly turn a hopeful search into a chore. In the Ryuu-no-Mi/Inmotech-Backend project, we've recently rolled out a significant feature to transform this experience, particularly for 'venta' (sale) and 'alquiler' (rental) operations, by introducing reactive facets, robust filtering, and intelligent type grouping.

The Need for Dynamic Property Search

Previously, users might have encountered static filter options that required multiple clicks or page reloads to see the impact of their selections. This approach is inefficient and doesn't leverage the full potential of modern web applications. Our goal was to create an intuitive search experience where filter options update in real-time based on current criteria, alongside the ability to easily group properties by their 'tipo' (type).

Implementing Reactive Facets and Advanced Filtering

To achieve this, we focused on building a backend capability that could efficiently process complex filter combinations and generate dynamic facet data. When a user selects 'venta' or 'alquiler', the available property types, price ranges, and other filter options should immediately reflect only the properties relevant to that initial choice.

This involved enhancing our data access layer, leveraging the Repository Pattern with Spring Data JPA. Our service layer now takes a comprehensive set of filter criteria and applies them to the property listings. Furthermore, we implemented logic to retrieve counts for property types based on the active filters, providing the data needed for the 'reactive facets' on the frontend.

Here's a simplified look at how a service might apply these filters using a custom Spring Data JPA repository method:

// Property entity (simplified for illustration)
public class Property {
    private Long id;
    private String operation; // e.g., "VENTA" or "ALQUILER"
    private String type;      // e.g., "Apartment", "House", "Land"
    private Double price;
    // ... other fields, getters and setters
}

// PropertyRepository using Spring Data JPA
public interface PropertyRepository extends JpaRepository<Property, Long> {
    @Query("SELECT p FROM Property p WHERE " +
           "(:operation IS NULL OR p.operation = :operation) AND " +
           "(:type IS NULL OR p.type = :type) AND " +
           "(:minPrice IS NULL OR p.price >= :minPrice) AND " +
           "(:maxPrice IS NULL OR p.price <= :maxPrice)")
    Page<Property> findByAdvancedFilters(
            @Param("operation") String operation,
            @Param("type") String type,
            @Param("minPrice") Double minPrice,
            @Param("maxPrice") Double maxPrice,
            Pageable pageable);
}

// Service layer applying filters
@Service
public class PropertySearchService {
    @Autowired
    private PropertyRepository propertyRepository;

    public Page<Property> applyFilters(FilterCriteria criteria) {
        Pageable pageable = PageRequest.of(criteria.getPage(), criteria.getSize());
        return propertyRepository.findByAdvancedFilters(
            criteria.getOperation(),
            criteria.getType(),
            criteria.getMinPrice(),
            criteria.getMaxPrice(),
            pageable);
    }
}

This Java example demonstrates a PropertyRepository method that accepts multiple optional filter parameters (operation, type, minPrice, maxPrice). The PropertySearchService then orchestrates the call, passing a FilterCriteria object (which would encapsulate user selections) to fetch paginated results. The backend also calculates counts for different property types, allowing the frontend to display updated facet options instantly.

The Outcome: A Seamless User Experience

By implementing reactive facets and sophisticated filtering, users of Inmotech-Backend now benefit from a much more dynamic and responsive property search. They can quickly narrow down their options, discover relevant properties faster, and enjoy an overall smoother browsing experience. This enhancement not only improves usability but also sets a strong foundation for future search functionalities.


Generated with Gitvlg.com

Enhancing Property Search: Reactive Facets and Grouping in Inmotech-Backend
JAIME ANDRÉS MONSERRATE VILLA

JAIME ANDRÉS MONSERRATE VILLA

Author

Share: