diff --git a/code_samples/search/custom/config/field_mapper_services.yaml b/code_samples/search/custom/config/field_mapper_services.yaml index 4da008c53b..413e3cbd1b 100644 --- a/code_samples/search/custom/config/field_mapper_services.yaml +++ b/code_samples/search/custom/config/field_mapper_services.yaml @@ -1,5 +1,5 @@ services: - App\Search\Mapper\WebinarEventTitleFulltextFieldMapper: + App\Search\FieldMapper\WebinarEventParentNameFieldMapper: arguments: - '@Ibexa\Contracts\Core\Persistence\Content\Handler' - '@Ibexa\Contracts\Core\Persistence\Content\Location\Handler' diff --git a/code_samples/search/custom/src/Search/FieldMapper/WebinarEventTitleFulltextFieldMapper.php b/code_samples/search/custom/src/Search/FieldMapper/WebinarEventParentNameFieldMapper.php similarity index 79% rename from code_samples/search/custom/src/Search/FieldMapper/WebinarEventTitleFulltextFieldMapper.php rename to code_samples/search/custom/src/Search/FieldMapper/WebinarEventParentNameFieldMapper.php index 6eae611537..d0e79206db 100644 --- a/code_samples/search/custom/src/Search/FieldMapper/WebinarEventTitleFulltextFieldMapper.php +++ b/code_samples/search/custom/src/Search/FieldMapper/WebinarEventParentNameFieldMapper.php @@ -8,7 +8,7 @@ use Ibexa\Contracts\Core\Search; use Ibexa\Contracts\Solr\FieldMapper\ContentFieldMapper; -class WebinarEventTitleFulltextFieldMapper extends ContentFieldMapper +class WebinarEventParentNameFieldMapper extends ContentFieldMapper { protected ContentHandler $contentHandler; @@ -22,13 +22,16 @@ public function __construct( $this->locationHandler = $locationHandler; } - public function accept(Content $content) + public function accept(Content $content): bool { // ContentType with ID 42 is webinar event - return $content->versionInfo->contentInfo->contentTypeId == 42; + return $content->versionInfo->contentInfo->contentTypeId === 42; } - public function mapFields(Content $content) + /** + * @return \Ibexa\Contracts\Core\Search\Field[] + */ + public function mapFields(Content $content): array { $mainLocationId = $content->versionInfo->contentInfo->mainLocationId; $location = $this->locationHandler->load($mainLocationId); @@ -37,9 +40,9 @@ public function mapFields(Content $content) return [ new Search\Field( - 'fulltext', + 'parent_name', $parentContentInfo->name, - new Search\FieldType\FullTextField() + new Search\FieldType\StringField() ), ]; } diff --git a/docs/search/extensibility/solr_document_field_mappers.md b/docs/search/extensibility/solr_document_field_mappers.md index 7ee4247782..3d4f6b826c 100644 --- a/docs/search/extensibility/solr_document_field_mappers.md +++ b/docs/search/extensibility/solr_document_field_mappers.md @@ -52,15 +52,15 @@ Mappers can be used on the extension points by registering them with the [servic - Location documents - `ibexa.search.solr.field.mapper.location` -The following example shows how you can index data from the parent location content, to make it available for full-text search on the child content. +The following example shows how you can index data from the parent location content, to make it available for search on the child content. The example relies on a use case of indexing webinar data on the webinar events, which are children of the webinar. The field mapper could then look like this: ```php -[[= include_file('code_samples/search/custom/src/Search/FieldMapper/WebinarEventTitleFulltextFieldMapper.php') =]] +[[= include_file('code_samples/search/custom/src/Search/FieldMapper/WebinarEventParentNameFieldMapper.php') =]] ``` -You index full text data only on the content document, therefore, you would register the service like this: +You index text data only on the content document, therefore, you would register the service like this: ``` yaml [[= include_file('code_samples/search/custom/config/field_mapper_services.yaml') =]]