Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 6a79d6d

Browse files
committed
Remove zero score in filter
1 parent c1c57d3 commit 6a79d6d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/sentiment/emotion_filter_order.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,29 @@ def self.register!(plugin)
99
scope_period =
1010
scope
1111
.arel
12-
.constraints
13-
.flat_map(&:children)
14-
.find do |node|
12+
&.constraints
13+
&.flat_map(&:children)
14+
&.find do |node|
1515
node.is_a?(Arel::Nodes::Grouping) &&
1616
node.expr.to_s.match?(/topics\.bumped_at\s*>=/)
1717
end
1818
&.expr
1919
&.split(">=")
20-
&.last
20+
&.last if scope.arel.constraints.present? &&
21+
scope.arel.constraints.any? { |c| c.is_a?(Arel::Nodes::Grouping) }
2122

2223
# Fallback in case we can't find the scope period
2324
scope_period ||= "CURRENT_DATE - INTERVAL '1 year'"
2425

2526
emotion_clause = <<~SQL
26-
COUNT(*) FILTER (WHERE (classification_results.classification::jsonb->'#{emotion}')::float > 0.1) AS emotion_#{emotion}
27+
COUNT(*) FILTER (WHERE (classification_results.classification::jsonb->'#{emotion}')::float > 0.1)
2728
SQL
2829

2930
# TODO: This is slow, we will need to materialize this in the future
3031
with_clause = <<~SQL
3132
SELECT
3233
topics.id,
33-
#{emotion_clause}
34+
#{emotion_clause} AS emotion_#{emotion}
3435
FROM
3536
topics
3637
INNER JOIN
@@ -48,6 +49,8 @@ def self.register!(plugin)
4849
AND posts.created_at >= #{scope_period}
4950
GROUP BY
5051
1
52+
HAVING
53+
#{emotion_clause} > 0
5154
SQL
5255

5356
scope

0 commit comments

Comments
 (0)