Enhancing Geographical Facets in Ryuu-no-Mi/Inmotech-Backend

Project Context: Ryuu-no-Mi/Inmotech-Backend

In the Ryuu-no-Mi/Inmotech-Backend project, we continuously strive to improve the user experience, particularly in property search and filtering. A key aspect of this is how we present geographical data to users, allowing them to quickly narrow down their search by location.

The Need for Granular Geographical Grouping

Previously, our property search facets provided filtering by cities, districts, and barrios. However, for a more intuitive and structured search experience, there was a clear need to group cities further by their respective 'autonomous communities' (regions). This would allow users to first select a broader region and then dive into specific cities within that region, making navigation much more efficient.

Implementing the Faceting Logic

To address this, we've introduced a significant enhancement to how geographical facets are generated. The PropiedadServiceImpl.getFacetas() method has been updated to return a new comunidades map. This map organizes cities, not just as a flat list, but grouped under their autonomous communities.

This grouping is achieved by leveraging an internal MapaGeograficoEstatico.getComunidad() utility. This service helps identify which autonomous community a given city belongs to. For any cities that are not found within our predefined geographical map, they are gracefully categorized under an 'Otras' (Other) section, ensuring no data is lost and all properties are still discoverable.

Updating the Data Transfer Object (DTO)

To accommodate this new structure, the FacetaDTO—our primary data transfer object for facets—has been expanded. It now explicitly includes a field for comunidades, in addition to the existing ciudades (cities), tipos (types), distritos (districts), and barrios (neighborhoods). This ensures the frontend receives the enriched geographical data in a structured format.

Illustrative Code Snippet

Here's a simplified Java example demonstrating the conceptual logic for grouping cities:

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class GeographicFacetService {

    // Simplified representation of a static geographic map
    private static class StaticGeographicMap {
        public String getAutonomousCommunity(String city) {
            // In a real scenario, this would consult a comprehensive map
            if (city.equals("Madrid") || city.equals("Alcalá de Henares")) {
                return "Comunidad de Madrid";
            } else if (city.equals("Barcelona") || city.equals("Girona")) {
                return "Cataluña";
            } else if (city.equals("Seville") || city.equals("Malaga")) {
                return "Andalucía";
            }
            return null; // City not explicitly mapped
        }
    }

    public Map<String, List<String>> groupCitiesByCommunity(List<String> allCities) {
        StaticGeographicMap geoMap = new StaticGeographicMap();
        Map<String, List<String>> communitiesMap = new HashMap<>();
        String otherCategory = "Otras";

        // Initialize 'Otras' category
        communitiesMap.put(otherCategory, new java.util.ArrayList<>());

        for (String city : allCities) {
            String community = geoMap.getAutonomousCommunity(city);
            if (community != null) {
                communitiesMap.computeIfAbsent(community, k -> new java.util.ArrayList<>()).add(city);
            } else {
                communitiesMap.get(otherCategory).add(city);
            }
        }
        return communitiesMap;
    }
}

This snippet illustrates how allCities are iterated, mapped to a community, and then added to the appropriate list within the communitiesMap or to the Otras category if unmapped.

Impact and Benefits

This enhancement significantly improves the usability of our property search. Users can now perform more targeted geographical searches, navigating through broader regions before drilling down into specific cities. This structured approach reduces cognitive load and provides a more intuitive path to finding relevant properties.

Future Considerations

When implementing complex data grouping and categorization, it's crucial to ensure the underlying mapping data (like MapaGeograficoEstatico) is accurate and easily maintainable. Regular updates to this map will ensure that new or previously unmapped locations are correctly categorized, further enhancing the user experience.


Generated with Gitvlg.com

Enhancing Geographical Facets in Ryuu-no-Mi/Inmotech-Backend
JAIME ANDRÉS MONSERRATE VILLA

JAIME ANDRÉS MONSERRATE VILLA

Author

Share: