Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Brotli~=1.1
babel~=2.15
certifi~=2024.8.30
certifi~=2025.1.31
flask-babel~=4.0
flask~=3.0
jinja2~=3.1
Expand Down
24 changes: 13 additions & 11 deletions searx/engines/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# install it manually to use the engine
# pylint: disable=import-error

import psycopg2
import psycopg

engine_type = 'offline'
host = "127.0.0.1"
Expand All @@ -19,7 +19,6 @@
limit = 10
paging = True
result_template = 'key-value.html'
_connection = None


def init(engine_settings):
Expand All @@ -29,21 +28,24 @@ def init(engine_settings):
if not engine_settings['query_str'].lower().startswith('select '):
raise ValueError('only SELECT query is supported')

global _connection
_connection = psycopg2.connect(
database=database,
user=username,
password=password,
host=host,
port=port,

def get_connection():
"""Creates and returns a new connection."""
connection_string = (
f"hostaddr='{host or ''}' "
f"port='{port or ''}' "
f"dbname='{database}' "
f"user='{username}' "
f"password='{password}'"
)
return psycopg.connect(conninfo=connection_string)


def search(query, params):
query_params = {'query': query}
query_to_run = query_str + ' LIMIT {0} OFFSET {1}'.format(limit, (params['pageno'] - 1) * limit)

with _connection:
with get_connection() as _connection:
with _connection.cursor() as cur:
cur.execute(query_to_run, query_params)

Expand All @@ -63,7 +65,7 @@ def _fetch_results(cur):
results.append(result)

# no results to fetch
except psycopg2.ProgrammingError:
except psycopg.ProgrammingError:
pass

return results
2 changes: 1 addition & 1 deletion searx/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ engines:
url: https://thepiratebay.org/
timeout : 3.0

# Required dependency: psychopg2
# Required dependency: psycopg
# - name : postgresql
# engine : postgresql
# database : postgres
Expand Down
Loading