Method: Wordmap#query

Defined in:
lib/wordmap.rb

#query(*query, trace: nil) ⇒ Object

Query consists of one or more clauses. Each clause is an array.

Clauses can have 2 shapes:

1. ['key1', 'key2', ...] # match any of these main keys
2. [:index_name, 'key1', 'key2', ...] # match by any of these index keys
  • OR logic is used inside a clause (matches are unioned)

  • AND logic is used between clauses (matches are intersected)

Example 1:

query(['horse1', 'horse2', 'horse3'], [:trait, 'fluffy'])

Out of horse1, horse2, horse3 return only the fluffy ones.

Example 2:

query([:color, 'orange', 'green'], [:type, 'vegetable', 'fruit'])

Return all orange and green fruits and vegetables.



77
78
79
80
81
# File 'lib/wordmap.rb', line 77

def query(*query, trace: nil)
  enum =
    Access.each_by_query(@descriptors, @indexes, query, LTRIM_REGEX, trace)
  block_given? ? enum.each { |v| yield(v) } : enum
end