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)

<?php
use XELOS\Framework\Module\Model\DocumentModel;
use XELOS\Framework\Core\Interfaces\SearchableDocumentModelInterface;
use XELOS\Modules\Search\SearchIndexRecord;

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

    public function onSearchIndexUpdate(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 by implements the SeachableDocumentModelInterface.

Adding additional faceted filters to the search results

The search index has been extended, so that modules can add meta data to the index with the SearchIndexRecord:

/** SearchIndexRecord $baseIndexRecord */
$baseIndexRecord->addMetaData('extension', $this->get_file_extension());
# Alternatively, set multiple meta data
$meta = [
  'filesize' => '9894',
  'extension => 'pptx',
  // ...
];
$baseIndexRecord->setMetaData($meta);

Alternatively other modules can add meta data with the SearchPreprocessor hook:

$baseIndexRecord->addMetaData('extension', $this->get_file_extension(), $this->mod->context);

The given instance ID ($this->mod->context) later decides which hook handles display and filtering of the faceted values. If no context is given, the context ID of the document index of the search index record is used.

The added meta data requires a \XELOS\Modules\Search\Hook\Base\SearchMetaData hook. The hook returns the labels for the keys and the values of the meta data array.

Further it is possible to define custom aggregations to return custom values which are not in the index, e.g. the System DMS saves the filesize for each DMS file in the index, but it returns a facetted filter for files smaller then 1 MB, 1-5MB and bigger than 5MB. To enable the custom values a custom search query is implemented in getSearchQuery.

See \XELOS\Modules\SystemDMS\Hook\Search\SearchMetaData for details.

Updating the index

To get the defined meta data into the search index, a re-indexing of the instances is required, e.g. the Lookbook enables filtering by the browsable properties (used on the browse page). To enable filtering of all profiles, the Lookbook instance has to be re-indexed.