refactor(search): use typed OpenSearch SDK request body
Some checks failed
CI / check (push) Failing after 1m0s

Pull in @opensearch-project/opensearch only for its
Search_RequestBody type so the inline search body is
type-checked. Also drops the unsupported
highlight.content.boundary_scanner_locale option.
This commit is contained in:
Julien Calixte
2026-06-07 12:04:43 +02:00
parent 4ff3ea6644
commit 7875d24d48
3 changed files with 42 additions and 7 deletions

View File

@@ -1,3 +1,4 @@
import type { API } from "@opensearch-project/opensearch";
import { log } from "../log.ts";
const OPENSEARCH_URL = Deno.env.get("OPENSEARCH_URL");
@@ -185,7 +186,9 @@ export const searchNotes = async (
filters.push({ term: { did: opts.did } });
}
const body: Record<string, unknown> = {
const searchAfter = opts.cursor ? decodeCursor(opts.cursor) : undefined;
const body: API.Search_RequestBody = {
size: limit,
query: {
bool: {
@@ -207,20 +210,15 @@ export const searchNotes = async (
fragment_size: 200,
number_of_fragments: 1,
boundary_scanner: "sentence",
boundary_scanner_locale: "en-US",
},
title: { number_of_fragments: 0 },
},
},
sort: [{ _score: "desc" }, { rkey: "desc" }],
_source: ["did", "rkey", "title", "content", "publishedAt"],
...(searchAfter ? { search_after: searchAfter } : {}),
};
if (opts.cursor) {
const decoded = decodeCursor(opts.cursor);
if (decoded) body.search_after = decoded;
}
const res = await request("POST", `/${OPENSEARCH_INDEX}/_search`, body);
if (!res.ok) {
const text = await res.text();