Skip to content

Commit f21819c

Browse files
committed
Highlight & error handling improvements
1 parent b3a5bf4 commit f21819c

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/DSL/Bridge.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ private function _sanitizeSearchResponse($response, $params, $queryTag)
10151015

10161016
//Meta data
10171017
if (!empty($hit['highlight'])) {
1018-
$datum['_meta']['highlights'] = $hit['highlight'];
1018+
$datum['_meta']['highlights'] = $this->_sanitizeHighlights($hit['highlight']);
10191019
}
10201020

10211021
$datum['_meta']['_index'] = $hit['_index'];
@@ -1032,6 +1032,23 @@ private function _sanitizeSearchResponse($response, $params, $queryTag)
10321032
return $this->_return($data, $meta, $params, $queryTag);
10331033
}
10341034

1035+
private function _sanitizeHighlights($highlights)
1036+
{
1037+
//remove keyword results
1038+
foreach ($highlights as $field => $vals) {
1039+
if (str_contains($field, '.keyword')) {
1040+
$cleanField = str_replace('.keyword', '', $field);
1041+
if (isset($highlights[$cleanField])) {
1042+
unset($highlights[$field]);
1043+
} else {
1044+
$highlights[$cleanField] = $vals;
1045+
}
1046+
}
1047+
}
1048+
1049+
return $highlights;
1050+
}
1051+
10351052
private function _sanitizeAggsResponse($response, $params, $queryTag)
10361053
{
10371054
$meta['timed_out'] = $response['timed_out'];

src/DSL/Results.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ private function _decodeError($error)
4242
$return['msg'] = $error;
4343
$return['data'] = [];
4444
$jsonStartPos = strpos($error, ': ') + 2;
45-
$response = stripslashes($error);
45+
$response = ($error);
4646
$title = substr($response, 0, $jsonStartPos);
4747
$jsonString = substr($response, $jsonStartPos);
4848
$errorArray = json_decode($jsonString, true);
49+
4950
if (json_last_error() === JSON_ERROR_NONE) {
5051
$errorReason = $errorArray['error']['reason'] ?? null;
5152
if (!$errorReason) {

0 commit comments

Comments
 (0)