Skip to content

Commit

Permalink
update: searxng api: safesearch & language
Browse files Browse the repository at this point in the history
  • Loading branch information
yokingma committed May 5, 2024
1 parent 9b95259 commit 9c85990
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ REFERENCE_COUNT=8
# Whitelist domains, eg. isou.chat,example.org, skip if empty.
WHITELIST_DOMAINS=
# Server Port
PORT=3000
PORT=3000
# SearXNG query options, safesearch: Filter search results, 0: None 1: Moderate 2: Strict.
SEARXNG_SAFE=0
2 changes: 1 addition & 1 deletion searxng/settings.yml.new
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ server:
# If your instance owns a /etc/searxng/settings.yml file, then set the following
# values there.

secret_key: "a7b336b0b3029c3a028582144553cb1eb26c1aeacf202897d92ddcf91510c154" # Is overwritten by ${SEARXNG_SECRET}
secret_key: "ce2b5333aff5738e0a1712bbd1a59050c416f8d1cf3fb6242ed1aee9caa6ec1a" # Is overwritten by ${SEARXNG_SECRET}
# Proxying image results through searx
image_proxy: false
# 1.0 and 1.1 are supported
Expand Down
8 changes: 6 additions & 2 deletions src/search/searxng.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ISearXNGOptions {
q: string;
pageno?: number;
categories?: ESearXNGCategory[];
language?: string;
}

export enum ESearXNGCategory {
Expand All @@ -19,15 +20,18 @@ export enum ESearXNGCategory {

export default async function search(params: ISearXNGOptions): Promise<ISearchResponseResult[]> {
try {
const { q, pageno = 1, categories = [ESearXNGCategory.GENERAL] } = params;
const { q, pageno = 1, categories = [ESearXNGCategory.GENERAL], language = 'all' } = params;
const safesearch = process.env.SEARXNG_SAFE ?? 0;
const res = await httpRequest({
endpoint: `${URL}/search`,
method: 'POST',
query: {
q,
pageno,
categories: categories.join(','),
format: 'json'
format: 'json',
safesearch,
language
}
});
const result = await res.json();
Expand Down

0 comments on commit 9c85990

Please sign in to comment.