diff --git a/config/settings/base.py b/config/settings/base.py index 1a5d177..999c000 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -47,7 +47,7 @@ LOCALE_PATHS = [str(BASE_DIR / "locale")] # ------------------------------------------------------------------------------ # https://docs.djangoproject.com/en/dev/ref/settings/#databases DATABASES = {"default": env.db("DATABASE_URL")} -DATABASES["default"]["ATOMIC_REQUESTS"] = True +DATABASES["default"]["ATOMIC_REQUESTS"] = False # https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" @@ -78,6 +78,7 @@ THIRD_PARTY_APPS = [ "allauth.account", "allauth.mfa", "allauth.socialaccount", + "django_elasticsearch_dsl", ] LOCAL_APPS = [ @@ -289,5 +290,60 @@ SOCIALACCOUNT_FORMS = {"signup": "diarios_oficiais_search_alems.users.forms.User INSTALLED_APPS += ["compressor"] STATICFILES_FINDERS += ["compressor.finders.CompressorFinder"] -# Your stuff... +# Elastic Search # ------------------------------------------------------------------------------ +ELASTICSEARCH_USER = env.str("ELASTICSEARCH_USER") +ELASTICSEARCH_PASSWORD = env.str("ELASTICSEARCH_PASSWORD") + +ELASTICSEARCH_DSL = { + "default": { + "hosts": "http://elasticsearch:9200", + "timeout": 60, + "http_auth": ( + ELASTICSEARCH_USER, + ELASTICSEARCH_PASSWORD, + ), + }, +} +ELASTICSEARCH_HOSTS = "http://elasticsearch:9200" + +ELASTICSEARCH_INDEX_SETTINGS = { + # Define o número de shards (partições) para o índice. + "number_of_shards": 1, + # Define o número de réplicas de cada shard. + "number_of_replicas": 0, + # Configurações de análise do Elasticsearch para processamento do texto + "analysis": { + # Definição de filtros de análise + "filter": { + # Filtro de remoção de stopwords (palavras comuns que não agregam significado) + "portuguese_stop": {"type": "stop", "stopwords": "_portuguese_"}, + # Filtro de stemming para reduzir palavras à sua raiz (ex: "correndo" -> "correr") + "portuguese_stemmer": {"type": "stemmer", "language": "portuguese"}, + # Filtro de sinônimos, carregando um arquivo externo com a lista de sinônimos + "synonym_filter": { + "type": "synonym", + "synonyms_path": "analysis/sinonimos.txt", # Caminho para o arquivo de sinônimos + }, + }, + # Definição de analisadores (combinações de tokenizer e filtros) + "analyzer": { + # Criando um analisador chamado "pt_analyzer" para português + "pt_analyzer": { + # Define o tokenizer como "standard", que quebra o texto em palavras básicas + "tokenizer": "standard", + # Lista de filtros a serem aplicados ao texto após a tokenização + "filter": [ + # Converte todas as palavras para minúsculas + "lowercase", + # Aplica o filtro de remoção de stopwords em português + "portuguese_stop", + # Aplica o filtro de stemming para reduzir palavras à sua raiz + "portuguese_stemmer", + # Aplica o filtro de sinônimos, substituindo palavras por seus sinônimos conforme o arquivo + "synonym_filter", + ], + } + }, + }, +}