Class: ElasticGraph::GraphQL::Filtering::FilterValueSetExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/graphql/filtering/filter_value_set_extractor.rb

Overview

Responsible for extracting a set of values from query filters, based on a using a custom set type that is able to efficiently model the “all values” case.

Instance Method Summary collapse

Constructor Details

#initialize(schema_names, all_values_set, &build_set_for_filter) ⇒ FilterValueSetExtractor

Returns a new instance of FilterValueSetExtractor.



15
16
17
18
19
# File 'lib/elastic_graph/graphql/filtering/filter_value_set_extractor.rb', line 15

def initialize(schema_names, all_values_set, &build_set_for_filter)
  @schema_names = schema_names
  @all_values_set = all_values_set
  @build_set_for_filter = build_set_for_filter
end

Instance Method Details

#extract_filter_value_set(filter_hashes, target_field_paths) ⇒ Object

Given a list of ‘filter_hashes` and a list of `target_field_paths`, returns a representation of a set that includes all values that could be matched by the given filters.

Essentially, this method guarantees that the following pseudo code is always satisfied:

“‘ ruby filter_value_set = extract_filter_value_set(filter_hashes, target_field_paths) Datastore.all_documents_matching(filter_hashes).each do |document|

target_field_paths.each do |field_path|
  expect(filter_value_set).to include(document.value_at(field_path))
end

end “‘



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/elastic_graph/graphql/filtering/filter_value_set_extractor.rb', line 34

def extract_filter_value_set(filter_hashes, target_field_paths)
  # We union the filter values together in cases where we have multiple target field paths
  # to make sure we cover all the values we need to. We generally do not have multiple
  # `target_field_paths` except for specialized cases, such as when searching multiple
  # indices in one query, where those indices are configured to use differing `routing_field_paths`.
  # In such a situation we must use the set union of values. Remember: including additional
  # routing values causes no adverse behavior (although it may introduce an inefficiency)
  # but if we fail to route to a shard that contains a matching document, the search results
  # will be incorrect.
  map_reduce_sets(target_field_paths, :union, negate: false) do |target_field_path|
    filter_value_set_for_target_field_path(target_field_path, filter_hashes)
  end
end