123456789_123456789_123456789_123456789_123456789_

Class: Redis::Commands::Search::PredicateCollection

Relationships & Source Files
Inherits: Object
Defined in: lib/redis/commands/modules/search/query.rb

Overview

An ordered collection of predicates joined with AND (a space) or OR (+ | +).

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(type) ⇒ PredicateCollection

Parameters:

  • type (Symbol) —

    :and to join with a space, :or to join with |

[ GitHub ]

  
# File 'lib/redis/commands/modules/search/query.rb', line 717

def initialize(type)
  @type = type
  @predicates = []
end

Instance Attribute Details

#predicates ⇒ Symbol, Array<Predicate, PredicateCollection> (readonly)

Returns:

  • (Symbol) —

    :and or :or

  • (Array<Predicate, PredicateCollection>) —

    the contained predicates

[ GitHub ]

  
# File 'lib/redis/commands/modules/search/query.rb', line 714

attr_reader :type, :predicates

#type ⇒ Symbol, Array<Predicate, PredicateCollection> (readonly)

Returns:

  • (Symbol) —

    :and or :or

  • (Array<Predicate, PredicateCollection>) —

    the contained predicates

[ GitHub ]

  
# File 'lib/redis/commands/modules/search/query.rb', line 714

attr_reader :type, :predicates

Instance Method Details

#add(predicate) ⇒ Array

Add a predicate (or nested collection) to this collection.

Parameters:

  • predicate (Predicate, PredicateCollection) —

    the predicate to add

Returns:

  • (Array) —

    the updated list of predicates

[ GitHub ]

  
# File 'lib/redis/commands/modules/search/query.rb', line 726

def add(predicate)
  @predicates << predicate
end

#to_s ⇒ String

Returns:

  • (String) —

    the parenthesised, joined query-string fragment

[ GitHub ]

  
# File 'lib/redis/commands/modules/search/query.rb', line 731

def to_s
  joiner = @type == :or ? ' | ' : ' '
  "(#{@predicates.join(joiner)})"
end