mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-18 19:55:55 +08:00
Nick: search
This commit is contained in:
parent
a8e0482718
commit
9297afd1ff
@ -5,6 +5,58 @@ import { logger } from "../lib/logger";
|
|||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
|
|
||||||
|
export async function fire_engine_search(
|
||||||
|
q: string,
|
||||||
|
options: {
|
||||||
|
tbs?: string;
|
||||||
|
filter?: string;
|
||||||
|
lang?: string;
|
||||||
|
country?: string;
|
||||||
|
location?: string;
|
||||||
|
numResults: number;
|
||||||
|
page?: number;
|
||||||
|
},
|
||||||
|
abort?: AbortSignal,
|
||||||
|
): Promise<SearchResult[]> {
|
||||||
|
try {
|
||||||
|
let data = JSON.stringify({
|
||||||
|
query: q,
|
||||||
|
lang: options.lang,
|
||||||
|
country: options.country,
|
||||||
|
location: options.location,
|
||||||
|
tbs: options.tbs,
|
||||||
|
numResults: options.numResults,
|
||||||
|
page: options.page ?? 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!process.env.FIRE_ENGINE_BETA_URL) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`${process.env.FIRE_ENGINE_BETA_URL}/search`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"X-Disable-Cache": "true",
|
||||||
|
},
|
||||||
|
body: data,
|
||||||
|
signal: abort,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const responseData = await response.json();
|
||||||
|
return responseData;
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
Sentry.captureException(error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function fireEngineMap(
|
export async function fireEngineMap(
|
||||||
q: string,
|
q: string,
|
||||||
options: {
|
options: {
|
||||||
@ -34,7 +86,7 @@ export async function fireEngineMap(
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(`${process.env.FIRE_ENGINE_BETA_URL}/search`, {
|
const response = await fetch(`${process.env.FIRE_ENGINE_BETA_URL}/map`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -4,6 +4,7 @@ import { googleSearch } from "./googlesearch";
|
|||||||
import { searchapi_search } from "./searchapi";
|
import { searchapi_search } from "./searchapi";
|
||||||
import { serper_search } from "./serper";
|
import { serper_search } from "./serper";
|
||||||
import { searxng_search } from "./searxng";
|
import { searxng_search } from "./searxng";
|
||||||
|
import { fire_engine_search } from "./fireEngine";
|
||||||
|
|
||||||
export async function search({
|
export async function search({
|
||||||
query,
|
query,
|
||||||
@ -31,8 +32,19 @@ export async function search({
|
|||||||
timeout?: number;
|
timeout?: number;
|
||||||
}): Promise<SearchResult[]> {
|
}): Promise<SearchResult[]> {
|
||||||
try {
|
try {
|
||||||
|
if (process.env.FIRE_ENGINE_BETA_URL) {
|
||||||
|
const results = await fire_engine_search(query, {
|
||||||
|
numResults: num_results,
|
||||||
|
tbs,
|
||||||
|
filter,
|
||||||
|
lang,
|
||||||
|
country,
|
||||||
|
location,
|
||||||
|
});
|
||||||
|
if (results.length > 0) return results;
|
||||||
|
}
|
||||||
if (process.env.SERPER_API_KEY) {
|
if (process.env.SERPER_API_KEY) {
|
||||||
return await serper_search(query, {
|
const results = await serper_search(query, {
|
||||||
num_results,
|
num_results,
|
||||||
tbs,
|
tbs,
|
||||||
filter,
|
filter,
|
||||||
@ -40,9 +52,10 @@ export async function search({
|
|||||||
country,
|
country,
|
||||||
location,
|
location,
|
||||||
});
|
});
|
||||||
|
if (results.length > 0) return results;
|
||||||
}
|
}
|
||||||
if (process.env.SEARCHAPI_API_KEY) {
|
if (process.env.SEARCHAPI_API_KEY) {
|
||||||
return await searchapi_search(query, {
|
const results = await searchapi_search(query, {
|
||||||
num_results,
|
num_results,
|
||||||
tbs,
|
tbs,
|
||||||
filter,
|
filter,
|
||||||
@ -50,9 +63,10 @@ export async function search({
|
|||||||
country,
|
country,
|
||||||
location,
|
location,
|
||||||
});
|
});
|
||||||
|
if (results.length > 0) return results;
|
||||||
}
|
}
|
||||||
if (process.env.SEARXNG_ENDPOINT) {
|
if (process.env.SEARXNG_ENDPOINT) {
|
||||||
return await searxng_search(query, {
|
const results = await searxng_search(query, {
|
||||||
num_results,
|
num_results,
|
||||||
tbs,
|
tbs,
|
||||||
filter,
|
filter,
|
||||||
@ -60,6 +74,7 @@ export async function search({
|
|||||||
country,
|
country,
|
||||||
location,
|
location,
|
||||||
});
|
});
|
||||||
|
if (results.length > 0) return results;
|
||||||
}
|
}
|
||||||
return await googleSearch(
|
return await googleSearch(
|
||||||
query,
|
query,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user