Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CMD-176 conditional elastic search #857

Merged
merged 16 commits into from
Aug 8, 2024
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
7 changes: 7 additions & 0 deletions docs/upgrade-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@

## from v4.N to v4.14

- [Rename `PORTAL_ES_ENABLED` Setting](#rename-portal_es_enabled-settings)
- [Upgrade Docker Compose](#upgrade-docker-compose)

### Rename `PORTAL_ES_ENABLED` Setting

| from | to |
| - | - |
| `PORTAL_ES_ENABLED` | `PORTAL_SEARCH_INDEX_IS_AUTOMATIC` |

### Upgrade Docker Compose

Update to _at least_ the latest Docker Compose v2.
Expand Down
72 changes: 29 additions & 43 deletions taccsite_cms/_settings/search.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,38 @@
"""Configure search plugins"""
"""Configure deprecated search solution"""

########################
# TACC: SEARCH
# SEARCH
########################

PORTAL_ES_ENABLED = True

# To support any search
PORTAL_SEARCH_PATH = '/search'

if PORTAL_ES_ENABLED:
# Elasticsearch
PORTAL_SEARCH_QUERY_PARAM_NAME = 'query_string'
else:
# Google
PORTAL_SEARCH_QUERY_PARAM_NAME = 'q'

########################
# ELASTICSEARCH
########################

if PORTAL_ES_ENABLED:
ES_AUTH = 'username:password'
ES_HOSTS = 'http://elasticsearch:9200'
ES_INDEX_PREFIX = 'cms-dev-{}'
ES_DOMAIN = 'http://localhost:8000'

# Elasticsearch Indexing
HAYSTACK_ROUTERS = ['aldryn_search.router.LanguageRouter', ]
HAYSTACK_SIGNAL_PROCESSOR = 'taccsite_cms.signal_processor.RealtimeSignalProcessor'
ALDRYN_SEARCH_DEFAULT_LANGUAGE = 'en'
ALDRYN_SEARCH_REGISTER_APPHOOK = True
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': ES_HOSTS,
'INDEX_NAME': ES_INDEX_PREFIX.format('cms'),
'KWARGS': {'http_auth': ES_AUTH}
}
# To support Google search
# PORTAL_SEARCH_QUERY_PARAM_NAME = 'q'
# PORTAL_SEARCH_INDEX_IS_AUTOMATIC = False

# To support Elasticsearch
PORTAL_SEARCH_QUERY_PARAM_NAME = 'query_string'
PORTAL_SEARCH_INDEX_IS_AUTOMATIC = True

ES_AUTH = 'username:password'
ES_HOSTS = 'http://elasticsearch:9200'
ES_INDEX_PREFIX = 'cms-dev-{}'
ES_DOMAIN = 'http://localhost:8000'

HAYSTACK_ROUTERS = ['aldryn_search.router.LanguageRouter', ]
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': ES_HOSTS,
'INDEX_NAME': ES_INDEX_PREFIX.format('cms'),
'KWARGS': {'http_auth': ES_AUTH}
}
}

########################
# DJANGO CMS
########################
ALDRYN_SEARCH_DEFAULT_LANGUAGE = 'en'
ALDRYN_SEARCH_REGISTER_APPHOOK = True

if PORTAL_ES_ENABLED:
_INSTALLED_APPS = [
'haystack', # search index
'aldryn_apphooks_config', # search index & django CMS Blog
]
else:
_INSTALLED_APPS = []
_INSTALLED_APPS = [
'haystack', # search index
]
13 changes: 12 additions & 1 deletion taccsite_cms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def gettext(s): return s
] + search_INSTALLED_APPS + [

# miscellaneous
'aldryn_apphooks_config', # search index & django CMS Blog
'test_without_migrations', # run tests faster

] + form_plugin_INSTALLED_APPS + [
Expand Down Expand Up @@ -723,6 +724,8 @@ def get_subdirs_as_module_names(path):
(CORTAL_ICONS, 'icon', _('TACC "Cortal" Icons')),
]



########################
# SETTINGS IMPORT
########################
Expand Down Expand Up @@ -754,8 +757,9 @@ def get_subdirs_as_module_names(path):

########################
# SETTINGS DEPRECATED
########################
# TODO: Make clients not use nor set these
########################

deprecated_SETTINGS_EXPORT = []

# For header_branding.html
Expand Down Expand Up @@ -801,6 +805,13 @@ def get_subdirs_as_module_names(path):
if 'INCLUDES_SEARCH_BAR' == old_setting_name:
PORTAL_HAS_SEARCH = INCLUDES_SEARCH_BAR

########################
# SETTINGS CONDITIONAL
########################

if PORTAL_SEARCH_INDEX_IS_AUTOMATIC:
HAYSTACK_SIGNAL_PROCESSOR = 'taccsite_cms.signal_processor.RealtimeSignalProcessor'

########################
# SETTINGS EXPORT
########################
Expand Down
11 changes: 11 additions & 0 deletions taccsite_cms/settings_custom.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@
"img_file_src": "https://cdn.jsdelivr.net/gh/TACC/Core-CMS-Custom@813aa7c/ptdatax_assets/favicon.ico",
}

########################
# SEARCH
########################

# To support Google search
PORTAL_SEARCH_QUERY_PARAM_NAME = 'q'

# To disable Elasticsearch
PORTAL_SEARCH_INDEX_IS_AUTOMATIC = False

########################
# DJANGOCMS_BLOG
########################
Expand All @@ -143,6 +153,7 @@

tacc_app_index = INSTALLED_APPS.index('taccsite_cms')
INSTALLED_APPS[tacc_app_index:tacc_app_index] = [
# 'aldryn_apphooks_config' # already in Core
# 'filer', # already in Core
# 'easy_thumbnails', # already in Core
'parler',
Expand Down