Skip to content
Snippets Groups Projects
Commit 59c3315d authored by Ere Maijala's avatar Ere Maijala
Browse files

Fixed fetching similar records when deduplication is enabled and made it...

Fixed fetching similar records when deduplication is enabled and made it possible to also disable deduplication in a deduplicated Solr index so that dedup records are filtered out.
parent 0790360c
Branches
Tags
No related merge requests found
...@@ -573,7 +573,9 @@ container_title = "Journal Title" ...@@ -573,7 +573,9 @@ container_title = "Journal Title"
; This section defines how records are handled when being fetched from Solr. ; This section defines how records are handled when being fetched from Solr.
[Records] [Records]
; Boolean value indicating if deduplication is enabled. Defaults to false. ; Boolean value indicating if deduplication is enabled. If true, deduplication is
; enabled. If false, dedup records are filtered out. If unspecified, deduplication
; support is completely disabled.
;deduplication = true ;deduplication = true
; Priority order (descending) for record sources (record ID prefixes separated ; Priority order (descending) for record sources (record ID prefixes separated
; from the actual record by period, e.g. testsrc.12345) ; from the actual record by period, e.g. testsrc.12345)
......
...@@ -213,10 +213,10 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface ...@@ -213,10 +213,10 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface
} }
// Apply deduplication if applicable: // Apply deduplication if applicable:
if (isset($search->Records->deduplication) if (isset($search->Records->deduplication)) {
&& $search->Records->deduplication $this->getDeduplicationListener(
) { $backend, $search->Records->deduplication
$this->getDeduplicationListener($backend)->attach($events); )->attach($events);
} }
// Attach hierarchical facet listener: // Attach hierarchical facet listener:
...@@ -370,15 +370,18 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface ...@@ -370,15 +370,18 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface
* Get a deduplication listener for the backend * Get a deduplication listener for the backend
* *
* @param BackendInterface $backend Search backend * @param BackendInterface $backend Search backend
* @param bool $enabled Whether deduplication is enabled
* *
* @return DeduplicationListener * @return DeduplicationListener
*/ */
protected function getDeduplicationListener(BackendInterface $backend) protected function getDeduplicationListener(BackendInterface $backend, $enabled)
{ {
return new DeduplicationListener( return new DeduplicationListener(
$backend, $backend,
$this->serviceLocator, $this->serviceLocator,
$this->searchConfig $this->searchConfig,
'datasources',
$enabled
); );
} }
......
...@@ -76,6 +76,13 @@ class DeduplicationListener ...@@ -76,6 +76,13 @@ class DeduplicationListener
*/ */
protected $dataSourceConfig; protected $dataSourceConfig;
/**
* Whether deduplication is enabled.
*
* @var bool
*/
protected $enabled;
/** /**
* Constructor. * Constructor.
* *
...@@ -83,18 +90,21 @@ class DeduplicationListener ...@@ -83,18 +90,21 @@ class DeduplicationListener
* @param ServiceLocatorInterface $serviceLocator Service locator * @param ServiceLocatorInterface $serviceLocator Service locator
* @param string $searchConfig Search config file id * @param string $searchConfig Search config file id
* @param string $dataSourceConfig Data source file id * @param string $dataSourceConfig Data source file id
* @param bool $enabled Whether deduplication is
* enabled
* *
* @return void * @return void
*/ */
public function __construct( public function __construct(
BackendInterface $backend, BackendInterface $backend,
ServiceLocatorInterface $serviceLocator, ServiceLocatorInterface $serviceLocator,
$searchConfig, $dataSourceConfig = 'datasources' $searchConfig, $dataSourceConfig = 'datasources', $enabled = true
) { ) {
$this->backend = $backend; $this->backend = $backend;
$this->serviceLocator = $serviceLocator; $this->serviceLocator = $serviceLocator;
$this->searchConfig = $searchConfig; $this->searchConfig = $searchConfig;
$this->dataSourceConfig = $dataSourceConfig; $this->dataSourceConfig = $dataSourceConfig;
$this->enabled = $enabled;
} }
/** /**
...@@ -125,7 +135,18 @@ class DeduplicationListener ...@@ -125,7 +135,18 @@ class DeduplicationListener
$params = $event->getParam('params'); $params = $event->getParam('params');
$context = $event->getParam('context'); $context = $event->getParam('context');
if (($context == 'search' || $context == 'similar') && $params) { if (($context == 'search' || $context == 'similar') && $params) {
$params->add('fq', '-merged_child_boolean:TRUE'); // If deduplication is enabled, filter out merged child records,
// otherwise filter out dedup records.
if ($this->enabled) {
$fq = '-merged_child_boolean:true';
if ($context == 'similar' && $id = $event->getParam('id')) {
$fq .= ' AND -local_ids_str_mv:"'
. addcslashes($id, '"') . '"';
}
} else {
$fq = '-merged_boolean:true';
}
$params->add('fq', $fq);
} }
} }
return $event; return $event;
...@@ -147,7 +168,7 @@ class DeduplicationListener ...@@ -147,7 +168,7 @@ class DeduplicationListener
return $event; return $event;
} }
$context = $event->getParam('context'); $context = $event->getParam('context');
if ($context == 'search') { if ($this->enabled && ($context == 'search' || $context == 'similar')) {
$this->fetchLocalRecords($event); $this->fetchLocalRecords($event);
} }
return $event; return $event;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment