Class: Sunspot::Query::Connective::Disjunction

Inherits:
Abstract show all
Defined in:
lib/sunspot/query/connective.rb

Overview

Disjunctions combine their components with an OR operator.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#add_component, #initialize, #negate, #negated?, #to_params

Methods inherited from Scope

#add_negated_restriction, #add_negated_shorthand_restriction, #add_restriction, #add_shorthand_restriction, #dynamic_query, #exclude_instance

Constructor Details

This class inherits a constructor from Sunspot::Query::Connective::Abstract

Class Method Details

.inverseObject



65
66
67
# File 'lib/sunspot/query/connective.rb', line 65

def inverse
  Conjunction
end

Instance Method Details

#add_conjunctionObject

Add a conjunction to the disjunction. This overrides the method in the Scope class since scopes are implicitly conjunctive and thus can return themselves as a conjunction. Inside a disjunction, however, a conjunction must explicitly be created.



84
85
86
87
# File 'lib/sunspot/query/connective.rb', line 84

def add_conjunction
  @components << conjunction = Conjunction.new(setup)
  conjunction
end

#add_disjunctionObject



89
90
91
# File 'lib/sunspot/query/connective.rb', line 89

def add_disjunction
  self
end

#to_boolean_phraseObject



70
71
72
73
74
75
76
# File 'lib/sunspot/query/connective.rb', line 70

def to_boolean_phrase
  if @components.any? { |component| component.negated? }
    denormalize.to_boolean_phrase
  else
    super
  end
end