/** * @param Query $query * @param callable $transform * @param null $readEndpoint * @param null $writeEndpoint * @param bool $commit */ public function updateBufferedPlugin(Query $query, callable $transform = null, $readEndpoint = null, $writeEndpoint = null, $commit = true) { /** * @var PrefetchIterator $prefetch * @var BufferedAdd $update * @var SelectDocument $document */ $prefetch = $this->getSolarium()->getPlugin('prefetchiterator'); $prefetch->setPrefetch($this->getBuffer()); $prefetch->setQuery($query); $prefetch->setEndpoint($readEndpoint); $update = $this->solarium->getPlugin('bufferedadd'); $update->setBufferSize($this->getBuffer()); $update->setEndpoint($writeEndpoint); foreach ($prefetch as $document) { if (is_callable($transform)) { $document = $transform($document); } else { $document = new UpdateDocument($document->getFields()); } $update->addDocument($document); } $update->flush(); if ($commit === true) { $update->commit(); } }
protected function assertHasDocumentFields(Document $document, $expectedFields) { $actualFields = $document->getFields(); foreach ($expectedFields as $expectedField) { $this->assertTrue(array_key_exists($expectedField, $actualFields), 'field' . $expectedField . ' not in document'); } }
public function testSetAndGetFieldsUsingModifiersWithoutKey() { $this->doc->clear(); $this->doc->setField('id', 1); $this->doc->setField('name', 'newname', null, Document::MODIFIER_SET); $this->setExpectedException('Solarium\\Exception\\RuntimeException'); $this->doc->getFields(); }
/** * @param Document $document * @return array */ public static function createArrayFromDocument($document) { $array = []; $solr_fields = ["_version_"]; $solr_system_marks = ["_s"]; $fields = $document->getFields(); foreach ($fields as $field => $value) { if ($field == "id") { $value = str_replace($fields["document_s"], "", $value); } if (in_array($field, $solr_fields)) { continue; } foreach ($solr_system_marks as $solr_system_mark) { if (substr($field, -strlen($solr_system_mark)) == $solr_system_mark) { $field = substr($field, 0, -strlen($solr_system_mark)); break; } } $array[$field] = $value; } return $array; }