- Solr Library Update: small changes in SolrIndexBuilder.php, SolariumAdapter.php and SolariumDocument.php
This commit is contained in:
parent
bcbd05d7d8
commit
b335bd7e9c
|
@ -5,6 +5,11 @@ namespace App\Console\Commands;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use App\Models\Dataset;
|
use App\Models\Dataset;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use App\Library\Search\SolariumAdapter;
|
||||||
|
use \Exception;
|
||||||
|
|
||||||
|
|
||||||
class SolrIndexBuilder extends Command
|
class SolrIndexBuilder extends Command
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -43,17 +48,21 @@ class SolrIndexBuilder extends Command
|
||||||
// update statistics table
|
// update statistics table
|
||||||
foreach ($datasets as $dataset) {
|
foreach ($datasets as $dataset) {
|
||||||
$datasetId = $dataset->id;
|
$datasetId = $dataset->id;
|
||||||
$time = new \Illuminate\Support\Carbon();
|
// $time = new \Illuminate\Support\Carbon();
|
||||||
$dataset->server_date_modified = $time;
|
// $dataset->server_date_modified = $time;
|
||||||
$dataset->save();
|
// $dataset->save();
|
||||||
// try {
|
// Log::debug(__METHOD__ . ': ' . 'Adding index job for dataset ' . $datasetId . '.');
|
||||||
// // Opus_Search_Service::selectIndexingService('onDocumentChange')
|
|
||||||
// $service = new SolariumAdapter("solr", config('solarium'));
|
try {
|
||||||
// $service->addDatasetsToIndex($dataset);
|
// Opus_Search_Service::selectIndexingService('onDocumentChange')
|
||||||
// } catch (Exception $e) {
|
$service = new SolariumAdapter("solr", config('solarium'));
|
||||||
// Log::debug(__METHOD__ . ': ' . 'Indexing document ' . $datasetId . ' failed: ' . $e->getMessage());
|
$service->addDatasetsToIndex($dataset);
|
||||||
// }
|
} catch (Exception $e) {
|
||||||
|
$this->error(__METHOD__ . ': ' . 'Indexing document ' . $dataset->id . ' failed: ' . $e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,6 @@ class EncryptCookies extends BaseEncrypter
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $except = [
|
protected $except = [
|
||||||
//
|
'XDEBUG_SESSION'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,12 @@ namespace App\Library\Search;
|
||||||
|
|
||||||
//use App\Library\Util\SolrSearchQuery;
|
//use App\Library\Util\SolrSearchQuery;
|
||||||
use App\Library\Search\SearchResult;
|
use App\Library\Search\SearchResult;
|
||||||
use App\Library\Util\SearchParameter;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use App\Library\Search\SolariumDocument;
|
use App\Library\Search\SolariumDocument;
|
||||||
|
use App\Library\Util\SearchParameter;
|
||||||
use App\Models\Dataset;
|
use App\Models\Dataset;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Solarium\Core\Client\Adapter\Curl;
|
||||||
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||||
use \Solarium\QueryType\Select\Query\Query;
|
use \Solarium\QueryType\Select\Query\Query;
|
||||||
|
|
||||||
class SolariumAdapter
|
class SolariumAdapter
|
||||||
|
@ -22,7 +24,11 @@ class SolariumAdapter
|
||||||
public function __construct($serviceName, $options)
|
public function __construct($serviceName, $options)
|
||||||
{
|
{
|
||||||
$this->options = $options;
|
$this->options = $options;
|
||||||
$this->client = new \Solarium\Client($options);
|
$adapter = new Curl();
|
||||||
|
$dispatcher = new EventDispatcher();
|
||||||
|
|
||||||
|
$this->client = new \Solarium\Client($adapter, $dispatcher, $options);
|
||||||
|
// $this->client = new \Solarium\Client($options);
|
||||||
|
|
||||||
// ensure service is basically available
|
// ensure service is basically available
|
||||||
$ping = $this->client->createPing();
|
$ping = $this->client->createPing();
|
||||||
|
@ -61,25 +67,30 @@ class SolariumAdapter
|
||||||
$slices = array_chunk($datasets, 16);
|
$slices = array_chunk($datasets, 16);
|
||||||
// update documents of every chunk in a separate request
|
// update documents of every chunk in a separate request
|
||||||
foreach ($slices as $slice) {
|
foreach ($slices as $slice) {
|
||||||
|
// get an update query instance
|
||||||
$update = $this->client->createUpdate();
|
$update = $this->client->createUpdate();
|
||||||
|
|
||||||
$updateDocs = array_map(function ($rdrDoc) use ($builder, $update) {
|
$updateDocs = array_map(function ($rdrDoc) use ($builder, $update) {
|
||||||
$solarium_document = $update->createDocument();
|
$solarium_document = $update->createDocument();
|
||||||
return $builder->toSolrUpdateDocument($rdrDoc, $solarium_document);
|
return $builder->toSolrUpdateDocument($rdrDoc, $solarium_document);
|
||||||
}, $slice);
|
}, $slice);
|
||||||
|
|
||||||
// adding the document to the update query
|
// add the documents and a commit command to the update query
|
||||||
$update->addDocuments($updateDocs);
|
$update->addDocuments($updateDocs);
|
||||||
// Then commit the update:
|
$update->addCommit();
|
||||||
$update->addCommit();
|
|
||||||
$result = $this->client->update($update);
|
// this executes the query and returns the result
|
||||||
|
$result = $this->client->update($update);
|
||||||
|
echo '<b>Update query executed</b><br/>';
|
||||||
|
echo 'Query status: ' . $result->getStatus() . '<br/>';
|
||||||
|
echo 'Query time: ' . $result->getQueryTime();
|
||||||
|
|
||||||
//$this->execute($update, 'failed updating slice of documents');
|
//$this->execute($update, 'failed updating slice of documents');
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally commit all updates
|
// finally commit all updates
|
||||||
// $update = $this->client->createUpdate();
|
// $update = $this->client->createUpdate();
|
||||||
|
|
||||||
// $update->addCommit();
|
// $update->addCommit();
|
||||||
|
|
||||||
// $this->execute($update, 'failed committing update of documents');
|
// $this->execute($update, 'failed committing update of documents');
|
||||||
|
@ -196,7 +207,7 @@ class SolariumAdapter
|
||||||
$result = null;
|
$result = null;
|
||||||
try {
|
try {
|
||||||
$result = $this->client->execute($query);
|
$result = $this->client->execute($query);
|
||||||
} catch (\Solarium\Exception\HttpException $e) {
|
} catch (\Solarium\Exception\HttpException$e) {
|
||||||
sprintf('%s: %d %s', $actionText, $e->getCode(), $e->getStatusMessage());
|
sprintf('%s: %d %s', $actionText, $e->getCode(), $e->getStatusMessage());
|
||||||
} finally {
|
} finally {
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -207,7 +218,7 @@ class SolariumAdapter
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function processQuery(\Solarium\QueryType\Select\Query\Query $query): SearchResult
|
protected function processQuery(\Solarium\QueryType\Select\Query\Query$query): SearchResult
|
||||||
{
|
{
|
||||||
// send search query to service
|
// send search query to service
|
||||||
$request = $this->execute($query, 'failed querying search engine');
|
$request = $this->execute($query, 'failed querying search engine');
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace App\Library\Search;
|
namespace App\Library\Search;
|
||||||
|
|
||||||
use App\Models\Dataset;
|
use App\Models\Dataset;
|
||||||
use Solarium\QueryType\Update\Query\Document\Document;
|
use Solarium\QueryType\Update\Query\Document;
|
||||||
use Solarium\QueryType\Update\Query\Document\DocumentInterface;
|
use Solarium\QueryType\Update\Query\Document\DocumentInterface;
|
||||||
|
|
||||||
class SolariumDocument extends SolrDocumentXslt
|
class SolariumDocument extends SolrDocumentXslt
|
||||||
|
@ -13,10 +13,10 @@ class SolariumDocument extends SolrDocumentXslt
|
||||||
parent::__construct($options);
|
parent::__construct($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toSolrUpdateDocument(Dataset $rdrDataset, DocumentInterface $solrDoc)
|
public function toSolrUpdateDocument(Dataset $rdrDataset, $solrDoc)
|
||||||
{
|
{
|
||||||
if (!($solrDoc instanceof Document)) {
|
if (!($solrDoc instanceof Document)) {
|
||||||
throw new \Exception('provided Solr document must be instance of Solarium Update Document');
|
throw new \Exception(get_class($solrDoc) . 'provided Solr document must be instance of Solarium Update Document');
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert Opus document to Solr XML document for supporting custom transformations
|
// convert Opus document to Solr XML document for supporting custom transformations
|
||||||
|
|
Loading…
Reference in New Issue
Block a user