class AndList
Public Instance Methods
can_embed?()
click to toggle source
We make an and-list embeddable only if all it's elements are embeddable, then no problem we just embed them all as Solr '+' mandatory, and achieve the AND. For now, pure negative is considered not embeddable, although theoretically it could sometimes be embedded if transformed properly.
# File lib/parsing_nesting/tree.rb, line 210 def can_embed? !simple_pure_negative? && !list.collect { |i| i.can_embed? }.include?(false) end
negate()
click to toggle source
convent logical property here, not(a AND b) === not(a) OR not(b)
# File lib/parsing_nesting/tree.rb, line 249 def negate OrList.new(list.collect { |n| n.negate }) end
to_embed()
click to toggle source
Only if all operands are embeddable. Trick is if they were bare terms/phrases, we add a '+' on front, but if they already were +/-, then we don't need to, and leaving them along will have desired semantics. This works even on “-”, because dismax mm seems to not consider “-” clauses, they are always required regardless of mm.
# File lib/parsing_nesting/tree.rb, line 220 def to_embed list.collect do |operand| s = operand.to_embed if s =~ /^\+/ || s =~ /^\-/ s else '+' + s end end.join(" ") end
to_query(local_params)
click to toggle source
for those that aren't embeddable, or pure negative
# File lib/parsing_nesting/tree.rb, line 232 def to_query(local_params) if simple_pure_negative? # Can do it in one single nested dismax, if we're simple arguments # that are pure negative. # build_nested_query will handle negating the pure negative for # us. build_nested_query(list, local_params) else "( " + list.collect do |i| i.to_query(local_params) end.join(" AND ") + " )" end end