mono/packages/ui/docs/locations/algo.md
2026-03-21 20:18:25 +01:00

2.2 KiB

Search Algorithm Strategies

1. Zoom Level Calibration

Objective: Determine the optimal zoom level to maximize the number of unique locations found for a given keyword and location.

Strategy

  1. Input:

    • Keyword (e.g., "carpenters")
    • Location (e.g., "Barcelona, Spain")
    • Zoom Range (e.g., 12-18)
  2. Process:

    • Iterate through the defined range of zoom levels.
    • For each zoom level:
      • Perform a Google Maps search using the googleMaps function.
      • Store the results in a JSON file using the --dst option (e.g., ./tmp/search/test-zoomlevel-<zoom>.json).
      • Count the total number of valid results returned.
    • Maintain a record of (Zoom Level -> Result Count).
  3. Output:

    • The zoom level that yielded the maximum number of results.
  4. Notes:

    • This process assumes that for a fixed point, the "best" zoom captures the most relevant density without being too broad (losing small entities) or too narrow (missing context).
    • Overlaps/Duplicates should be handled by the underlying search function or post-processing if multi-point scanning is used later.

Objective: Scan a larger, defined area (e.g., "Madrid" or "Spain") using the optimal zoom level to ensure comprehensive coverage.

Strategy (Planning)

  1. Input:

    • Target Area Boundaries (Polygon/Box).
    • Calibrated Zoom Level (from Step 1).
    • List of Provinces/Towns (if segmenting by admin regions).
  2. Grid Generation:

    • Determine the lat/long delta that corresponds to the calibrated zoom level's viewport size.
    • Create a grid of search coordinates covering the Target Area.
  3. Execution & State Management:

    • This is a long-running task.
    • State Store: Maintain a persistent state (JSON/DB) tracking:
      • Queue of pending coordinates.
      • Completed coordinates.
      • Failed coordinates.
    • Process the queue sequentially or in parallel batches.
  4. Aggregation:

    • Combine all result files.
    • Perform global deduplication (by place_id or title + address).