Skip to content

Commit bc8b0ae

Browse files
Add highlight implementation for redisearch adapter
1 parent 93e52a6 commit bc8b0ae

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/seal-redisearch-adapter/src/RediSearchSchemaManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private function createJsonFields(array $fields, string $prefix = '', string $js
173173
'sortable' => $field->sortable,
174174
'filterable' => $field->filterable,
175175
],
176-
$field instanceof Field\ObjectField => $indexFields = \array_replace($indexFields, $this->createJsonFields($field->fields, $name, $jsonPath)),
176+
$field instanceof Field\ObjectField => $indexFields = \array_replace($indexFields, $this->createJsonFields($field->fields, $name . '.', $jsonPath)),
177177
$field instanceof Field\TypedField => \array_map(function ($fields, $type) use ($name, &$indexFields, $jsonPath, $field) {
178178
$newJsonPath = $jsonPath . '[\'' . $type . '\']';
179179
if ($field->multiple) {

packages/seal-redisearch-adapter/src/RediSearchSearcher.php

+14
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ public function search(Search $search): Result
9696
}
9797
}
9898

99+
if ($search->highlightFields !== []) {
100+
$arguments[] = 'HIGHLIGHT';
101+
$arguments[] = 'FIELDS';
102+
$arguments[] = \count($search->highlightFields);
103+
104+
foreach ($search->highlightFields as $highlightField) {
105+
$arguments[] = $highlightField;
106+
}
107+
108+
$arguments[] = 'TAGS';
109+
$arguments[] = $search->highlightPreTag;
110+
$arguments[] = $search->highlightPostTag;
111+
}
112+
99113
$arguments[] = 'DIALECT';
100114
$arguments[] = '3';
101115

0 commit comments

Comments
 (0)