Setup:
- I have indexed node content with a few fields from the content, using search_api, in the database
- I have setup a view that lists that indexed content with a fulltext search filter, and some other filters
- 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)
- How do I add something to this listing that changes constantly? (think about views on that content, and other user interactions)
- 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.