From 679a773411cceadc9166c419280d1a26fa4f0ae5 Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Thu, 14 Mar 2024 14:40:46 -0300 Subject: [PATCH] FIX: Handle nil post_search_data for search result (#26179) Since we are introducing new ways to search in Discourse, like the AI semantic search using embeddings, posts can be part of a search result list without having any search data. Since the code path already handles this, we only need to add a safety check when accessing the post_search_data. --- lib/search/grouped_search_results.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/search/grouped_search_results.rb b/lib/search/grouped_search_results.rb index 05da9722681..57bbc13be8d 100644 --- a/lib/search/grouped_search_results.rb +++ b/lib/search/grouped_search_results.rb @@ -78,8 +78,10 @@ class Search def blurb(post) opts = { term: @blurb_term, blurb_length: @blurb_length } + post_search_data_version = post&.post_search_data&.version - if post.post_search_data.version >= SearchIndexer::MIN_POST_BLURB_INDEX_VERSION && + if post_search_data_version.present? && + post_search_data_version >= SearchIndexer::MIN_POST_BLURB_INDEX_VERSION && !Search.segment_chinese? && !Search.segment_japanese? if use_pg_headlines_for_excerpt scrubbed_headline = post.headline.gsub(SCRUB_HEADLINE_REGEXP, '\1')