8.4.2: is there better way of getting searchable content?

Permalink
At the moment I get searchable content in a block with the following:
public function getSearchableContent()
{
    $content = '';
    $page = $this->getCollectionObject();
    if (!$page->isError()) {
        $cid = $page->getCollectionID();
        if ($cid) {
            $my_object = MyObject::getByCollectionID($cid);
            if ($my_object) {
                $content = $my_object->getTitle() . ' ' . trim(strip_tags(html_entity_decode($my_object->getContent(), ENT_QUOTES, 'UTF-8')));
            }
        }
    }
    return $content;
}

Is there a better way of doing this?

If I don't have such a block, how can I do the same without a block, straight from the database (for the entity object)? That is, can I make my object's db table indexable and searchable?

linuxoid
 
linuxoid replied on at Permalink Reply
linuxoid
bump
JohntheFish replied on at Permalink Reply
JohntheFish
An extreme trick is to scrape the search text off a rendered page, either directly via php and an http request, or indirectly via JS embedded in the page with an ajax callback to save it and some gating to make sure it just doesn't continuously update every page render.

The JS way ensures all kinds of content generated by script also gets captured.

Or you could combine the 2 using a headless browser.

I haven't done it for the search index, but implemented similar for auto-generating metadata on 5.6.