Skip to content

Helper: Search

The search library included in XELOS delivers search functionality across all modules via an SQL or ELASTIC SEARCH interface.

Adding documents to the search index

If you already have a module with a document model, the easiest way to add your document data to the central search is by implementing the SearchableDocumentModelInterface in your DocumentModel:

MyDocumentModel.php (Example)

class MyDocumentModel extends DocumentModel implements SearchableDocumentModelInterface {
    [...]

    public function updateSearchIndex(SearchIndexRecord $searchIndexRecord): SearchIndexRecord {

        // Set Base-Index
        $searchIndexRecord
            ->setIndexContent($this->myContent)
            ->setTitle($this->title)
            ->setSummary($this->description);

        // If additional language versions are available -> Add them as translated content
        $searchIndexRecord->addTranslatedContent('EN_GB')->addTitle($this->title_en);

        // Return index record
        return $searchIndexRecord;
    }
}

You need to make sure that your document model is registered for index_events in your config.yml:

document_registry:
  myDocumentModel:
    [...]
    registered_for: ['search', 'index_events']