Add autocomplete suggestions with smart zoom

- Update recoSearch to use /api/suggestions endpoint
- Improve zoom levels for different types:
  * Cities: zoom 11
  * Regions: zoom 7
  * Posts: zoom 16
  * Profiles: zoom 14
- Support lat/lon in normalized results
- Real-time suggestions as user types

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Your Name 2025-12-23 11:59:11 -05:00
parent a3903906df
commit 290e713796
2 changed files with 22 additions and 6 deletions

View File

@ -4,10 +4,21 @@ import "../../styles/smartSearchBar.css";
function defaultZoomForKind(kind) {
const k = (kind || "").toLowerCase();
// Specific types from suggestions endpoint
if (k === "post") return 16; // Close zoom for posts
if (k === "profile") return 14; // Medium zoom for profiles
if (k === "city") return 11; // City-level zoom
if (k === "region") return 7; // Wide zoom for regions/provinces
if (k === "place" || k === "poi") return 13; // Places zoom
// Legacy/fallback
if (k.includes("post")) return 15;
if (k.includes("place") || k.includes("poi")) return 13;
if (k.includes("region") || k.includes("area") || k.includes("city")) return 9;
return 12;
if (k.includes("city")) return 11;
if (k.includes("region") || k.includes("area") || k.includes("province") || k.includes("state")) return 7;
if (k.includes("place")) return 13;
return 12; // Default
}
function IconPin(props) {

View File

@ -11,7 +11,8 @@
*/
const DEFAULT_PATHS = [
"/api/unified-search", // NEW: Unified search (posts + profiles + places)
"/api/suggestions", // NEW: Autocomplete suggestions (cities, posts, profiles)
"/api/unified-search", // Unified search (posts + profiles + places)
"/api/search", // Fallback: Posts only
"/api/reco/search",
"/api/reco/suggest",
@ -30,7 +31,7 @@ function normalizeOne(r) {
.toString()
.trim();
// coords possibles
// coords possibles (support multiple formats)
const lat = typeof r.lat === "number" ? r.lat : (typeof r.latitude === "number" ? r.latitude : null);
const lon = typeof r.lon === "number" ? r.lon : (typeof r.lng === "number" ? r.lng : null);
@ -40,13 +41,17 @@ function normalizeOne(r) {
: (lat != null && lon != null ? [lon, lat] : null);
const type = (r.type ?? r.kind ?? r.entity ?? "").toString().toLowerCase().trim();
const kind = type || (coords ? "place" : "item");
return {
id: (r.id ?? r._id ?? r.key ?? title).toString(),
type: type || (coords ? "place" : "item"),
type: kind,
kind: kind, // Keep both for compatibility
title,
subtitle: (r.subtitle ?? r.sub ?? r.extra ?? r.category ?? "").toString(),
coords,
lat,
lon,
raw: r,
};
}