Browse Source

没有highlight 降级 null

visuddhinanda 2 days ago
parent
commit
28c529c88b
1 changed files with 10 additions and 2 deletions
  1. 10 2
      api-v12/app/DTO/Search/HitItemDTO.php

+ 10 - 2
api-v12/app/DTO/Search/HitItemDTO.php

@@ -18,7 +18,7 @@ class HitItemDTO
     public static function fromArray(array $data): self
     public static function fromArray(array $data): self
     {
     {
         $source = $data['_source'];
         $source = $data['_source'];
-        $highlight = $data['highlight'];
+        $highlight = $data['highlight'] ?? null;
         $highlightArray = [];
         $highlightArray = [];
         if (is_array($highlight)) {
         if (is_array($highlight)) {
             foreach ($highlight as $key => $value) {
             foreach ($highlight as $key => $value) {
@@ -33,6 +33,14 @@ class HitItemDTO
                 $contentArray[] = $value;
                 $contentArray[] = $value;
             }
             }
         }
         }
+        $titleArray = [];
+        if (is_array($source['title'])) {
+            foreach ($source['title'] as $key => $value) {
+                $titleArray[] = $value;
+            }
+        }
+        $title = implode('', $titleArray);
+
         $category = [];
         $category = [];
         if (is_array($source['category'])) {
         if (is_array($source['category'])) {
             $category = $source['category'];
             $category = $source['category'];
@@ -43,7 +51,7 @@ class HitItemDTO
         return new self(
         return new self(
             id: $source['id'],
             id: $source['id'],
             score: $data['_score'],
             score: $data['_score'],
-            title: $source['title']['pali'] ?? '',
+            title: $title,
             content: implode('', $contentArray),
             content: implode('', $contentArray),
             path: $source['path'] ?? '',
             path: $source['path'] ?? '',
             category: $category,
             category: $category,