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.



335
336
337
# File 'lib/parsing_nesting/tree.rb', line 335

def initialize(exp)
  self.operand = exp
end

Instance Attribute Details

#operandObject

Returns the value of attribute operand.



338
339
340
# File 'lib/parsing_nesting/tree.rb', line 338

def operand
  @operand
end

Instance Method Details

#can_embed?Boolean

Returns:

  • (Boolean)


354
355
356
# File 'lib/parsing_nesting/tree.rb', line 354

def can_embed?
  false
end

#negateObject



358
359
360
# File 'lib/parsing_nesting/tree.rb', line 358

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.



344
345
346
347
348
349
350
351
352
# File 'lib/parsing_nesting/tree.rb', line 344

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.kind_of?(NotExpression)
    operand.operand.to_query(solr_params)
  else
    "NOT " + operand.to_query(solr_params)
  end
end