0
0
Fork 0

Add option to not consider word boundaries when processing keyword filtering (#7975)

* Add option to not consider word boundaries when filtering phrases

* Add a few tests for keyword/phrase filtering
This commit is contained in:
ThibG 2018-07-09 02:22:09 +02:00 committed by Eugen Rochko
parent 451e585b97
commit 1ca4e51eb3
9 changed files with 61 additions and 11 deletions

View file

@ -200,7 +200,16 @@ class FeedManager
active_filters = Rails.cache.fetch("filters:#{receiver_id}") { CustomFilter.where(account_id: receiver_id).active_irreversible.to_a }.to_a
active_filters.select! { |filter| filter.context.include?(context.to_s) && !filter.expired? }
active_filters.map! { |filter| Regexp.new("\\b#{Regexp.escape(filter.phrase)}\\b", true) }
active_filters.map! do |filter|
if filter.whole_word
sb = filter.phrase =~ /\A[[:word:]]/ ? '\b' : ''
eb = filter.phrase =~ /[[:word:]]\Z/ ? '\b' : ''
/(?mix:#{sb}#{Regexp.escape(filter.phrase)}#{eb})/
else
/#{Regexp.escape(filter.phrase)}/i
end
end
return false if active_filters.empty?