Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ NGOHUB_API_HOST=api.ngohub.ro

# The link checked to verify the NGO Hub app
BASE_WEBSITE="https://redirectioneaza.ro"

# TypeSense settings
TYPESENSE_KEY=test-1234
TYPESENSE_PORT= 8108

16 changes: 16 additions & 0 deletions backend/donations/views/common/search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any

import typesense
from django.conf import settings
from django.contrib.postgres.search import (
SearchQuery,
Expand Down Expand Up @@ -133,6 +134,21 @@ def get_search_results(cls, queryset: QuerySet, query: str, language_code: str)
class CauseSearchMixin(CommonSearchMixin):
@classmethod
def get_search_results(cls, queryset: QuerySet, query: str, language_code: str) -> QuerySet[Cause]:
search_client = typesense.Client(
{
"nodes": [
{
"host": settings.TYPESENSE_HOST,
"port": settings.TYPESENSE_PORT,
"protocol": settings.TYPESENSE_PROTO,
}
],
"api_key": settings.TYPESENSE_KEY,
"connection_timeout_seconds": 2,
}
)
print("TYPESENSE COLLECTIONS:", search_client.collections.retrieve())

if settings.ENABLE_CAUSE_SEARCH_EXACT_MATCH:
query_filter = Q(name__icontains=query)
# If the query looks like a registration number then also try to find the main causes owned by
Expand Down
3 changes: 2 additions & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "redirectioneaza"
version = "3.27.0"
version = "3.2027.0"
description = "A tool to help NGOs with managing the redirection of people's tax income."

requires-python = ">=3.15"
Expand Down Expand Up @@ -35,6 +35,7 @@ dependencies = [
"reportlab~=5.0.0",
"requests~=2.34.0",
"sentry-sdk[django]~=2.72.0",
"typesense~=2.1.0",
"whitenoise~=6.12.0",
]

Expand Down
6 changes: 6 additions & 0 deletions backend/redirectioneaza/settings/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,16 @@
# Feature flags
ENABLE_MULTIPLE_FORMS=(bool, False),
ENABLE_BULK_ANONYMIZATION=(bool, False),
# Auditlog
AUDITLOG_EXPIRY_DAYS=(int, 1 * 365), # 1 year
# Admins
SEED_ADMIN_EMAIL=(str, ""),
DJANGO_ADMIN_EMAIL=(str, ""),
# Search
TYPESENSE_KEY=(str, ""),
TYPESENSE_PORT=(str, "8108"),
TYPESENSE_HOST=(str, "localhost"),
TYPESENSE_PROTO=(str, "http"),
)

environ.Env.read_env(ENV_FILE_PATH)
5 changes: 5 additions & 0 deletions backend/redirectioneaza/settings/feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
ENABLE_CAUSE_SEARCH_WORD_SIMILARITY = env.bool("ENABLE_CAUSE_SEARCH_WORD_SIMILARITY", False)
ENABLE_CAUSE_SEARCH_EXACT_MATCH = env.bool("ENABLE_CAUSE_SEARCH_EXACT_MATCH", True)

TYPESENSE_KEY = env.str("TYPESENSE_KEY", "")
TYPESENSE_PORT = env.str("TYPESENSE_PORT", "8108")
TYPESENSE_HOST = env.str("TYPESENSE_HOST", "localhost")
TYPESENSE_PROTO = env.str("TYPESENSE_PROTO", "http")

# Feature flags
ENABLE_FLAG_CONTACT = env.bool("ENABLE_FLAG_CONTACT", False)
ENABLE_MULTIPLE_FORMS = env.bool("ENABLE_MULTIPLE_FORMS", True)
Expand Down
72 changes: 68 additions & 4 deletions backend/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions docker-compose.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ services:
- .env
environment:
- "PYTHONUNBUFFERED=1"

typesense_base:
image: typesense/typesense:30.2
restart: on-failure
ports:
- "${TYPESENSE_PORT:-8108}:8108"
volumes:
- redirect_typesense:/data
command: '--data-dir /data --api-key=${TYPESENSE_KEY} --thread-pool-size=8'

db_base:
container_name: redirect_db_dev
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ services:
depends_on:
- db

typesense:
extends:
file: docker-compose.base.yml
service: typesense_base
container_name: redirect_typesense

db:
extends:
file: docker-compose.base.yml
service: db_base_psql
container_name: redirect_psql

volumes:
redirect_typesense:
redirect_psql:
node_modules:
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ services:
cpus: "2"
mem_limit: "4g"

typesense_dev:
extends:
file: docker-compose.base.yml
service: typesense_base

db_psql_dev:
extends:
file: docker-compose.base.yml
Expand All @@ -23,4 +28,5 @@ services:

volumes:
redirect_psql:
redirect_typesense:
node_modules:
Loading