/** * Update document in index for model * * @param Model $model */ public function update(Model $model) { // Remove any existing documents for model. $this->delete($model); // Create new document for model. $doc = new Document(); list($name, $value) = $this->config->privateKeyPair($model); // Add private key. $doc->addField(Field::keyword($name, $value)); // Add model's class UID. list($name, $value) = $this->config->classUidPair($model); // Add class uid for identification of model's class. $doc->addField(Field::Keyword($name, $value)); $fields = $this->config->fields($model); // Add fields to document to be indexed (but not stored). foreach ($fields as $field) { $doc->addField(Field::unStored(trim($field), strip_tags(trim($model->{trim($field)})))); } $optionalAttributes = $this->config->optionalAttributes($model); // Add optional attributes to document to be indexed (but not stored). foreach ($optionalAttributes as $fieldName => $fieldValue) { $doc->addField(Field::unStored(trim($fieldName), strip_tags(trim($fieldValue)))); } // Add document to index. $this->index()->addDocument($doc); }
public function testPrivateKeyForIncorrectModel() { $message = "Configuration doesn't exist for model of class '" . get_class($this->unknownRepoMock) . "'."; $this->setExpectedException('\\InvalidArgumentException', $message); $this->config->privateKeyPair($this->unknownRepoMock); }