Explorar el Código

🐛 (api-v13): OpenSearch 检索的 channel 与 related_id 过滤不生效

- channel:metadata.channel 在映射里是 text,标准分词器按连字符把 uuid 拆开,
  term 拿整个 uuid 去比永远对不上,改用 match_phrase
- related_id:传数组时用 term 会让 OpenSearch 报错,数组改用 terms(命中任一)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
visuddhinanda hace 17 horas
padre
commit
afc1e829c1
Se han modificado 1 ficheros con 8 adiciones y 4 borrados
  1. 8 4
      api-v13/app/Services/OpenSearchService.php

+ 8 - 4
api-v13/app/Services/OpenSearchService.php

@@ -431,9 +431,9 @@ class OpenSearchService
      * @type string $category           按分类过滤
      * @type array $tags               按标签过滤(terms)
      * @type array $pageRefs           按页码引用过滤(terms)
-     * @type string $relatedId          按关联 ID 过滤
+     * @type string|array $relatedId    按关联 ID 过滤(数组时命中任一)
      * @type string $author             按作者过滤
-     * @type string $channel            按频道过滤
+     * @type string $channel            按频道过滤(channel uuid)
      * @type array $highlight_pre_tags 高亮前置标签,默认 ['<mark>']
      * @type array $highlight_post_tags 高亮后置标签,默认 ['</mark>']
      *             }
@@ -497,15 +497,19 @@ class OpenSearchService
         }
 
         if (! empty($params['relatedId'])) {
-            $filters[] = ['term' => ['related_id' => $params['relatedId']]];
+            $filters[] = is_array($params['relatedId'])
+                ? ['terms' => ['related_id' => array_values($params['relatedId'])]]
+                : ['term' => ['related_id' => $params['relatedId']]];
         }
 
         if (! empty($params['author'])) {
             $filters[] = ['match' => ['metadata.author' => $params['author']]];
         }
 
+        // metadata.channel 在映射里是 text(标准分词器会把 uuid 按连字符拆开),
+        // term 拿整个 uuid 去比永远对不上,只能按短语匹配
         if (! empty($params['channel'])) {
-            $filters[] = ['term' => ['metadata.channel' => $params['channel']]];
+            $filters[] = ['match_phrase' => ['metadata.channel' => $params['channel']]];
         }
 
         // ---------- 查询部分 ----------