Class: ParsingNesting::Tree::NotExpression

Inherits:
Object
  • Object
show all
Defined in:
lib/parsing_nesting/tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exp) ⇒ NotExpression

Returns a new instance of NotExpression.



326
327
328
# File 'lib/parsing_nesting/tree.rb', line 326

def initialize(exp)
  self.operand = exp
end

Instance Attribute Details

#operandObject

Returns the value of attribute operand.



329
330
331
# File 'lib/parsing_nesting/tree.rb', line 329

def operand
  @operand
end

Instance Method Details

#can_embed?Boolean

Returns:

  • (Boolean)


345
346
347
# File 'lib/parsing_nesting/tree.rb', line 345

def can_embed?
  false
end

#negateObject



349
350
351
# File 'lib/parsing_nesting/tree.rb', line 349

def negate
  operand
end

#to_query(solr_params) ⇒ Object

We have to do the weird thing with : AND NOT (real thing), because Solr 1.4.1 seems not to be able to handle “x OR NOT y” otherwise, at least in some cases, but does fine with “x OR (: AND NOT y)”, which should mean the same thing.



335
336
337
338
339
340
341
342
343
# File 'lib/parsing_nesting/tree.rb', line 335

def to_query(solr_params)
  # rescue double-nots to not treat them crazy-like and make the query
  # more work for Solr than it needs to be with a double-negative.
  if operand.is_a?(NotExpression)
    operand.operand.to_query(solr_params)
  else
    "NOT " + operand.to_query(solr_params)
  end
end