public static function wrapPrivateFieldQuery(Field $field, array $query) { if ($field->isPrivate()) { return self::restrictQueryToCollections($query, $field->getDependantCollections()); } else { return $query; } }
public static function wrapPrivateFieldAggregation(Field $field, array $aggregation) { if ($field->isPrivate()) { $wrapper = []; $wrapper['filter']['terms']['base_id'] = $field->getDependantCollections(); $wrapper['aggs']['__wrapped_private_field__'] = $aggregation; return $wrapper; } else { return $aggregation; } }
private function limitField(Field $field, array $allowed_collections = null) { if ($allowed_collections === null) { $allowed_collections = $this->allowedCollections(); } $collections = array_values(array_intersect($field->getDependantCollections(), $allowed_collections)); return $field->withOptions(['used_by_collections' => $collections]); }
public function testCollectionsUsedByPrivateFields() { $structure = new Structure(); $structure->add($foo = new Field('foo', Mapping::TYPE_STRING, ['private' => true, 'used_by_collections' => [1, 2]])); $structure->add(new Field('foo', Mapping::TYPE_STRING, ['private' => true, 'used_by_collections' => [2, 3]])); $structure->add(new Field('bar', Mapping::TYPE_STRING, ['private' => true, 'used_by_collections' => [2, 3]])); $structure->add(new Field('baz', Mapping::TYPE_STRING, ['private' => false])); $this->assertEquals([1, 2], $foo->getDependantCollections()); static $expected = ['foo' => [1, 2, 3], 'bar' => [2, 3]]; $this->assertEquals($expected, $structure->getCollectionsUsedByPrivateFields()); }