public function deleteLocation($locationId, $contentId)
    {
        // 1. Update (reindex) all Content in the subtree with additional Location(s) outside of it
        $ast = array(
            'filter' => array(
                'and' => array(
                    0 => array(
                        'nested' => array(
                            'path' => 'locations_doc',
                            'filter' => array(
                                'regexp' => array(
                                    'locations_doc.path_string_id' => ".*/{$locationId}/.*",
                                ),
                            ),
                        ),
                    ),
                    1 => array(
                        'nested' => array(
                            'path' => 'locations_doc',
                            'filter' => array(
                                'regexp' => array(
                                    'locations_doc.path_string_id' => array(
                                        // Matches anything (@) and (&) not (~) <expression>
                                        'value' => "@&~(.*/{$locationId}/.*)",
                                        'flags' => 'INTERSECTION|COMPLEMENT|ANYSTRING',
                                    ),
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        );

        $response = $this->gateway->findRaw(json_encode($ast), $this->contentDocumentTypeIdentifier);
        $result = json_decode($response->body);

        $documents = array();
        foreach ($result->hits->hits as $hit) {
            $documents[] = $this->mapper->mapContentById($hit->_id);
        }

        $this->gateway->bulkIndex($documents);

        // 2. Delete all Content in the subtree with no other Location(s) outside of it
        $ast['filter']['and'][1] = array(
            'not' => $ast['filter']['and'][1],
        );
        $ast = array(
            'query' => array(
                'filtered' => $ast,
            ),
        );

        $response = $this->gateway->findRaw(json_encode($ast), $this->contentDocumentTypeIdentifier);
        $documentsToDelete = json_decode($response->body);

        foreach ($documentsToDelete->hits->hits as $documentToDelete) {
            $this->gateway->deleteByQuery(json_encode(['query' => ['match' => ['_id' => $documentToDelete->_id]]]), $this->contentDocumentTypeIdentifier);
            $this->gateway->deleteByQuery(json_encode(['query' => ['match' => ['content_id_id' => $documentToDelete->_id]]]), $this->locationDocumentTypeIdentifier);
        }
    }
public function deleteLocation($locationId, $contentId)
    {
        // 1. Update (reindex) all Content in the subtree with additional Location(s) outside of it
        $ast = array(
            'filter' => array(
                'and' => array(
                    0 => array(
                        'nested' => array(
                            'path' => 'locations_doc',
                            'filter' => array(
                                'regexp' => array(
                                    'locations_doc.path_string_id' => ".*/{$locationId}/.*",
                                ),
                            ),
                        ),
                    ),
                    1 => array(
                        'nested' => array(
                            'path' => 'locations_doc',
                            'filter' => array(
                                'regexp' => array(
                                    'locations_doc.path_string_id' => array(
                                        // Matches anything (@) and (&) not (~) <expression>
                                        'value' => "@&~(.*/{$locationId}/.*)",
                                        'flags' => 'INTERSECTION|COMPLEMENT|ANYSTRING',
                                    ),
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        );

        $response = $this->gateway->findRaw(json_encode($ast), $this->contentDocumentTypeIdentifier);
        $result = json_decode($response->body);

        $documents = array();
        foreach ($result->hits->hits as $hit) {
            $documents[] = $this->mapper->mapContentById($hit->_id);
        }

        $this->gateway->bulkIndex($documents);

        // 2. Delete all Content in the subtree with no other Location(s) outside of it
        $ast['filter']['and'][1] = array(
            'not' => $ast['filter']['and'][1],
        );
        $ast = array(
            'query' => array(
                'filtered' => $ast,
            ),
        );

        $response = $this->gateway->findRaw(json_encode($ast), $this->contentDocumentTypeIdentifier);
        $documentsToDelete = json_decode($response->body);

        foreach ($documentsToDelete->hits->hits as $documentToDelete) {
            $this->gateway->deleteByQuery(json_encode(['query' => ['match' => ['_id' => $documentToDelete->_id]]]), $this->contentDocumentTypeIdentifier);
            $this->gateway->deleteByQuery(json_encode(['query' => ['match' => ['content_id_id' => $documentToDelete->_id]]]), $this->locationDocumentTypeIdentifier);
        }
    }
public function deleteLocation ( $ locationId , $ contentId ) { // 1. Update (reindex) all Content in the subtree with additional Location(s) outside of it $ ast = array ( 'filter' => array ( 'and' => array ( 0 => array ( 'nested' => array ( 'path' => 'locations_doc' , 'filter' => array ( 'regexp' => array ( 'locations_doc.path_string_id' => ".*/{$locationId}/.*" , ) , ) , ) , ) , 1 => array ( 'nested' => array ( 'path' => 'locations_doc' , 'filter' => array ( 'regexp' => array ( 'locations_doc.path_string_id' => array ( // Matches anything (@) and (&) not (~) <expression> 'value' => "@&~(.*/{$locationId}/.*)" , 'flags' => 'INTERSECTION|COMPLEMENT|ANYSTRING' , ) , ) , ) , ) , ) , ) , ) , ) ; $ response = $ this -> gateway -> findRaw ( json_encode ( $ ast ) , $ this -> contentDocumentTypeIdentifier ) ; $ result = json_decode ( $ response -> body ) ; $ documents = array ( ) ; foreach ( $ result -> hits -> hits as $ hit ) { $ documents [ ] = $ this -> mapper -> mapContentById ( $ hit -> _id ) ; } $ this -> gateway -> bulkIndex ( $ documents ) ; // 2. Delete all Content in the subtree with no other Location(s) outside of it $ ast [ 'filter' ] [ 'and' ] [ 1 ] = array ( 'not' => $ ast [ 'filter' ] [ 'and' ] [ 1 ] , ) ; $ ast = array ( 'query' => array ( 'filtered' => $ ast , ) , ) ; $ response = $ this -> gateway -> findRaw ( json_encode ( $ ast ) , $ this -> contentDocumentTypeIdentifier ) ; $ documentsToDelete = json_decode ( $ response -> body ) ; foreach ( $ documentsToDelete -> hits -> hits as $ documentToDelete ) { $ this -> gateway -> deleteByQuery ( json_encode ( [ 'query' => [ 'match' => [ '_id' => $ documentToDelete -> _id ] ] ] ) , $ this -> contentDocumentTypeIdentifier ) ; $ this -> gateway -> deleteByQuery ( json_encode ( [ 'query' => [ 'match' => [ 'content_id_id' => $ documentToDelete -> _id ] ] ] ) , $ this -> locationDocumentTypeIdentifier ) ; } }
Deletes a location from the index.

@todo When we support Location-less Content, we will have to reindex instead of removing
@todo Should we not already support the above?
@todo The subtree could potentially be huge, so this implementation should scroll reindex

@param mixed $locationId
@param mixed $contentId @todo Make use of this, or remove if not needed.
Deletes a location from the index .