fix: slim help center search results (#13761)
Fixes help center public article search so query responses stay compact and locale-scoped. Whitespace-only queries are now treated as empty in both the portal UI and the server-side search path, and search suggestions stay aligned with the trimmed query. Fixes: https://github.com/chatwoot/chatwoot/issues/10402 Closes: https://github.com/chatwoot/chatwoot/issues/10402 ## Why The public help center search endpoint reused the full article serializer for query responses, which returned much more data than the search suggestions UI needed. That made responses heavier than necessary and also surfaced nested portal and category data that made the results look cross-locale. Whitespace-only searches could also still reach the backend search path, and in Enterprise that meant embedding search could be invoked for a blank query. ## What changed - return a compact search-specific payload for article query responses - keep the existing full article serializer for normal article listing responses - preserve current-locale search behavior for the portal search flow - trim whitespace-only search terms on the client so they do not open suggestions or trigger a request - reuse the normalized query on the backend so whitespace-only requests are treated as empty searches in both OSS and Enterprise paths - pass the trimmed search term into suggestions so highlighting matches the actual query being sent - add request and frontend regression coverage for compact payloads, locale scoping, and whitespace-only search behavior ## Validation 1. Open `/hc/:portal/:locale` in the public help center. 2. Enter only spaces in the search box and confirm suggestions do not open. 3. Search for a real term and confirm suggestions appear. 4. Verify the results are limited to the active locale. 5. Click a suggestion and confirm it opens the correct article page. 6. Inspect the query response and confirm it returns the compact search payload instead of the full article serializer. --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -34,18 +34,53 @@ RSpec.describe 'Public Articles API', type: :request do
|
||||
end
|
||||
|
||||
it 'get all articles with searched text query' do
|
||||
article2 = create(:article,
|
||||
account_id: account.id,
|
||||
portal: portal,
|
||||
category: category,
|
||||
author_id: agent.id,
|
||||
content: 'this is some test and funny content')
|
||||
expect(article2.id).not_to be_nil
|
||||
long_content = ([('intro ' * 30).strip, 'funny', ('tail ' * 30).strip].join(' ')).strip
|
||||
create(:article,
|
||||
account_id: account.id,
|
||||
portal: portal,
|
||||
category: category,
|
||||
author_id: agent.id,
|
||||
content: long_content)
|
||||
|
||||
get "/hc/#{portal.slug}/#{category.locale}/categories/#{category.slug}/articles.json", params: { query: 'funny' }
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body, symbolize_names: true)[:payload]
|
||||
expect(response_data.length).to eq(1)
|
||||
expect(response_data[0].keys).to match_array(%i[id category_id title content link])
|
||||
expect(response_data[0][:content]).to include('funny')
|
||||
expect(response_data[0][:content].length).to be < long_content.length
|
||||
end
|
||||
|
||||
it 'limits search results to the current locale' do
|
||||
create(:article,
|
||||
account_id: account.id,
|
||||
portal: portal,
|
||||
category: category,
|
||||
author_id: agent.id,
|
||||
title: 'English locale result',
|
||||
content: 'shared-search-term in english')
|
||||
create(:article,
|
||||
account_id: account.id,
|
||||
portal: portal,
|
||||
category: category_2,
|
||||
author_id: agent.id,
|
||||
title: 'Spanish locale result',
|
||||
content: 'shared-search-term in spanish')
|
||||
|
||||
get "/hc/#{portal.slug}/#{category.locale}/articles.json", params: { query: 'shared-search-term' }
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body, symbolize_names: true)[:payload]
|
||||
expect(response_data.pluck(:title)).to eq(['English locale result'])
|
||||
end
|
||||
|
||||
it 'treats whitespace-only queries as empty searches' do
|
||||
get "/hc/#{portal.slug}/#{category.locale}/articles.json", params: { query: ' ' }
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body, symbolize_names: true)[:payload]
|
||||
expect(response_data.length).to eq(3)
|
||||
expect(response_data.first).to include(:description, :slug, :portal)
|
||||
end
|
||||
|
||||
it 'get all popular articles if sort params is passed' do
|
||||
|
||||
@@ -14,6 +14,14 @@ RSpec.describe 'Public Articles API', type: :request do
|
||||
get "/hc/#{portal.slug}/en/articles.json", params: { query: 'funny' }
|
||||
expect(Article).to have_received(:vector_search)
|
||||
end
|
||||
|
||||
it 'does not use vector search for whitespace-only queries' do
|
||||
allow(Article).to receive(:vector_search)
|
||||
|
||||
get "/hc/#{portal.slug}/en/articles.json", params: { query: ' ' }
|
||||
|
||||
expect(Article).not_to have_received(:vector_search)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user