0

On Drupal 8, I try to make a facet on a taxonomy term contained in a paragraph entity contained in a content type. Is it possible?

My stack : Druapl 8.9.0 + Search API 8.x-1.17 + Facets 8.x-1.5

In Search API, I have indexed the taxonomy from the paragraph. In database I have a new table with 2 columns entity and taxonomy. It seems OK to link node with paragraph with taxonomy id.

enter image description here

I have created the facet without problem but it does not display on my search page.

Is someone has realized this before? Or maybe a advise to resolve this problem.

1 Answer 1

0

A solution is to associate the taxonomy directly with the content type (field_ingredient_search_index in the example below) and make a hook to update it automatically.

$nodeTerms = []; // 1,2,3 = terms IDs
$erase = [];
$node->set('field_ingredient_search_index', $erase);
    
foreach ($node->get('field_liste_ingredients')->referencedEntities() as $enty){
    
  if($enty->getParagraphType()->id == 'ingredient' && isset($enty->get('field_ingredient')->target_id)) {
      $nodeTerms[] = $enty->get('field_ingredient')->target_id;
  }
    
}
    
$node->set('field_ingredient_search_index', $nodeTerms);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.