Forráskód Böngészése

查询参数支持 highlight tag

visuddhinanda 5 napja
szülő
commit
6a2956ae8c
1 módosított fájl, 13 hozzáadás és 2 törlés
  1. 13 2
      api-v12/app/Services/OpenSearchService.php

+ 13 - 2
api-v12/app/Services/OpenSearchService.php

@@ -424,6 +424,17 @@ class OpenSearchService
                 $query = $this->buildFuzzyQuery($params['query']);
         }
 
+        if (!empty($params['highlight_pre_tags'])) {
+            $highlight_pre_tags = $params['highlight_pre_tags'];
+        } else {
+            $highlight_pre_tags = ['<mark>'];
+        }
+        if (!empty($params['highlight_post_tags'])) {
+            $highlight_post_tags = $params['highlight_post_tags'];
+        } else {
+            $highlight_post_tags = ['</mark>'];
+        }
+
         // ---------- 最终 DSL ----------
         $dsl = [
             'from' => $from,
@@ -451,8 +462,8 @@ class OpenSearchService
                 "fragmenter" => "sentence",
                 "fragment_size" => 200,
                 "number_of_fragments" => 1,
-                'pre_tags' => ['_'],
-                'post_tags' => ['_'],
+                'pre_tags' => $highlight_pre_tags,
+                'post_tags' => $highlight_post_tags,
             ],
         ];