mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 03:08:23 +08:00
FEATURE: Better handling of quotation marks in site text search
It also matches 3 dots with the ellipsis symbol.
This commit is contained in:
@ -39,11 +39,22 @@ module I18n
|
||||
false
|
||||
end
|
||||
|
||||
def self.create_search_regexp(query, as_string: false)
|
||||
regexp = Regexp.escape(query)
|
||||
|
||||
regexp.gsub!(/['‘’‚‹›]/, "['‘’‚‹›]")
|
||||
regexp.gsub!(/["“”„«»]/, '["“”„«»]')
|
||||
regexp.gsub!(/(?:\\\.\\\.\\\.|…)/, '(?:\.\.\.|…)')
|
||||
|
||||
as_string ? regexp : /#{regexp}/i
|
||||
end
|
||||
|
||||
def search(locale, query)
|
||||
results = {}
|
||||
regexp = self.class.create_search_regexp(query)
|
||||
|
||||
fallbacks(locale).each do |fallback|
|
||||
find_results(/#{Regexp.escape(query)}/i, results, translations[fallback])
|
||||
find_results(regexp, results, translations[fallback])
|
||||
end
|
||||
|
||||
results
|
||||
|
Reference in New Issue
Block a user