Cookbook
Copy-paste recipes for the most common AACsearch SDK patterns — autocomplete, faceted search, product listings, click tracking, scoped tokens, multi-tenant, multi-locale, and graceful failure.
These recipes assume you have already followed Browser SDK setup and have a search-only API key (ss_search_*). All snippets are typed against @aacsearch/client (Node + browser) — adapt to other languages as needed.
Pick a recipe
| Recipe | What you get |
|---|---|
| Autocomplete | Debounced search-as-you-type with a dropdown of suggestions |
| Faceted search | Multi-select filter sidebar driven by AACsearch facet counts |
| Product listing page | Server-rendered PLP with filters, sort, pagination |
| Infinite scroll | Load-more pagination using TanStack Query's useInfiniteQuery |
| Click analytics | Track result clicks and conversions with events/track |
| No-results recommendations | Show fallback content when found: 0 |
| Fallback search | Degrade gracefully when AACsearch is unreachable |
| Scoped B2B catalog | Per-customer price tiers and product visibility via scoped tokens |
| Marketplace tenant isolation | Multi-vendor marketplace where each storefront sees only its own SKUs |
| Multi-locale catalog | Same products in en/de/es/fr/ru — single index with locale facet |
Common setup
Every recipe assumes one of these clients:
// Browser-safe (search only)
import { SearchClient } from "@aacsearch/client";
const client = new SearchClient({
baseUrl: process.env.NEXT_PUBLIC_AACSEARCH_BASE_URL!,
apiKey: process.env.NEXT_PUBLIC_AACSEARCH_SEARCH_KEY!, // ss_search_*
indexSlug: "products",
});// Server-only (full CRUD)
import { AdminClient } from "@aacsearch/client";
const admin = new AdminClient({
baseUrl: process.env.AACSEARCH_BASE_URL!,
apiKey: process.env.AACSEARCH_ADMIN_KEY!, // aa_admin_*
projectId: process.env.AACSEARCH_ORG_ID!,
});Sample dataset assumed across recipes:
type Product = {
id: string;
external_id: string;
title: string;
description: string;
brand: string;
categories: string[];
price: number; // major units, decimal
in_stock: boolean;
locale: "en" | "de" | "es" | "fr" | "ru";
organization_id: string; // for multi-tenant recipes
customer_tier?: "retail" | "wholesale" | "vip"; // B2B only
};Every recipe is independently runnable. They share conventions (sample dataset, env var names, naming) but you can copy any one without setting up the others first.
What you will not find here
- Index management — see SDK reference
- Authentication setup — see API keys
- Error handling fundamentals — see Errors and rate limits
- Connector implementation — see Connector API lifecycle
Related
Swift SDK
Install and use the aacsearch-swift SDK for search, index management, synonyms, curations, and analytics from iOS, macOS, and visionOS apps.
Autocomplete
Debounced search-as-you-type with a dropdown of suggestions. Uses `useDeferredValue` for React-idiomatic debounce and `multi-search` to fetch products + categories in one round trip.