Skip to content

Commit 073e600

Browse files
mateuszdebinskiMateusz Dębiński
andauthored
IBX-10311: Changed example of field mapper (#2828)
* IBX-10311: Changed example of field mapper * PHP & JS CS Fixes * Corrected FQCN * Corrected filename --------- Co-authored-by: Mateusz Dębiński <[email protected]> Co-authored-by: mateuszdebinski <[email protected]>
1 parent b434866 commit 073e600

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-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'
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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;
1414

@@ -22,13 +22,16 @@ public function __construct(
2222
$this->locationHandler = $locationHandler;
2323
}
2424

25-
public function accept(Content $content)
25+
public function accept(Content $content): bool
2626
{
2727
// ContentType with ID 42 is webinar event
28-
return $content->versionInfo->contentInfo->contentTypeId == 42;
28+
return $content->versionInfo->contentInfo->contentTypeId === 42;
2929
}
3030

31-
public function mapFields(Content $content)
31+
/**
32+
* @return \Ibexa\Contracts\Core\Search\Field[]
33+
*/
34+
public function mapFields(Content $content): array
3235
{
3336
$mainLocationId = $content->versionInfo->contentInfo->mainLocationId;
3437
$location = $this->locationHandler->load($mainLocationId);
@@ -37,9 +40,9 @@ public function mapFields(Content $content)
3740

3841
return [
3942
new Search\Field(
40-
'fulltext',
43+
'parent_name',
4144
$parentContentInfo->name,
42-
new Search\FieldType\FullTextField()
45+
new Search\FieldType\StringField()
4346
),
4447
];
4548
}

docs/search/extensibility/solr_document_field_mappers.md

Lines changed: 3 additions & 3 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
60-
[[= include_file('code_samples/search/custom/src/Search/FieldMapper/WebinarEventTitleFulltextFieldMapper.php') =]]
60+
[[= include_file('code_samples/search/custom/src/Search/FieldMapper/WebinarEventParentNameFieldMapper.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)