Currently, the AI Search processor in the ai_search module executes the search query and returns scored entity results directly.
There is no way for other modules to adjust or re-rank these results before they are returned.
This issue introduces a new hook:
hook_ai_search_results_alter(array &$results, $keywords)
The new hook allows other modules to:
function mymodule_ai_search_results_alter(array &$results, $keywords): void {
// Example: Boost a specific node manually.
if (isset($results['entity:node/8215:en'])) {
$results['entity:node/8215:en'] += 0.2;
}
// Example: Slightly boost all "article" nodes.
foreach ($results as $entity_id => $score) {
if (preg_match('/^entity:node\/(\d+)/', $entity_id, $matches)) {
$nid = (int) $matches[1];
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
if ($node && $node->bundle() === 'article') {
$results[$entity_id] = $score + 0.05;
}
}
}
arsort($results);
}
Developer Notes
Benefits
Active
1.2
AI Search
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
No activities found.