2019-02-14 14:09:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Library\Search;
|
|
|
|
|
|
|
|
use App\Models\Dataset;
|
2021-05-26 12:38:09 +00:00
|
|
|
use Solarium\QueryType\Update\Query\Document;
|
2019-03-29 17:29:20 +00:00
|
|
|
use Solarium\QueryType\Update\Query\Document\DocumentInterface;
|
2019-02-14 14:09:11 +00:00
|
|
|
|
|
|
|
class SolariumDocument extends SolrDocumentXslt
|
|
|
|
{
|
|
|
|
public function __construct($options)
|
|
|
|
{
|
|
|
|
parent::__construct($options);
|
|
|
|
}
|
|
|
|
|
2021-05-26 12:38:09 +00:00
|
|
|
public function toSolrUpdateDocument(Dataset $rdrDataset, $solrDoc)
|
2019-02-14 14:09:11 +00:00
|
|
|
{
|
|
|
|
if (!($solrDoc instanceof Document)) {
|
2021-05-26 12:38:09 +00:00
|
|
|
throw new \Exception(get_class($solrDoc) . 'provided Solr document must be instance of Solarium Update Document');
|
2019-02-14 14:09:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convert Opus document to Solr XML document for supporting custom transformations
|
|
|
|
$solrDomDoc = parent::toSolrDocument($rdrDataset, new \DomDocument());
|
|
|
|
|
|
|
|
// read back fields from generated Solr XML document
|
|
|
|
$solrXmlDoc = simplexml_import_dom($solrDomDoc)->doc[0];
|
|
|
|
|
|
|
|
$solrDoc->clear();
|
|
|
|
foreach ($solrXmlDoc->field as $field) {
|
|
|
|
$solrDoc->addField(strval($field['name']), strval($field));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $solrDoc;
|
|
|
|
}
|
|
|
|
}
|