diff options
author | ThibG <thib@sitedethib.com> | 2018-07-09 02:22:09 +0200 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2018-07-09 02:22:09 +0200 |
commit | 1ca4e51eb38de6de81cedf3ddcdaa626f1d1c569 (patch) | |
tree | 3cf44ef95b178d233fd34d2ec2aae2a7021c159d /app/lib | |
parent | 451e585b9720c61ef9a155a16484b25ded79d512 (diff) |
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
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/feed_manager.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index 55c72d0ea..c247ab21d 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -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? |