Class: ElasticGraph::SchemaDefinition::Indexing::DerivedFields::MinOrMaxValue Private

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/schema_definition/indexing/derived_fields/min_or_max_value.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Responsible for providing bits of the painless script specific to a ElasticGraph::SchemaDefinition::Indexing::DerivedIndexedType#min_value or ElasticGraph::SchemaDefinition::Indexing::DerivedIndexedType#max_value field.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.function_def(min_or_max) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns painless function for managing a min or max field.

Parameters:

  • min_or_max (:min, :max)

    which type of function to generate.

Returns:

  • (String)

    painless function for managing a min or max field.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/elastic_graph/schema_definition/indexing/derived_fields/min_or_max_value.rb', line 41

def self.function_def(min_or_max)
  operator = (min_or_max == :min) ? "<" : ">"

  <<~EOS
    boolean #{min_or_max}Value_idempotentlyUpdateValue(List values, def parentObject, String fieldName) {
      def currentFieldValue = parentObject[fieldName];
      def #{min_or_max}NewValue = values.isEmpty() ? null : Collections.#{min_or_max}(values);

      if (currentFieldValue == null || (#{min_or_max}NewValue != null && #{min_or_max}NewValue.compareTo(currentFieldValue) #{operator} 0)) {
        parentObject[fieldName] = #{min_or_max}NewValue;
        return true;
      }

      return false;
    }
  EOS
end

Instance Method Details

#apply_operation_returning_update_statusString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a line of painless code to manage a min or max value field and return a boolean indicating if it was updated.

Returns:

  • (String)

    a line of painless code to manage a min or max value field and return a boolean indicating if it was updated.



22
23
24
25
26
27
# File 'lib/elastic_graph/schema_definition/indexing/derived_fields/min_or_max_value.rb', line 22

def apply_operation_returning_update_status
  *parent_parts, field = destination_field.split(".")
  parent_parts = ["ctx", "_source"] + parent_parts

  %{#{min_or_max}Value_idempotentlyUpdateValue(data["#{source_field}"], #{parent_parts.join(".")}, "#{field}")}
end

#function_definitionsArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns painless functions required by a min or max value field.

Returns:

  • (Array<String>)

    painless functions required by a min or max value field.



35
36
37
# File 'lib/elastic_graph/schema_definition/indexing/derived_fields/min_or_max_value.rb', line 35

def function_definitions
  [MinOrMaxValue.function_def(min_or_max)]
end

#setup_statementsArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a list of painless statements that must be called at the top of the script to set things up.

Returns:

  • (Array<String>)

    a list of painless statements that must be called at the top of the script to set things up.



30
31
32
# File 'lib/elastic_graph/schema_definition/indexing/derived_fields/min_or_max_value.rb', line 30

def setup_statements
  FieldInitializerSupport.build_empty_value_initializers(destination_field, leaf_value: :leave_unset)
end