Skip to content

Commit

Permalink
🔍 Elasticsearch (#146)
Browse files Browse the repository at this point in the history
* Adds elasticsearch ~ 8.0 python package and updates the PDM lockfile.
* Changes `Collection.introduction` from SearchField to AutocompleteField
* Adds ElasticSearch config to example env vars and to Wagtail settings files.
  * Sets default search backend to use Elasticsearch, but keeps database as search backend for tests.

Also:
* Adds example ENV vars for OV API, AUTH0 and Google to .env.example.
  • Loading branch information
mrharpo authored Jan 5, 2024
1 parent aef7d15 commit 37df19f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,18 @@ OV_DB_USER=postgres
OV_DB_PASSWORD=""

OV_BASE_URL=http://localhost:3000
OV_API_URL=http://localhost:8000/api/v2
OV_ADMIN_BASE_URL=http://localhost:8000
OV_PREVIEW_URL=http://localhost:3000/preview


ES_URL=https://localhost:9200
ES_USER=elastic
ES_PASSWORD=ElasticPassword
ES_VERIFY_CERTS=false

AUTH0_URL=https://dev-woezeiq4zu4qlou1.us.auth0.com
AUTH0_CLIENT_ID=Auth0ClientID
AUTH0_CLIENT_SECRET=Auth0Secret

GOOGLE_CLIENT_ID=yourGoogleClientID.apps.googleusercontent.com
2 changes: 1 addition & 1 deletion ov_collections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Collection(HeadlessMixin, Page):

search_fields: ClassVar[list[index.SearchField]] = [
*Page.search_fields,
index.SearchField('introduction'),
index.AutocompleteField('introduction'),
]

content_panels: ClassVar[list[FieldPanel]] = [
Expand Down
13 changes: 12 additions & 1 deletion ov_wag/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,18 @@
# https://docs.wagtail.io/en/stable/topics/search/backends.html
WAGTAILSEARCH_BACKENDS = {
'default': {
'BACKEND': 'wagtail.search.backends.database',
'BACKEND': 'wagtail.search.backends.elasticsearch8',
'URLS': [os.environ.get('ES_URL', 'https://localhost:9200')],
'INDEX': 'wagtail',
'TIMEOUT': 5,
'OPTIONS': {
'verify_certs': os.environ.get('ES_VERIFY_CERTS', 'true') == 'true',
'basic_auth': [
os.environ.get('ES_USER', 'elastic'),
os.environ.get('ES_PASSWORD'),
],
},
'INDEX_SETTINGS': {},
}
}

Expand Down
1 change: 1 addition & 0 deletions ov_wag/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

WAGTAILSEARCH_BACKENDS = {'default': {'BACKEND': 'wagtail.search.backends.database'}}

with suppress(ImportError):
from .local import * # noqa F403
29 changes: 28 additions & 1 deletion pdm.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies = [
"wagtail-headless-preview~=0.7",
"django-cors-headers~=4.3",
"django-allauth~=0.59",
"elasticsearch~=8.0",
]
requires-python = '>=3.9,<4.0'

Expand Down

0 comments on commit 37df19f

Please sign in to comment.