fix(search): scope global result types

This commit is contained in:
2026-06-07 09:39:03 +08:00
parent 9027551768
commit ff2e5114a5
3 changed files with 48 additions and 7 deletions
+8 -4
View File
@@ -49,11 +49,11 @@ Hermes task landing checklist:
## Current Baseline
- Current tracking checkpoint: 2026-06-07 P3.87 search article payload parity, prepared as `feat(search): align article result payloads`.
- Latest implementation checkpoint: this checkpoint, prepared as `feat(search): align article result payloads`.
- Latest documentation/tooling checkpoint: this tracker update records Chatwoot search article partial payload parity for `portal_slug` and `category_name`. No route artifacts change.
- Current tracking checkpoint: 2026-06-07 P3.88 global search type-scope parity, prepared as `fix(search): scope global result types`.
- Latest implementation checkpoint: this checkpoint, prepared as `fix(search): scope global result types`.
- Latest documentation/tooling checkpoint: this tracker update records Chatwoot global SearchAPI result-type scope parity. No route artifacts change.
- Plan landing status: complete for the current known Hermes plans and user-confirmed scope. Future work should update this file directly instead of opening a parallel tracker.
- Worktree status at this implementation checkpoint: SearchAPI article results now hydrate Chatwoot `_article` fields `portal_slug` and `category_name` from DB-backed handlers and Meilisearch documents, while retaining P3.86 message payloads, P3.85 conversation payloads, P3.84 agent-sender filter parity, P3.83 conversation ordering, P3.82 contact-conversation reindex fanout, P3.81 conversation identity search, P3.80 search time-bound parity, P3.79 advanced-search feature gates, P3.78 message recency, P3.77 current-user inbox access, and prior checkpoints. Live API/browser/enterprise smoke still needs the full PostgreSQL/Redis/Meilisearch/GoChat/Vite/Chrome stack.
- Worktree status at this implementation checkpoint: Global SearchAPI now ignores unsupported local `types` expansions and scopes the search backend to Chatwoot's four result families: conversations, contacts, messages, and articles. This retains P3.87 article payloads, P3.86 message payloads, P3.85 conversation payloads, P3.84 agent-sender filter parity, P3.83 conversation ordering, P3.82 contact-conversation reindex fanout, P3.81 conversation identity search, P3.80 search time-bound parity, P3.79 advanced-search feature gates, P3.78 message recency, P3.77 current-user inbox access, and prior checkpoints. Live API/browser/enterprise smoke still needs the full PostgreSQL/Redis/Meilisearch/GoChat/Vite/Chrome stack.
- Next executable implementation checkpoint: continue Phase 2/3 drift audit for the next reused-frontend mismatch, or run B12 live smoke when the full PostgreSQL/Redis/Meilisearch/GoChat/Vite/Chrome stack is available. Re-run Phase 6 placeholder audit after future route/smoke changes.
- `go test ./...` passes when run outside the restricted socket sandbox for the latest implementation baseline; the latest docs/tooling checkpoint verified `scripts/parity_frontend_smoke.sh --check` with workspace-local temp/cache dirs after `/tmp` was full.
- Route dump succeeds with `967` registered routes after profile MFA route tracking.
@@ -156,6 +156,7 @@ This table is the shortest authoritative handoff view. If an older lower section
| Priority | Workstream | Current state | Next checkpoint | Commit close rule |
| --- | --- | --- | --- | --- |
| 0 | P3.88 global search type-scope parity | Implemented for reused global SearchAPI: `GET /search` now scopes backend searches to the same four result families rendered by Chatwoot `search/index.json.jbuilder` (`conversations`, `contacts`, `messages`, `articles`) and ignores unsupported local `types=company/help_center` expansion before DB fallback or Meilisearch execution. | Keep in Review; reopen from B12 global-search smoke or fresh reference/frontend evidence for additional rendered result families, company search UI integration, or Searchkick all-type behavior drift. | Focused SearchHandler global type-scope tests passed; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change. |
| 0 | P3.87 search article payload parity | Implemented for reused SearchAPI article cards: DB-backed handlers and Meilisearch documents now carry Chatwoot `_article` `portal_slug` and `category_name` fields, so article search cards can route to `portals/:portalSlug/:locale/articles/edit/:id` and display category names without adapter code. Durable index replay and full reindex preload article portal/category relations. | Keep in Review; reopen from B12 search/help-center smoke or fresh reference evidence for article description payload drift, translated-article locale routing, or category/portal deletion edge cases. | Focused SearchHandler, SearchRepo, DurableSearchIndexer, reindex, and document-builder tests passed; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change. |
| 0 | P3.86 search message payload parity | Implemented for reused SearchAPI message cards: DB-backed handlers now serialize message search hits through the Chatwoot `_message` contract with conversation display IDs, sender push data, and attachment push data; Meilisearch message documents and reindex/durable indexing paths now carry display-ID and attachment payload data when relations are loaded. | Keep in Review; reopen from B12 search smoke or fresh reference evidence for exact AgentBot sender push data, voice-call `call` payloads, or provider-specific attachment metadata beyond the inspected frontend card usage. | Focused SearchHandler, SearchRepo, DurableSearchIndexer, reindex, and document-builder tests passed; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change. |
| 0 | P3.85 search conversation payload parity | Implemented for reused SearchAPI conversation cards: DB fallback results and Meilisearch documents now carry Chatwoot search Jbuilder fields `message`, `contact`, `inbox`, `agent`, and `additional_attributes`, with conversation indexing/reindexing preloading those display relations. | Keep in Review; reopen from B12 search smoke or fresh reference evidence for exact `api/v1/models/message` field drift, message attachment/sender serialization gaps, or Meilisearch document payload bloat/per-page tuning. | Focused SearchHandler, SearchRepo, and document-builder tests passed; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change. |
@@ -251,6 +252,7 @@ These rows are the executable development plan from this point forward. A checkp
| ID | Owner files | Reference files | Work to land | Exit gate |
| --- | --- | --- | --- | --- |
| P3.88 global search type-scope parity | `internal/handler/api/v1/search_handler.go`, `internal/handler/api/v1/search_handler_test.go` | `reference/chatwoot/app/controllers/api/v1/accounts/search_controller.rb`, `reference/chatwoot/app/services/search_service.rb#perform`, `reference/chatwoot/app/views/api/v1/accounts/search/index.json.jbuilder`, `reference/chatwoot/app/javascript/dashboard/api/search.js` | Global SearchAPI now follows Chatwoot's `search('all')` rendered surface by forcing backend execution to `conversations`, `contacts`, `messages`, and `articles` for `GET /search`, ignoring unsupported local `types=company/help_center` expansions before DB fallback or Meilisearch execution. | Review by `fix(search): scope global result types`; focused SearchHandler tests prove unsupported `types=company` does not call company search and the raw payload remains the four Chatwoot result families; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change. |
| P3.87 search article payload parity | `internal/handler/api/v1/search_handler.go`, `internal/search/engine.go`, `internal/service/search_indexer_worker.go`, `cmd/reindex_search/main.go`, search handler/document/indexer tests | `reference/chatwoot/app/views/api/v1/accounts/search/_article.json.jbuilder`, `articles.json.jbuilder`, `reference/chatwoot/app/javascript/dashboard/modules/search/components/SearchResultArticlesList.vue`, `SearchResultArticleItem.vue` | Article SearchAPI results now match the reused frontend card route/display fields: `portal_slug` is hydrated from the article portal, `category_name` is hydrated from the optional article category, DB-backed handlers reload those relations for result rows and Meilisearch hits, and durable/full reindex paths preload the relations before document creation. | Review by `feat(search): align article result payloads`; focused SearchHandler, SearchRepo, DurableSearchIndexer, reindex, and document-builder tests prove DB-backed payload hydration plus Meilisearch nested payload shape; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change. |
| P3.86 search message payload parity | `internal/handler/api/v1/search_handler.go`, `internal/search/engine.go`, `internal/service/search_indexer_worker.go`, `cmd/reindex_search/main.go`, search handler/document/indexer tests | `reference/chatwoot/app/views/api/v1/models/_message.json.jbuilder`, `reference/chatwoot/app/models/message.rb#push_event_data`, `reference/chatwoot/app/models/attachment.rb#push_event_data`, `reference/chatwoot/app/javascript/dashboard/modules/search/components/SearchResultMessagesList.vue`, `SearchResultMessageItem.vue` | Message SearchAPI results now match the reused frontend card needs from Chatwoot's `_message` serializer: `conversation_id` is the conversation display ID for navigation, `sender` is hydrated from persisted contact/user rows for DB-backed handlers, attachments use Chatwoot-style push data, and Meilisearch message documents carry display-ID/attachment payload data when relations are preloaded by durable indexing and full reindex. | Review by `feat(search): align message result payloads`; focused SearchHandler, SearchRepo, DurableSearchIndexer, reindex, and document-builder tests prove DB-backed payload hydration plus Meilisearch nested payload shape; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change. |
| P3.83 search conversation ordering parity | `internal/repository/search_repo.go`, `internal/repository/search_repo_test.go` | `reference/chatwoot/app/services/search_service.rb#filter_conversations` | Conversation DB fallback search default ordering now uses `conversations.created_at DESC, conversations.id DESC`, matching Chatwoot `@conversations = conversations_query.order('conversations.created_at DESC')`, instead of the older local `last_activity_at DESC` conversation-list default. | Review by `feat(search): align conversation search order`; focused test proves created-at ordering wins even when `last_activity_at` points the other way; full `go test ./...` passed outside the restricted socket sandbox after retrying an unrelated `internal/worker` SQLite in-memory flake; `git diff --check` passed. No route artifacts change. |
@@ -362,6 +364,7 @@ This ledger records the committed parity checkpoints that future slices should b
| Commit | Scope | Verification summary | Follow-up state |
| --- | --- | --- | --- |
| `fix(search): scope global result types` | Advances P3.88 with Chatwoot global SearchAPI result-family parity. `GET /search` now forces the backend filter to conversations, contacts, messages, and articles before DB fallback or Meilisearch execution, matching `SearchService#perform` plus `search/index.json.jbuilder` and preventing local company/help-center document types from affecting reused frontend global-search results. | `go test ./internal/handler/api/v1 -run 'TestSearchHandler_GlobalSearch_(Success\|WithFilterParams\|UsesReferenceResultTypes)' -count=1` passed with workspace-local temp/cache dirs; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change. | Move P3.88 to Review; continue Phase 2/3 drift audit, Phase 6 placeholder audit, or B12 live smoke. |
| `feat(search): align article result payloads` | Advances P3.87 with Chatwoot SearchAPI article result payload parity. Article search hits now include `portal_slug` and `category_name` from the same partial fields consumed by the reused article search card; DB-backed handlers reload portal/category relations for article results and Meilisearch hits, and durable/full reindex paths preload those relations before document creation. | `go test ./internal/handler/api/v1 ./internal/search ./internal/repository ./internal/service ./cmd/reindex_search -run 'TestSearchHandler_SearchArticles\|TestArticleDocumentCarriesSearchPartialData\|TestSearchRepo_SearchArticles\|TestDurableSearchIndexerPreloadsArticlePortalAndCategory' -count=1` passed with workspace-local temp/cache dirs; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change. | Move P3.87 to Review; continue Phase 2/3 drift audit, Phase 6 placeholder audit, or B12 live smoke. |
| `feat(search): align message result payloads` | Advances P3.86 with Chatwoot SearchAPI message result payload parity. Message search hits now route to conversation display IDs instead of DB IDs, expose `sender` push data for DB-backed results, expose attachment push data for DB-backed and Meilisearch document results, and index/reindex message documents with preloaded conversation/attachment display data where available. | `go test ./internal/handler/api/v1 ./internal/search ./internal/repository ./internal/service ./cmd/reindex_search -run 'TestSearchHandler_SearchMessages\|TestDocumentBuildersSetStableUIDAndType\|TestMessageDocumentCarriesChatwootPayloadData\|TestSearchRepo_SearchMessages\|TestDurableSearchIndexer' -count=1` passed with workspace-local temp/cache dirs; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change. | Move P3.86 to Review; continue Phase 2/3 drift audit, Phase 6 placeholder audit, or B12 live smoke. |
| `feat(search): align conversation result payloads` | Advances P3.85 with Chatwoot search conversation-result payload parity. SearchAPI conversation hits now expose nested `message`, `contact`, `inbox`, `agent`, and `additional_attributes` data from both DB fallback rows and Meilisearch documents, and the indexing/reindexing paths preload the display relations needed by the reused frontend cards. | Focused SearchHandler, SearchRepo, and document-builder tests passed; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change. | Move P3.85 to Review; continue Phase 2/3 drift audit, Phase 6 placeholder audit, or B12 live smoke. |
@@ -2728,3 +2731,4 @@ Verification milestone gates:
- 2026-06-07: Documentation checkpoint prepared as `docs: reconcile parity tracker`; current baseline now points at `0b47066 feat(search): align conversation result payloads`, the stale P3.39 next-slice wording is replaced, and the Commit Ledger now includes P3.84/P3.85 so the plan can be followed from this document without reading older Hermes notes. Verification for this docs-only checkpoint: `git diff --check`; no Go code or route artifacts changed.
- 2026-06-07: P3.86 search message payload checkpoint prepared as `feat(search): align message result payloads`; audited Chatwoot `_message.json.jbuilder`, `Message#push_event_data`, `Attachment#push_event_data`, and reused `SearchResultMessagesList.vue`/`SearchResultMessageItem.vue`. GoChat SearchAPI message results now hydrate DB-backed hits with conversation display IDs, sender push data, and attachment push data; Meilisearch hit serialization preserves nested sender/attachment payloads; message documents, durable index replay, and full `cmd/reindex_search` now preload or carry display/attachment data where available. Focused SearchHandler, SearchRepo, DurableSearchIndexer, reindex, and document-builder tests passed; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change.
- 2026-06-07: P3.87 search article payload checkpoint prepared as `feat(search): align article result payloads`; audited Chatwoot search `_article.json.jbuilder`, `articles.json.jbuilder`, and reused `SearchResultArticlesList.vue`/`SearchResultArticleItem.vue`. GoChat SearchAPI article results now hydrate `portal_slug` and `category_name` from portal/category relations for DB-backed handlers and Meilisearch hits; article documents, durable index replay, and full `cmd/reindex_search` now preload or carry those route/display fields where available. Focused SearchHandler, SearchRepo, DurableSearchIndexer, reindex, and document-builder tests passed; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change.
- 2026-06-07: P3.88 global search type-scope checkpoint prepared as `fix(search): scope global result types`; audited Chatwoot `SearchController#search`, `SearchService#perform`, `search/index.json.jbuilder`, and reused dashboard `SearchAPI.get`. GoChat global SearchAPI now forces backend execution to the four rendered Chatwoot result families (`conversations`, `contacts`, `messages`, `articles`) and ignores unsupported local `types=company/help_center` expansion before DB fallback or Meilisearch search, so hidden local document types cannot affect reused frontend global-search results. Focused SearchHandler tests passed; full `go test ./...` passed outside the restricted socket sandbox; `git diff --check` passed. No route artifacts change.
@@ -15,6 +15,13 @@ import (
const chatwootSearchPerPage = 15
var chatwootGlobalSearchTypes = []search.SearchResultType{
search.ResultTypeConversation,
search.ResultTypeContact,
search.ResultTypeMessage,
search.ResultTypeArticle,
}
// SearchHandler handles global search API endpoints.
// Reference: Chatwoot GlobalSearchService — cross-entity search with advanced filtering.
type SearchHandler struct {
@@ -79,6 +86,7 @@ func (h *SearchHandler) GlobalSearch(c *gin.Context) {
query := c.Query("q")
filter := parseChatwootSearchFilter(c)
filter.Types = append([]search.SearchResultType(nil), chatwootGlobalSearchTypes...)
result, svcErr := h.svc.GlobalSearch(c.Request.Context(), accountID, query, &filter)
if svcErr != nil {
+32 -3
View File
@@ -35,9 +35,10 @@ type mockSearchRepo struct {
contactTotal int64
contactErr error
companies []model.Company
companyTotal int64
companyErr error
companies []model.Company
companyTotal int64
companyErr error
companyCalled bool
articles []model.Article
articleTotal int64
@@ -58,6 +59,7 @@ func (m *mockSearchRepo) SearchContacts(ctx context.Context, accountID uint, que
}
func (m *mockSearchRepo) SearchCompanies(ctx context.Context, accountID uint, query string, filter *search.SearchFilter) ([]model.Company, int64, error) {
m.companyCalled = true
return m.companies, m.companyTotal, m.companyErr
}
@@ -176,6 +178,33 @@ func TestSearchHandler_GlobalSearch_WithFilterParams(t *testing.T) {
assert.Len(t, payload["conversations"], 1)
}
func TestSearchHandler_GlobalSearch_UsesReferenceResultTypes(t *testing.T) {
repo := &mockSearchRepo{
companies: []model.Company{{ID: 99, AccountID: 1, Name: "Acme"}},
companyTotal: 1,
}
svc := search.NewSearchService(repo)
handler := NewSearchHandler(svc)
router := setupSearchHandlerRouter(handler)
w := httptest.NewRecorder()
req := httptest.NewRequest("GET", "/api/v1/accounts/1/search?q=Acme&types=company", nil)
router.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
assert.False(t, repo.companyCalled)
var body map[string]interface{}
assert.NoError(t, json.Unmarshal(w.Body.Bytes(), &body))
payload, ok := body["payload"].(map[string]interface{})
require.True(t, ok)
assert.Contains(t, payload, "conversations")
assert.Contains(t, payload, "contacts")
assert.Contains(t, payload, "messages")
assert.Contains(t, payload, "articles")
assert.NotContains(t, payload, "companies")
}
// ========== SearchConversations handler tests ==========
func TestSearchHandler_SearchConversations_Success(t *testing.T) {