Skip to content

Commit d771551

Browse files
author
Mateusz Dębiński
committed
IBX-10311: Changed example of field mapper
1 parent 14a39ce commit d771551

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

code_samples/search/custom/config/field_mapper_services.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
services:
2-
App\Search\Mapper\WebinarEventTitleFulltextFieldMapper:
2+
App\Search\FieldMapper\WebinarEventParentNameFieldMapper:
33
arguments:
44
- '@Ibexa\Contracts\Core\Persistence\Content\Handler'
55
- '@Ibexa\Contracts\Core\Persistence\Content\Location\Handler'

code_samples/search/custom/src/Search/FieldMapper/WebinarEventTitleFulltextFieldMapper.php renamed to code_samples/search/custom/src/Search/FieldMapper/WebinarEventParentNameFieldMapper.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
use Ibexa\Contracts\Core\Search;
99
use Ibexa\Contracts\Solr\FieldMapper\ContentFieldMapper;
1010

11-
class WebinarEventTitleFulltextFieldMapper extends ContentFieldMapper
11+
class WebinarEventParentNameFieldMapper extends ContentFieldMapper
1212
{
1313
protected ContentHandler $contentHandler;
14-
1514
protected LocationHandler $locationHandler;
1615

1716
public function __construct(
@@ -22,13 +21,16 @@ public function __construct(
2221
$this->locationHandler = $locationHandler;
2322
}
2423

25-
public function accept(Content $content)
24+
public function accept(Content $content): bool
2625
{
2726
// ContentType with ID 42 is webinar event
28-
return $content->versionInfo->contentInfo->contentTypeId == 42;
27+
return $content->versionInfo->contentInfo->contentTypeId === 42;
2928
}
3029

31-
public function mapFields(Content $content)
30+
/**
31+
* @return Search\Field[]
32+
*/
33+
public function mapFields(Content $content): array
3234
{
3335
$mainLocationId = $content->versionInfo->contentInfo->mainLocationId;
3436
$location = $this->locationHandler->load($mainLocationId);
@@ -37,9 +39,9 @@ public function mapFields(Content $content)
3739

3840
return [
3941
new Search\Field(
40-
'fulltext',
42+
'parent_name',
4143
$parentContentInfo->name,
42-
new Search\FieldType\FullTextField()
44+
new Search\FieldType\StringField()
4345
),
4446
];
4547
}

docs/search/extensibility/solr_document_field_mappers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ Mappers can be used on the extension points by registering them with the [servic
5252
- Location documents
5353
- `ibexa.search.solr.field.mapper.location`
5454

55-
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.
55+
The following example shows how you can index data from the parent location content, to make it available for search on the child content.
5656
The example relies on a use case of indexing webinar data on the webinar events, which are children of the webinar.
5757
The field mapper could then look like this:
5858

5959
```php
6060
[[= include_file('code_samples/search/custom/src/Search/FieldMapper/WebinarEventTitleFulltextFieldMapper.php') =]]
6161
```
6262

63-
You index full text data only on the content document, therefore, you would register the service like this:
63+
You index text data only on the content document, therefore, you would register the service like this:
6464

6565
``` yaml
6666
[[= include_file('code_samples/search/custom/config/field_mapper_services.yaml') =]]

0 commit comments

Comments
 (0)