visuddhinanda 22 часов назад
Родитель
Сommit
1046f2bd17
1 измененных файлов с 28 добавлено и 2 удалено
  1. 28 2
      api-v12/app/DTO/Search/HitItemDTO.php

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

@@ -11,22 +11,48 @@ class HitItemDTO
         public string $title,
         public string $title,
         public string $path,
         public string $path,
         public array $category,
         public array $category,
+        public string $highlight,
+
     ) {}
     ) {}
 
 
     public static function fromArray(array $data): self
     public static function fromArray(array $data): self
     {
     {
         $source = $data['_source'];
         $source = $data['_source'];
+        $highlight = $data['highlight'];
+        $highlightArray = [];
+        if (is_array($highlight)) {
+            foreach ($highlight as $key => $value) {
+                $highlightArray = array_merge($highlightArray, $value);
+            }
+        }
+
+        $content = $source['content'];
+        $contentArray = [];
+        if (is_array($content)) {
+            foreach ($content as $key => $value) {
+                $contentArray[] = $value;
+            }
+        }
+        $category = [];
+        if (is_array($source['category'])) {
+            $category = $source['category'];
+        } else {
+            $category = [$source['category']];
+        }
 
 
         return new self(
         return new self(
             id: $source['id'],
             id: $source['id'],
             score: $data['_score'],
             score: $data['_score'],
             title: $source['title']['pali'] ?? '',
             title: $source['title']['pali'] ?? '',
-            content: $source['content']['pali'] ?? '',
+            content: implode('', $contentArray),
             path: $source['path'] ?? '',
             path: $source['path'] ?? '',
-            category: $source['category'] ?? [],
+            category: $category,
+            highlight: implode('', $highlightArray),
         );
         );
     }
     }
 
 
+
+
     /**
     /**
      * 提取 para 引用ID(核心逻辑🔥)
      * 提取 para 引用ID(核心逻辑🔥)
      */
      */