DEV: Make search results blurb non-pg headlines setting dependent (#20939)

Followup to #20915. If we're grouping search results that don't rely on core's search, we won't have access to pg headlines. This is now configurable via the constructor, defaulting to `SiteSetting.use_pg_headlines_for_excerpt`
This commit is contained in:
Roman Rizzi 2023-04-03 11:09:36 -03:00 committed by GitHub
parent f3402be262
commit ecac62dd6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -24,6 +24,7 @@ class Search
:search_context, :search_context,
:more_full_page_results, :more_full_page_results,
:error, :error,
:use_pg_headlines_for_excerpt,
) )
attr_accessor :search_log_id attr_accessor :search_log_id
@ -36,7 +37,8 @@ class Search
search_context:, search_context:,
blurb_length: nil, blurb_length: nil,
blurb_term: nil, blurb_term: nil,
is_header_search: false is_header_search: false,
use_pg_headlines_for_excerpt: SiteSetting.use_pg_headlines_for_excerpt
) )
@type_filter = type_filter @type_filter = type_filter
@term = term @term = term
@ -50,6 +52,7 @@ class Search
@groups = [] @groups = []
@error = nil @error = nil
@is_header_search = is_header_search @is_header_search = is_header_search
@use_pg_headlines_for_excerpt = use_pg_headlines_for_excerpt
end end
def error=(error) def error=(error)
@ -73,7 +76,7 @@ class Search
if post.post_search_data.version >= SearchIndexer::MIN_POST_BLURB_INDEX_VERSION && if post.post_search_data.version >= SearchIndexer::MIN_POST_BLURB_INDEX_VERSION &&
!Search.segment_chinese? && !Search.segment_japanese? !Search.segment_chinese? && !Search.segment_japanese?
if SiteSetting.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')
prefix_omission = scrubbed_headline.start_with?(post.leading_raw_data) ? "" : OMISSION prefix_omission = scrubbed_headline.start_with?(post.leading_raw_data) ? "" : OMISSION
postfix_omission = scrubbed_headline.end_with?(post.trailing_raw_data) ? "" : OMISSION postfix_omission = scrubbed_headline.end_with?(post.trailing_raw_data) ? "" : OMISSION