Skip to content
12 changes: 6 additions & 6 deletions lib/job/arAccessionExportJob.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ class arAccessionExportJob extends arExportJob
*/
public static function findExportRecords($parameters)
{
// Create new ES query
// Create ES query
$query = new arElasticSearchPluginQuery(
arElasticSearchPluginUtil::SCROLL_SIZE
);

// If slugs contains '*', export all records; otherwise filter by specific slugs
if (in_array('*', $parameters['params']['slugs'])) {
$query->queryBool->addMust(new \Elastica\Query\MatchAll());
} else {
if ($parameters['params']['fromClipboard']) {
$query->queryBool->addMust(
new \Elastica\Query\Terms('slug', $parameters['params']['slugs'])
);
} else {
$query->addAggFilters(AccessionBrowseAction::$AGGS, $parameters['params']);
$query->addAdvancedSearchFilters([], $parameters['params'], 'accession');
}

return QubitSearch::getInstance()
->index
->getIndex('QubitAccession')
->createSearch($query->getQuery(false, false));
->createSearch($query->queryBool);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public function addAdvancedSearchFilters(
// Default to show only top level descriptions
if (
'isaar' != $archivalStandard
&& 'accession' != $archivalStandard
&& (
!isset($params['topLod'])
|| filter_var($params['topLod'], FILTER_VALIDATE_BOOLEAN)
Expand Down Expand Up @@ -430,6 +431,8 @@ protected function queryField($field, $query, $archivalStandard)
default:
if ('isaar' == $archivalStandard) {
$documentType = 'actor';
} elseif ('accession' == $archivalStandard) {
$documentType = 'accession';
} else {
$documentType = 'informationObject';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,20 @@ private static function setBoostValues($indexType, $fields)
'places.i18n.%s.name' => 3,
];

break;

case 'accession':
$boost = [
'identifier' => 10,
'donors.i18n.%s.authorizedFormOfName' => 10,
'i18n.%s.title' => 10,
'i18n.%s.scopeAndContent' => 10,
'i18n.%s.locationInformation' => 5,
'i18n.%s.processingNotes' => 5,
'i18n.%s.sourceOfAcquisition' => 5,
'i18n.%s.archivalHistory' => 5,
];

break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,133 +17,102 @@
* along with Access to Memory (AtoM). If not, see <http://www.gnu.org/licenses/>.
*/

class AccessionBrowseAction extends sfAction
class AccessionBrowseAction extends DefaultBrowseAction
{
public static $AGGS = [
'acquisitionType' => [
'type' => 'term',
'field' => 'acquisitionType.id',
'size' => 10,
],
'resourceType' => [
'type' => 'term',
'field' => 'resourceType.id',
'size' => 10,
],
'processingStatus' => [
'type' => 'term',
'field' => 'processingStatus.id',
'size' => 10,
],
'processingPriority' => [
'type' => 'term',
'field' => 'processingPriority.id',
'size' => 10,
],
'donor' => [
'type' => 'term',
'field' => 'donors.id',
'size' => 10,
],
'creator' => [
'type' => 'term',
'field' => 'creators.id',
'size' => 10,
],
];

public function execute($request)
{
$title = $this->context->i18n->__(ucfirst($this->context->getModuleName()));
$this->response->setTitle("{$title} - {$this->response->getTitle()}");

if (!isset($request->limit)) {
$request->limit = sfConfig::get('app_hits_per_page');
// If a global search has been requested, translate that into an advanced search
if (isset($request->subquery)) {
$request->sq0 = $request->subquery;
}

if (!isset($request->page)) {
$request->page = 1;
// Add first criterion to the search box if it's over any field
if (1 !== preg_match('/^[\s\t\r\n]*$/', $request->sq0) && !isset($request->sf0)) {
$request->subquery = $request->sq0;
}

// Avoid pagination over ES' max result window config (default: 10000)
$maxResultWindow = arElasticSearchPluginConfiguration::getMaxResultWindow();

if ((int) $request->limit * (int) $request->page > $maxResultWindow) {
// Show alert
$message = $this->context->i18n->__(
"We've redirected you to the first page of results. To avoid using vast amounts of memory, AtoM limits pagination to %1% records. To view the last records in the current result set, try changing the sort direction.",
['%1%' => $maxResultWindow]
);
$this->getUser()->setFlash('notice', $message);

// Redirect to first page
$params = $request->getParameterHolder()->getAll();
unset($params['page']);
$this->redirect($params);
}
// Create the query and filter it with the selected aggs
parent::execute($request);

$this->sortOptions = [
'lastUpdated' => $this->context->i18n->__('Date modified'),
'accessionNumber' => $this->context->i18n->__('Accession number'),
'title' => $this->context->i18n->__('Title'),
'acquisitionDate' => $this->context->i18n->__('Acquisition date'),
];

if (!isset($request->sort)) {
if (1 !== preg_match('/^[\s\t\r\n]*$/', $request->subquery)) {
$request->sort = 'relevance';
} elseif ($this->getUser()->isAuthenticated()) {
$request->sort = sfConfig::get('app_sort_browser_user');
} else {
$request->sort = sfConfig::get('app_sort_browser_anonymous');
}
}
// Add advanced search filters to process sq0 query
$this->search->addAdvancedSearchFilters([], $request->getParameterHolder()->getAll(), 'accession');

// Default sort direction
$sortDir = 'asc';
if ('lastUpdated' == $request->sort) {
$sortDir = 'desc';
}
$this->search->query->setQuery($this->search->queryBool);

// Set default sort direction in request if not present or not valid
if (!isset($request->sortDir) || !in_array($request->sortDir, ['asc', 'desc'])) {
$request->sortDir = $sortDir;
}
$this->setSort($request);

$culture = $this->context->user->getCulture();

$this->query = new \Elastica\Query();
$this->query->setSize($request->limit);
$this->query->setFrom(($request->page - 1) * $request->limit);

$this->queryBool = new \Elastica\Query\BoolQuery();

if (1 === preg_match('/^[\s\t\r\n]*$/', $request->subquery)) {
$this->queryBool->addMust(new \Elastica\Query\MatchAll());
} else {
$fields = [
'identifier' => 10,
'donors.i18n.%s.authorizedFormOfName' => 10,
'i18n.%s.title' => 10,
'i18n.%s.scopeAndContent' => 10,
'i18n.%s.locationInformation' => 5,
'i18n.%s.processingNotes' => 5,
'i18n.%s.sourceOfAcquisition' => 5,
'i18n.%s.archivalHistory' => 5,
'i18n.%s.appraisal' => 1,
'i18n.%s.physicalCharacteristics' => 1,
'i18n.%s.receivedExtentUnits' => 1,
'acquisitionType.i18n.%s.name' => 1,
'processingPriority.i18n.%s.name' => 1,
'processingStatus.i18n.%s.name' => 1,
'resourceType.i18n.%s.name' => 1,
'alternativeIdentifiers.i18n.%s.name' => 1,
'creators.i18n.%s.authorizedFormOfName' => 1,
'alternativeIdentifiers.i18n.%s.note' => 1,
'alternativeIdentifiers.type.i18n.%s.name' => 1,
'accessionEvents.i18n.%s.agent' => 1,
'accessionEvents.type.i18n.%s.name' => 1,
'accessionEvents.notes.i18n.%s.content' => 1,
'donors.contactInformations.contactPerson' => 1,
'accessionEvents.dateString' => 1,
Comment on lines -92 to -115
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see these weights being set anywhere and I don't think they'd be inherited from the browse action either. Doesn't removing them impact the search result order?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out, I didn't consider that.

I found that addAdvancedSearchFilters() makes a call to the setBoostValues() function, so I added boost values for the accession fields that were being boosted previously there. See here: e372ba4

The ordering should be the same now that the fields are boosted properly.

Screenshot 2026-02-18 133658

];

$this->queryBool->addMust(
arElasticSearchPluginUtil::generateQueryString(
$request->subquery, $fields
)
);

$this->sortOptions['relevance'] = $this->context->i18n->__('Relevance');
}
// Do the search
$resultSet = QubitSearch::getInstance()
->index
->getIndex('QubitAccession')
->search($this->search->query);

$this->pager = new QubitSearchPager($resultSet);
$this->pager->setPage($request->page ?: 1);
$this->pager->setMaxPerPage($request->limit);
$this->pager->init();

// Set query
$this->query->setQuery($this->queryBool);
$this->populateAggs($resultSet);
}

// Set order
/**
* Set sort order based on requested ordering.
*
* Modifies $this->search in-place.
*
* @param mixed $request
*/
protected function setSort($request)
{
switch ($request->sort) {
case 'identifier': // For backward compatibility
case 'accessionNumber':
$this->query->setSort(['identifier.untouched' => $request->sortDir]);
$this->search->query->setSort(['identifier.untouched' => $request->sortDir]);

break;

case 'title':
case 'alphabetic': // For backward compatibility
$field = sprintf('i18n.%s.title.alphasort', $this->context->user->getCulture());
$this->query->addSort([$field => $request->sortDir]);
$this->search->query->addSort([$field => $request->sortDir]);

break;

case 'acquisitionDate':
$this->query->addSort(['date' => ['order' => $request->sortDir, 'missing' => '_last']]);
$this->search->query->addSort(['date' => ['order' => $request->sortDir, 'missing' => '_last']]);

break;

Expand All @@ -153,16 +122,61 @@ public function execute($request)

case 'lastUpdated':
default:
$this->query->setSort(['updatedAt' => $request->sortDir]);
$this->search->query->setSort(['updatedAt' => $request->sortDir]);

break;
}
}

$resultSet = QubitSearch::getInstance()->index->getIndex('QubitAccession')->search($this->query);
/**
* Implement aggregations for fields in $AGGS.
*
* @param mixed $name
* @param mixed $buckets
*/
protected function populateAgg($name, $buckets)
{
switch ($name) {
case 'acquisitionType':
case 'resourceType':
case 'processingStatus':
case 'processingPriority':
$ids = array_column($buckets, 'key');
$criteria = new Criteria();
$criteria->add(QubitTerm::ID, $ids, Criteria::IN);

foreach (QubitTerm::get($criteria) as $item) {
$buckets[array_search($item->id, $ids)]['display'] = $item->getName(['cultureFallback' => true]);
}

$this->pager = new QubitSearchPager($resultSet);
$this->pager->setPage($request->page ? $request->page : 1);
$this->pager->setMaxPerPage($request->limit);
$this->pager->init();
break;

case 'donor':
$ids = array_column($buckets, 'key');
$criteria = new Criteria();
$criteria->add(QubitDonor::ID, $ids, Criteria::IN);

foreach (QubitDonor::get($criteria) as $item) {
$buckets[array_search($item->id, $ids)]['display'] = $item->__toString();
}

break;

case 'creator':
$ids = array_column($buckets, 'key');
$criteria = new Criteria();
$criteria->add(QubitActor::ID, $ids, Criteria::IN);

foreach (QubitActor::get($criteria) as $item) {
$buckets[array_search($item->id, $ids)]['display'] = $item->__toString();
}

break;

default:
return parent::populateAgg($name, $buckets);
}

return $buckets;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ public function execute($request)
);
$this->getUser()->setFlash('error', $message);
} else {
$getParameters = $request->getGetParameters();

if (isset($request->subquery)) {
$getParameters['sq0'] = $request->subquery;
}

if (1 !== preg_match('/^[\s\t\r\n]*$/', $request->sq0) && !isset($request->sf0)) {
$getParameters['subquery'] = $request->sq0;
}

$options = [
'params' => [
'slugs' => ['*'],
],
'params' => $getParameters,
];

QubitJob::runJob('arAccessionCsvExportJob', $options);
Expand Down
Loading
Loading