Skip to content

Commit

Permalink
Limit on /search is not deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
Keredu committed May 24, 2024
1 parent e5c8719 commit 2192978
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion apps/api/src/controllers/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ export async function searchHelper(

const tbs = searchOptions.tbs ?? null;
const filter = searchOptions.filter ?? null;
const num_results = searchOptions.limit ?? 7;
const num_results_buffer = Math.floor(num_results * 1.5);

let res = await search({
query: query,
advanced: advanced,
num_results: searchOptions.limit ?? 7,
num_results: num_results_buffer,
tbs: tbs,
filter: filter,
lang: searchOptions.lang ?? "en",
Expand All @@ -47,6 +49,9 @@ export async function searchHelper(
}

res = res.filter((r) => !isUrlBlocked(r.url));
if (res.length > num_results) {
res = res.slice(0, num_results);
}

if (res.length === 0) {
return { success: true, error: "No search results found", returnCode: 200 };
Expand Down

0 comments on commit 2192978

Please sign in to comment.