import type { SearXNGSearchResponse } from "../searxng/types.js";
/**
* Format search results for display
*/
export function formatSearchResults(
data: SearXNGSearchResponse,
type: "web" | "images" | "news"
): string {
if (!data.results || data.results.length === 0) {
return `No ${type} results found for "${data.query}".`;
}
const lines: string[] = [];
lines.push(`Search results for "${data.query}":`);
if (data.number_of_results) {
lines.push(`(${data.number_of_results} results)`);
}
lines.push("");
for (const result of data.results.slice(0, 10)) {
lines.push(`## ${result.title}`);
lines.push(`URL: ${result.url}`);
if (result.content) {
lines.push(result.content);
}
if (result.engines && result.engines.length > 0) {
lines.push(`Sources: ${result.engines.join(", ")}`);
}
lines.push("");
}
// Add suggestions if available
if (data.suggestions && data.suggestions.length > 0) {
lines.push("---");
lines.push(`Suggestions: ${data.suggestions.join(", ")}`);
}
// Add corrections if available
if (data.corrections && data.corrections.length > 0) {
lines.push("---");
lines.push(`Did you mean: ${data.corrections.join(", ")}`);
}
return lines.join("\n");
}