0

Setup:

  1. I have indexed node content with a few fields from the content, using search_api, in the database
  2. I have setup a view that lists that indexed content with a fulltext search filter, and some other filters
  3. I've successfully added STATIC data related to this indexed content to the view, by adding that data to the index as well (think of the author, taxonomy term data etc)
  4. How do I add something to this listing that changes constantly? (think about views on that content, and other user interactions)
  5. The end goal is to sort by that dynamic data. We can take the views as an example.

I've tried adding a custom relationship from the indexed content to the dynamic content to list those views, example:

    $data['$INDEX_ID']['$RELATIONSHIP_NAME'] = [
      'title' => t('Title'),
      'help' => t('Description'),
      'relationship' => [
        'base' => 'like_count',
        'base field' => 'like_count_nid',
        'field' => '$INDEX_FIELD_THAT_MATCHES_like_count_nid',
        'id' => 'search_api', // Tried "standard" too but that one throws an error when it tries to add the relationship.
        'label' => t('Some label')
      ]
    ];

This lets me add the relationship and field to the view but they all come out as null when I access the view, even though there is data. I've went down the path of data to check, and there are views for some nodes.

Has anyone ever done this before?

I can probably achieve it by embedding another view in this view but I was told to avoid that as it is bad practice and can lead to slowdowns. (EDIT: nevermind this, that wouldn't work as I need the sorting here not the display of the data)

I can also probably add it using a pre_execute hook, I'm not sure.

I'm assuming that indexing this dynamic data would be a terrible idea, am I wrong?

I'd appreciate any pointers at all here.

0

Your Answer

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

Browse other questions tagged or ask your own question.