import type {SearchResult} from "@/types/search.types";
import type { SearchRequest } from "@/types/request.types";
import * as searchClient from "@/client/search.client"

export async function search(query: SearchRequest): Promise<SearchResult> {
  if (!query.dataSources) {
    query["dataSources"] = ["CN"];
  }
  const result = await searchClient.search(query)
  if (result.docs && result.docs.length > 0) {
    for (const doc of result.docs) {
      if (doc.keywords == null) {
        doc.keywords = []
      }
    }
  }
  return result
}
