Method: Google::Cloud::Datastore::Entity#exclude_from_indexes!

Defined in:
lib/google/cloud/datastore/entity.rb

#exclude_from_indexes!(name, flag = nil) {|value| ... } ⇒ Object

Sets whether a property should be excluded from the Datastore indexes. Setting ‘true` will exclude the property from the indexes. Setting `false` will include the property on any applicable indexes. The default value is `false`. This is another way of saying that values are indexed by default.

If the property is multi-valued, each value in the list can be managed separately for exclusion from indexing. When you call this method for a multi-valued property, you can pass either a single boolean argument to be applied to all of the values, or an array that contains the boolean argument for each corresponding value in the property. For example, if a multi-valued property contains ‘[“a”, “b”]`, and only the value `“b”` should be indexed (meaning that `“a”`’ should be excluded), you should pass the array: ‘[true, false]`.

Examples:

entity["priority"] = 4
entity.exclude_from_indexes! "priority", true

Multi-valued properties can be given multiple exclude flags:

entity["tags"] = ["fun", "programming"]
entity.exclude_from_indexes! "tags", [true, false]

Or, a single flag can be applied to all values in a property:

entity["tags"] = ["fun", "programming"]
entity.exclude_from_indexes! "tags", true

Flags can also be set with a block:

entity["priority"] = 4
entity.exclude_from_indexes! "priority" do |priority|
  priority > 4
end

Parameters:

  • name (String)

    the property name

  • flag (Boolean, Array<Boolean>, nil) (defaults to: nil)

    whether the value or values should be excluded from indexing

Yields:

  • (value)

    a block yielding each value of the property

Yield Parameters:

  • value (Object)

    a value of the property

Yield Returns:

  • (Boolean)

    ‘true` if the value should be excluded from indexing

See Also:



331
332
333
334
335
336
337
338
339
# File 'lib/google/cloud/datastore/entity.rb', line 331

def exclude_from_indexes! name, flag = nil, &block
  name = name.to_s
  flag = block if block_given?
  if flag.nil?
    @_exclude_indexes.delete name
  else
    @_exclude_indexes[name] = flag
  end
end