Skip to content

Commit

Permalink
Issue #3342805: Support future dates in solr_boost_more_recent proces…
Browse files Browse the repository at this point in the history
…sor. (#87)
  • Loading branch information
vever001 authored Feb 1, 2024
1 parent cefdd0a commit 69b4956
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Plugin/search_api/processor/BoostMoreRecent.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public function buildConfigurationForm(array $form, FormStateInterface $formStat
'#title' => $this->t('Constant b'),
'#default_value' => $this->configuration['boosts'][$field_id]['b'] ?? 0.05,
];

$form['boosts'][$field_id]['support_future_dates'] = [
'#type' => 'checkbox',
'#title' => $this->t('Support future dates'),
'#default_value' => $this->configuration['boosts'][$field_id]['support_future_dates'] ?? FALSE,
'#description' => $this->t('Check this box if this field can contain future dates.'),
];
}
}

Expand Down Expand Up @@ -124,7 +131,11 @@ public function preprocessSearchQuery(QueryInterface $query) {

$boosts = $query->getOption('solr_document_boost_factors', []);
foreach ($this->configuration['boosts'] as $field_id => $boost) {
$boosts[$field_id] = sprintf('product(%.2F,recip(ms(%s,%s),%s,%.3F,%3F))', $boost['boost'], $boost['resolution'], SolrBackendInterface::FIELD_PLACEHOLDER, $boost['m'], $boost['a'], $boost['b']);
$support_future_dates = $boost['support_future_dates'] ?? FALSE;
$formula = $support_future_dates
? 'product(%.2F,recip(abs(ms(%s,%s)),%s,%.3F,%3F))'
: 'product(%.2F,recip(ms(%s,%s),%s,%.3F,%3F))';
$boosts[$field_id] = sprintf($formula, $boost['boost'], $boost['resolution'], SolrBackendInterface::FIELD_PLACEHOLDER, $boost['m'], $boost['a'], $boost['b']);
}
if ($boosts) {
$query->setOption('solr_document_boost_factors', $boosts);
Expand Down

0 comments on commit 69b4956

Please sign in to comment.