diff --git a/tradein-mvp/backend/app/services/estimator.py b/tradein-mvp/backend/app/services/estimator.py index e5aaecb1..aa6257e3 100644 --- a/tradein-mvp/backend/app/services/estimator.py +++ b/tradein-mvp/backend/app/services/estimator.py @@ -343,7 +343,10 @@ def _fetch_analogs( AND scraped_at > NOW() - (:fresh_days || ' days')::interval AND price_rub > 0 ORDER BY ( - distance_m / 1000.0 + -- distance_m — это SELECT-алиас. В ORDER BY-ВЫРАЖЕНИИ (не голым + -- термом) PostgreSQL трактует имя как входную колонку listings, + -- которой нет → "column distance_m does not exist". Инлайним ST_Distance. + ST_Distance(geom::geography, ST_MakePoint(:lon, :lat)::geography) / 1000.0 + CASE WHEN :target_year IS NOT NULL AND year_built IS NOT NULL THEN abs(year_built - :target_year) / 12.0 ELSE 0 END + CASE WHEN :target_house_type IS NOT NULL AND house_type IS NOT NULL