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.
This commit is contained in:
Rafael dos Santos Silva 2024-03-14 14:40:46 -03:00 committed by GitHub
parent c662a99db3
commit 679a773411
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -78,8 +78,10 @@ class Search
def blurb(post) def blurb(post)
opts = { term: @blurb_term, blurb_length: @blurb_length } 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? !Search.segment_chinese? && !Search.segment_japanese?
if use_pg_headlines_for_excerpt if use_pg_headlines_for_excerpt
scrubbed_headline = post.headline.gsub(SCRUB_HEADLINE_REGEXP, '\1') scrubbed_headline = post.headline.gsub(SCRUB_HEADLINE_REGEXP, '\1')