WT-Ranger
WT-Ranger

Reputation: 1

Core Taxonomy Term Views using Search API Indexed content, NOT normal content

This seems like a logical use case, but I cannot find any information about how to do this. I am creating a large, number of pages, site and want to use Solr Indexed data on the Taxonomy Term pages. The indexed content is not available in the normal Taxonomy Term view page. Any suggestions on how to create this?

(A) I have tried using a view of indexed data and then trying to set the path to the taxonomy term page using a contextual filter with the term ID. But the Content: Has term ID contextual filter is not an option with and indexed data view.

(B) I tried creating a aggregated field of the term ID's hope I could use those to pass to the path, with no success.

Upvotes: 0

Views: 486

Answers (1)

Balde Binos
Balde Binos

Reputation: 135

I'm not sure the following is the only solution.

I follow Your first approach:

  1. Create a view;
  2. Create a page;
  3. Set the path to taxonomy/term/% (assuming You disabled the "normal" taxonomy page);
  4. In advanced→contextual filers add the reference fields to the taxonomies (assuming those fields are included in the SOLR index);
  5. Set those contextual filters to use as predefined value the ID of the taxonomy from the URL.

Now, this might not work out of the box since the contextual filters will be processed as an AND condition (I think this is the default), therefore no results will be displayed.

Create some custom module (if you don't already have one) and include some code like:

/**
* Implementation of hook_views_query_alter().
*/
function your_module_views_query_alter(Drupal\views\ViewExecutable $view, Drupal\views\Plugin\views\query\QueryPluginBase $query) {

    $target_view_name = 'the_view_machine_name';
    $target_display_id = 'the_display_machine_name';

    if ($view->id() === $target_view_name && $view->current_display === $target_display_id) {

        $where = &$query->getWhere();
        $where[0]['type'] = 'OR';
    }
}

Don't forget to clear the caches.

Upvotes: 0

Related Questions