Skip to content

Feat/search v2#375

Merged
GorillaGigabytes merged 11 commits into
mainfrom
feat/search-v2
May 16, 2026
Merged

Feat/search v2#375
GorillaGigabytes merged 11 commits into
mainfrom
feat/search-v2

Conversation

@daveaugustus
Copy link
Copy Markdown
Contributor

No description provided.

- Add generation counter to ConnManager to prevent N goroutines from each
  reconnecting when they all fail on the same dead connection. Only the
  first caller reconnects; the rest piggyback on the fresh connection.
- Serialize PublishMessage through pubMu when confirms are enabled to
  prevent orphan confirmations from causing false timeouts in
  publishAndWaitConfirm.
- Fix Debugf format verb in GetDueScheduledBlogs log statement.
Backend implementation of Search v2 across gateway + user + blog services.

Highlights:

- Gateway: new internal/blogsearch (ES client + query builder + routes for /api/v2/blog/search/v2 and /api/v2/search/suggest).

- Gateway: internal/cache/searchcache fail-open Redis cache with structured search_event logging (latency, cache_hit, zero_result, result_count).

- Users svc: new database/user_search_v2.go backed by pg_trgm GIN indexes on user_account.search_doc; service exposes v2 search RPC.

- Blog svc: v2_queries tweaks to support denormalised reindex.

- Postgres migrations 000006 (CREATE EXTENSION pg_trgm) and 000007 (STORED search_doc column + GIN indexes).

- ES mapping v3 (documents/reindex/mapping_v3.json) + reindex tool (scripts/reindex_blogs_v3) with dry-run, atomic alias swap pattern.

- Deprecation: /api/v1/user/search and /api/v2/blog/search now 308 redirect to v2 paths, preserving query string.

- Critical fix: blogsearch.NewClient prefers OPENSEARCH_OS_HOST (container-network) over OPENSEARCH_ADDRESS (host-script).

- Critical fix: ES bool filter changed from filter:term=false to must_not:term=true to handle legacy docs missing is_archived/is_draft fields.

- Docs: design plan, implementation plan, prod deploy runbook, OpenAPI updates for both services.
… queries

mapping_v3.json declares these three fields as top-level keyword (no .keyword sub-field). Legacy term queries used '<field>.keyword', which silently matched zero docs against v3 because ES does not error on missing fields.

Symptoms post cut-over: GET /api/v2/blog/:id, /api/v2/blog/:id/stats, /api/v2/blog/user/:username, /api/v2/blog/trending, and archive/delete code paths returned 404 'the blog does not exist' even though docs were indexed.

Fix: 25 callsites across opensearch.go (11), v2_queries.go (10), blogs_matadata.go (3), query.go (1) changed from '<field>.keyword' to '<field>'. Backward-compatible with v2 mapping because blog IDs / account IDs tokenise to a single lowercase term under the default analyzer.

Writes (IndexRequest/UpdateRequest by DocumentID) are unaffected. No _update_by_query / _delete_by_query callers.

Docs: runbook gains §3.1 (mapping breaking change), §6 critical non-search smoke tests, §10 rollback row. Implementation plan Phase 2 records the fix.
- Switch WHERE predicate from \ua.search_doc % $1\ to \$1 <% ua.search_doc\ and rank \similarity(...)\ -> \word_similarity($1, ua.search_doc)\.
- pg_trgm \%\ (similarity) normalises by trigram count of both strings, so short queries against long search_docs fall below the 0.3 threshold and miss real matches (e.g. searching "joseph" against "SJ Shinu Joseph The fourth monkey" yields similarity=0.21, no hit).
- \<% \ (word_similarity) scores against the best-matching extent of the doc, immune to doc length. Same scenario yields 1.0 and matches.
- Existing GIN(gin_trgm_ops) index on search_doc supports \<%\ natively in PG 11+; no schema change needed.
- Verified empirically against dev DB: predicate change moves result count from 0 -> 1 for query "joseph".
@github-actions
Copy link
Copy Markdown

🏷️ [bumpr]
Next version:v1.9.1
Changes:v1.9.0...the-monkeys:feat/search-v2

@GorillaGigabytes GorillaGigabytes merged commit 995f8ef into main May 16, 2026
11 checks passed
@github-actions
Copy link
Copy Markdown

🚀 [bumpr] Bumped!
New version:v1.9.1
Changes:v1.9.0...v1.9.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants