Spaces:
Sleeping
Sleeping
File size: 1,350 Bytes
097eaf0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | import { Document } from "../controllers/v2/types";
import { SearchV2Response } from "../lib/entities";
export function transformToV1Response(
searchResponse: SearchV2Response,
): Document[] {
const documents: Document[] = [];
if (searchResponse.web && searchResponse.web.length > 0) {
for (const item of searchResponse.web) {
documents.push({
...item,
url: item.url,
title: item.title,
description: item.description,
} as Document);
}
}
if (searchResponse.news && searchResponse.news.length > 0) {
for (const item of searchResponse.news) {
if (item.url) {
documents.push({
...item,
url: item.url,
title: item.title || "",
description: item.snippet || "",
} as Document);
}
}
}
if (searchResponse.images && searchResponse.images.length > 0) {
for (const item of searchResponse.images) {
if (item.url) {
documents.push({
...item,
url: item.url,
title: item.title || "",
description: "",
} as Document);
}
}
}
return documents;
}
export function filterDocumentsWithContent(documents: Document[]): Document[] {
return documents.filter(
doc => doc.serpResults || (doc.markdown && doc.markdown.trim().length > 0),
);
}
|