Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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()
),
];
}
Expand Down
6 changes: 3 additions & 3 deletions docs/search/extensibility/solr_document_field_mappers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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') =]]
Expand Down
Loading