Indexer.php
/**
     * Make a document ready to be indexed.
     *
     * @param \PhpAmqpLib\Message\AMQPMessage $message
     */
Make a document ready to be indexed.
Make a document ready to be indexed .
public function prepareDocument(AMQPMessage $message)
    {
        $data = json_decode($message->body, true);
        $core = '';
        if (array_key_exists('core', $data['metadata'])) {
            $core = $data['metadata']['core'];
        }
        $updateQuery = $this->client->createUpdate();
        $document = $updateQuery->createDocument();
        foreach ($this->mapping as $field => $solrField) {
            if ($field === 'groups') {
                foreach ($solrField as $groupFieldName => $solrGroupFields) {
                    foreach ($solrGroupFields as $fieldName => $solrGroupFieldName) {
                        $composedFieldName = $groupFieldName . '.' . $fieldName;
                        $composedSolrFieldName = $groupFieldName . '.' . $solrGroupFieldName;
                        if (array_key_exists($composedFieldName, $data['document'])) {
                            $document->addField($composedSolrFieldName, $data['document'][$composedFieldName]);
                        }
                    }
                }
                continue;
            }
            if (array_key_exists($field, $data['document'])) {
                $document->addField($solrField, $data['document'][$field]);
            }
        }
        $this->documents[$core][] = $document;
        if (count($this->documents, true) >= $this->minimalDocumentSaveAmount) {
            foreach (array_keys($this->documents) as $core) {
                $this->setCoreNameFromMetadata(['core' => $core]);
                $updateQuery = $this->client->createUpdate();
                $this->addDocuments($updateQuery, $this->documents[$core]);
            }
            $this->documents = [];
        }
    }
public function prepareDocument ( AMQPMessage $ message ) { $ data = json_decode ( $ message -> body , true ) ; $ core = '' ; if ( array_key_exists ( 'core' , $ data [ 'metadata' ] ) ) { $ core = $ data [ 'metadata' ] [ 'core' ] ; } $ updateQuery = $ this -> client -> createUpdate ( ) ; $ document = $ updateQuery -> createDocument ( ) ; foreach ( $ this -> mapping as $ field => $ solrField ) { if ( $ field === 'groups' ) { foreach ( $ solrField as $ groupFieldName => $ solrGroupFields ) { foreach ( $ solrGroupFields as $ fieldName => $ solrGroupFieldName ) { $ composedFieldName = $ groupFieldName . '.' . $ fieldName ; $ composedSolrFieldName = $ groupFieldName . '.' . $ solrGroupFieldName ; if ( array_key_exists ( $ composedFieldName , $ data [ 'document' ] ) ) { $ document -> addField ( $ composedSolrFieldName , $ data [ 'document' ] [ $ composedFieldName ] ) ; } } } continue ; } if ( array_key_exists ( $ field , $ data [ 'document' ] ) ) { $ document -> addField ( $ solrField , $ data [ 'document' ] [ $ field ] ) ; } } $ this -> documents [ $ core ] [ ] = $ document ; if ( count ( $ this -> documents , true ) >= $ this -> minimalDocumentSaveAmount ) { foreach ( array_keys ( $ this -> documents ) as $ core ) { $ this -> setCoreNameFromMetadata ( [ 'core' => $ core ] ) ; $ updateQuery = $ this -> client -> createUpdate ( ) ; $ this -> addDocuments ( $ updateQuery , $ this -> documents [ $ core ] ) ; } $ this -> documents = [ ] ; } }
Make a document ready to be indexed.
Make a document ready to be indexed .