Skip to content

Commit ecddf75

Browse files
committed
FEATURE: Extended highlight configuration
Previously you only could define the highlighting for all fields and no_match_size was automatically active. Now teh parameters can be configured individually by field.
1 parent 10fd36c commit ecddf75

3 files changed

Lines changed: 18 additions & 17 deletions

File tree

Classes/Driver/AbstractQuery.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,19 @@ public function suggestions(string $name, array $suggestionDefinition): void
180180
/**
181181
* {@inheritdoc}
182182
*/
183-
public function highlight($fragmentSize, int $fragmentCount = null): void
183+
public function highlight($fragmentSize, int $fragmentCount = null, int $noMatchSize = 150, string $field = 'neos_fulltext.*'): void
184184
{
185185
if ($fragmentSize === false) {
186186
// Highlighting is disabled.
187187
unset($this->request['highlight']);
188-
} else {
189-
$this->request['highlight'] = [
190-
'fields' => [
191-
'neos_fulltext*' => [
192-
'fragment_size' => $fragmentSize,
193-
'no_match_size' => $fragmentSize,
194-
'number_of_fragments' => $fragmentCount
195-
]
196-
]
197-
];
188+
return;
198189
}
190+
191+
$this->request['highlight']['fields'][$field] = [
192+
'fragment_size' => $fragmentSize,
193+
'no_match_size' => $noMatchSize,
194+
'number_of_fragments' => $fragmentCount
195+
];
199196
}
200197

201198
/**

Classes/Driver/QueryInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ public function fulltext(string $searchWord, array $options = []): void;
8686
* It can be disabled by calling "highlight(FALSE)".
8787
*
8888
* @param integer|boolean $fragmentSize The result fragment size for highlight snippets. If this parameter is FALSE, highlighting will be disabled.
89-
* @param integer $fragmentCount The number of highlight fragments to show.
89+
* @param int|null $fragmentCount The number of highlight fragments to show.
90+
* @param int $noMatchSize
91+
* @param string $field
9092
* @return void
9193
* @api
9294
*/
93-
public function highlight($fragmentSize, int $fragmentCount = null): void;
95+
public function highlight($fragmentSize, int $fragmentCount = null, int $noMatchSize = 150, string $field = 'neos_fulltext.*'): void;
9496

9597
/**
9698
* This method is used to create any kind of aggregation.

Classes/Eel/ElasticSearchQueryBuilder.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,14 +730,16 @@ public function geoDistance(string $propertyName, $geoPoint, string $distance, s
730730
* Configure Result Highlighting. Only makes sense in combination with fulltext(). By default, highlighting is enabled.
731731
* It can be disabled by calling "highlight(FALSE)".
732732
*
733-
* @param integer|boolean $fragmentSize The result fragment size for highlight snippets. If this parameter is FALSE, highlighting will be disabled.
734-
* @param integer $fragmentCount The number of highlight fragments to show.
733+
* @param int|bool $fragmentSize The result fragment size for highlight snippets. If this parameter is FALSE, highlighting will be disabled.
734+
* @param int|null $fragmentCount The number of highlight fragments to show.
735+
* @param int $noMatchSize
736+
* @param string $field
735737
* @return ElasticSearchQueryBuilder
736738
* @api
737739
*/
738-
public function highlight($fragmentSize, int $fragmentCount = null): ElasticSearchQueryBuilder
740+
public function highlight($fragmentSize, int $fragmentCount = null, int $noMatchSize = 150, string $field = 'neos_fulltext.*'): ElasticSearchQueryBuilder
739741
{
740-
$this->request->highlight($fragmentSize, $fragmentCount);
742+
$this->request->highlight($fragmentSize, $fragmentCount, $noMatchSize, $field);
741743

742744
return $this;
743745
}

0 commit comments

Comments
 (0)