lib/sparkql/expression_state.rb in sparkql-0.1.8 vs lib/sparkql/expression_state.rb in sparkql-0.3.2
- old
+ new
@@ -1,20 +1,23 @@
# Custom fields need to add a table join to the customfieldsearch table when AND'd together,
-# but not when they are OR'd. This class maintains the state for all custom field expressions
+# but not when they are OR'd or nested. This class maintains the state for all custom field expressions
# lets the parser know when to do either.
class Sparkql::ExpressionState
def initialize
- @expressions = []
+ @expressions = {0=>[]}
@last_conjunction = "And" # always start with a join
+ @block_group = 0
end
def push(expression)
- @expressions << expression
+ @block_group = expression[:block_group]
+ @expressions[@block_group] ||= []
+ @expressions[@block_group] << expression
@last_conjunction = expression[:conjunction]
end
def needs_join?
- return @expressions.size == 1 || "And" == @last_conjunction
+ return @expressions[@block_group].size == 1 || ["Not", "And"].include?(@last_conjunction)
end
end
\ No newline at end of file