Need a way to tell if content is being rendered by the indexing

Created on 6 October 2022, almost 3 years ago
Updated 29 May 2023, about 2 years ago

I am needing to change what is being rendered on the node for the "rendered_item" search field. I need a level of control that means I can't just use the search index view mode for this. I've been using a messy and fragile work-around for now but what I really could use is some sort of indicator that is viewable within the various preprocesses that this node view is happening due to the node being indexed. I've poked around in xdebug and haven't found anything.

So first off, is there already some indicator that I've missed? If not, any suggestions on how I could add one? I was thinking what might work is making it run as a specific user rather than anonymous (which would also fix one of the problems I'm trying to fix at the same time). But this is a complex module and I don't have a clue where to even begin making a change like that. I'd appreciate any pointers. Thanks. :)

💬 Support request
Status

Fixed

Version

1.0

Component

General code

Created by

🇺🇸United States michelle Wisconsin, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇹Austria drunken monkey Vienna, Austria

    See 🐛 Rendered item is not indexed in groups content using layout builder Needs work for a ticket which proposes to set a specific user while indexing. That’s where you’d want to make that change: in the \Drupal\search_api\Plugin\search_api\processor\RenderedItem::addFieldValues() method, where the call to $this->getAccountSwitcher()->switchTo() is made.
    Another way would be to use debug_backtrace() and look (for example) for \Drupal\search_api\Entity\Index::indexSpecificItems().
    Finally, you could listen to the \Drupal\search_api\Event\IndexingItemsEvent (search_api.indexing_items) and \Drupal\search_api\Event\ItemsIndexedEvent (search_api.items_indexed) events and set/unset some global state between them. This could only cause problems when all items fail indexing, but even then it’s probably no big deal if your workaround is active for the rest of the page request – it will either be right at the end anyways, or in a batch process, or in Drush, and in none of these cases a node would get rendered after indexing happens.

    I hope this helps.

  • 🇺🇸United States michelle Wisconsin, USA

    Thanks, that other ticket looks useful. I'll dig into that one once the client prioritizes this again. It would be nice to have a more stable solution than the hack-around I did.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024