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

feat: added meilisearch dependency and fixt index creation #4381

Closed
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
30 changes: 30 additions & 0 deletions course_discovery/apps/course_metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from django_elasticsearch_dsl.registries import registry
from django_extensions.db.fields import AutoSlugField
from django_extensions.db.models import TimeStampedModel
from django_meili.models import IndexMixin
from edx_django_utils.cache import RequestCache, get_cache_key
from elasticsearch.exceptions import RequestError
from elasticsearch_dsl.query import Q as ESDSLQ
Expand Down Expand Up @@ -4604,3 +4605,32 @@ class RestrictedCourseRun(DraftModelMixin, TimeStampedModel):

def __str__(self):
return f"{self.course_run.key}: <{self.restriction_type}>"

if settings.MEILISEARCH_ENABLED:
class CourseProxy(IndexMixin, Course):
class MeiliMeta:
index_name = "Course"
filterable_fields = ("title",)
searchable_fields = ("uuid", "title")
displayed_fields = ("uuid", "title")
index_name = "course"

class Meta:
proxy = True


class PersonProxy(IndexMixin, Person):
class MeiliMeta:
index_name = "person"

class Meta:
proxy = True


class CourseRunProxy(IndexMixin, CourseRun):
class MeiliMeta:
index_name = "course_run"
primary_key = "uuid"

class Meta:
proxy = True
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def _update(self, models, options):
for document in registry.get_documents(models):
# pylint: disable=protected-access
index = document._index
record_count = self.get_record_count(document)
alias, new_index_name = self.prepare_backend_index(index)
record_count = self.get_record_count(document)
alias_mappings.append(AliasMapper(document, index, new_index_name, alias, record_count))
# Set the alias (from settings) to the timestamped catalog.
run_attempts = 0
Expand Down
18 changes: 18 additions & 0 deletions course_discovery/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
'nested_admin',
'openedx_events',
'multi_email_field',
'django_meili',
]

ALGOLIA = {
Expand Down Expand Up @@ -787,3 +788,20 @@
)

ENABLE_COURSE_REVIEWS_ADMIN = False

################### Studio Search (beta), using Meilisearch ###################
MEILISEARCH_ENABLED = False
if MEILISEARCH_ENABLED:
MEILISEARCH = {
'HTTPS': False, # Whether HTTPS is enabled for the meilisearch server
'HOST': 'meilisearch', # The host for the meilisearch server
'MASTER_KEY': 'masterKey',
# The master key for meilisearch. See https://www.meilisearch.com/docs/learn/security/basic_security for more detail

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should recommend using the master key for this sort of thing.

'PORT': 7700, # The port for the meilisearch server
'TIMEOUT': None, # The timeout to wait for when using sync meilisearch server
'CLIENT_AGENTS': None, # The client agents for the meilisearch server
'DEBUG': DEBUG, # Whether to throw exceptions on failed creation of documents
'SYNC': False,
# Whether to execute operations to meilisearch in a synchronous manner (waiting for each rather than letting the task queue operate)
'OFFLINE': False, # Whether to make any http requests for the application.
}
1 change: 1 addition & 0 deletions requirements/production.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ newrelic
python-memcached
pymemcache
PyYAML
django-meili==0.0.6
59 changes: 27 additions & 32 deletions requirements/production.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.8
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --output-file=requirements/production.txt requirements/production.in
Expand All @@ -19,40 +19,31 @@ algoliasearch-django==1.7.3
# -r requirements/base.in
amqp==5.2.0
# via kombu
annotated-types==0.7.0
# via pydantic
asgiref==3.8.1
# via
# django
# django-cors-headers
# django-countries
asn1crypto==1.5.1
# via snowflake-connector-python
async-timeout==4.0.3
# via
# aiohttp
# redis
attrs==23.2.0
# via
# aiohttp
# openedx-events
# zeep
backoff==2.2.1
# via -r requirements/base.in
backports-zoneinfo[tzdata]==0.2.1 ; python_version < "3.9"
# via
# -c requirements/constraints.txt
# celery
# django
# djangorestframework
# kombu
beautifulsoup4==4.12.3
# via
# -r requirements/base.in
# taxonomy-connector
billiard==4.2.0
# via celery
boto3==1.34.136
boto3==1.34.139
# via django-ses
botocore==1.34.136
botocore==1.34.139
# via
# boto3
# s3transfer
Expand All @@ -64,11 +55,13 @@ cairocffi==1.4.0
# cairosvg
cairosvg==2.7.1
# via -r requirements/base.in
camel-converter[pydantic]==3.1.2
# via meilisearch
celery==5.4.0
# via
# -c requirements/constraints.txt
# taxonomy-connector
certifi==2024.6.2
certifi==2024.7.4
# via
# -r requirements/production.in
# elasticsearch
Expand Down Expand Up @@ -100,7 +93,7 @@ click-repl==0.3.0
# via celery
code-annotations==1.8.0
# via edx-toggles
contentful==2.1.1
contentful==2.2.0
# via -r requirements/base.in
cryptography==42.0.8
# via
Expand Down Expand Up @@ -136,6 +129,7 @@ django==4.2.13
# django-filter
# django-guardian
# django-localflavor
# django-meili
# django-model-utils
# django-multi-email-field
# django-multiselectfield
Expand Down Expand Up @@ -215,11 +209,13 @@ django-libsass==0.9
# via -r requirements/base.in
django-localflavor==4.0
# via -r requirements/base.in
django-meili==0.0.6
# via -r requirements/production.in
django-model-utils==4.5.1
# via taxonomy-connector
django-multi-email-field==0.7.0
# via -r requirements/base.in
django-multiselectfield==0.1.12
django-multiselectfield==0.1.13
# via -r requirements/base.in
django-nested-admin==4.0.2
# via -r requirements/base.in
Expand All @@ -237,7 +233,7 @@ django-ses==4.1.0
# taxonomy-connector
django-simple-history==3.7.0
# via -r requirements/base.in
django-solo==2.2.0
django-solo==2.3.0
# via
# -r requirements/base.in
# taxonomy-connector
Expand Down Expand Up @@ -365,9 +361,9 @@ gevent==24.2.1
# via -r requirements/production.in
google-api-core==2.19.1
# via google-api-python-client
google-api-python-client==2.135.0
google-api-python-client==2.136.0
# via -r requirements/base.in
google-auth==2.30.0
google-auth==2.31.0
# via
# google-api-core
# google-api-python-client
Expand Down Expand Up @@ -403,9 +399,6 @@ importlib-metadata==6.11.0
# via
# -c requirements/common_constraints.txt
# -r requirements/base.in
# markdown
importlib-resources==6.4.0
# via pycountry
inflection==0.5.1
# via drf-yasg
isodate==0.6.1
Expand Down Expand Up @@ -433,6 +426,8 @@ markdown==3.6
# via -r requirements/base.in
markupsafe==2.1.5
# via jinja2
meilisearch==0.31.3
# via django-meili
more-itertools==10.3.0
# via simple-salesforce
multidict==6.0.5
Expand Down Expand Up @@ -500,6 +495,10 @@ pycountry==24.6.1
# via -r requirements/base.in
pycparser==2.22
# via cffi
pydantic==2.8.2
# via camel-converter
pydantic-core==2.20.1
# via pydantic
pyjwt[crypto]==2.8.0
# via
# drf-jwt
Expand Down Expand Up @@ -568,6 +567,7 @@ requests==2.32.3
# edx-drf-extensions
# edx-rest-api-client
# google-api-core
# meilisearch
# openai
# requests-file
# requests-oauthlib
Expand Down Expand Up @@ -646,16 +646,14 @@ tqdm==4.66.4
# via openai
typing-extensions==4.12.2
# via
# asgiref
# django-countries
# edx-opaque-keys
# kombu
# pydantic
# pydantic-core
# simple-salesforce
# snowflake-connector-python
tzdata==2024.1
# via
# backports-zoneinfo
# celery
# via celery
unicodecsv==0.14.1
# via -r requirements/base.in
uritemplate==4.1.1
Expand All @@ -667,7 +665,6 @@ urllib3==1.26.19
# botocore
# elasticsearch
# requests
# snowflake-connector-python
vine==5.1.0
# via
# amqp
Expand All @@ -688,9 +685,7 @@ yarl==1.9.4
zeep==4.2.1
# via simple-salesforce
zipp==3.19.2
# via
# importlib-metadata
# importlib-resources
# via importlib-metadata
zope-event==5.0
# via gevent
zope-interface==6.4.post2
Expand Down
Loading