Habib Ali Machpud
← Writing

Learning note

Designing search for a technical portfolio

Preserve technical terms, evidence labels, and published links while keeping indexing atomic and repeatable.

Start with the evidence

For Ask Habib, a useful search result is a page a visitor can inspect. A result keeps the page title, evidence label, canonical URL, and a short text excerpt. Multiple matching chunks from one page produce one result. A system-design proposal retains that label alongside professional experience and project work.

The implementation is lexical: PostgreSQL matches English word stems and simple tokens. Deterministic aliases connect Postgres to PostgreSQL, k8s to Kubernetes, and names such as C++, .NET, and Node.js to safe tokens. Path components preserve terms such as pgx in pgx/v5. An identifier allowlist helps recognise technical terms; an ambiguous word such as Go does not become a strong identifier on its own. This is text processing, without an inference about a visitor’s intent.

Make publication part of indexing

Markdown and strict frontmatter are validated before any database write. Content hashes include metadata and normalized Markdown. A separate pipeline fingerprint records parsing, term extraction, and chunking rules, so a rule change requires an explicit full rebuild.

The job keeps a session advisory lock on one acquired PostgreSQL connection. It checks the frontend’s release and public URL manifest before opening the short write transaction. Changed documents, replacement chunks, removed documents, and the corpus marker commit together. A failed write leaves the previous corpus intact; a repeat run preserves unchanged row identities and timestamps.

Normal deletion or renaming requires a retained redirect. A separately named operator recovery mode can restore an earlier release’s corpus after its frontend has been verified. That exception is necessary because old source cannot anticipate URLs introduced in a later release.

Bound the public path

Search accepts at most 128 Unicode characters and 16 validated tokens. SQL parameters carry a small generated tsquery grammar; user punctuation never becomes query syntax. Queries have a two-second deadline. A separate token bucket refills at 60 requests per minute with a burst of 20. Its bounded entries use ephemeral HMAC keys derived from trusted visitor identity, and expire after 15 minutes of inactivity. Raw IP addresses and search text are not logged.

The browser writes titles and snippets through DOM text nodes. It links only to canonical portfolio URLs, cancels obsolete requests, and provides static section links when search fails. No HTML highlighting is interpreted from a result.

What has been tested

Local Podman tests use real PostgreSQL for page grouping, aliases, repeat jobs, failed transactions, redirect enforcement, competing indexers, cancellation, and filtering results from a different content release. HTTP smoke checks cover publication ordering, unavailable search, recovery, and throttling. Browser checks cover keyboard submission, labelled results, and the empty state.

Production acceptance on 21 November 2026 indexed 17 documents into 95 chunks. Repeat indexing preserved all stored data and timestamps. The encrypted off-VPS backup restored with matching content hashes, index markers, and table privileges; an application rollback and exact-release restore retained the same database.

One warm production query for PostgreSQL took 1.905 ms of database execution time. That is a small-corpus observation, not a capacity benchmark. English and simple GIN indexes trade extra writes and storage for indexed matching as the corpus grows; the planner may prefer other indexes for this small data set. The decision is recorded in ADR-018.