From b0f79c00e78a188ec08f75ca3351ef1544ed3102 Mon Sep 17 00:00:00 2001 From: qasimgulzar Date: Tue, 13 Aug 2024 20:37:03 +0500 Subject: [PATCH] fix: rename package --- openedx_search_api/drivers/__init__.py | 6 +++--- openedx_search_api/drivers/meilisearch.py | 14 +++++++------- openedx_search_api/indexers/base.py | 5 +++-- .../management/commands/load_indexes.py | 4 ++-- openedx_search_api/urls.py | 2 +- setup.py | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/openedx_search_api/drivers/__init__.py b/openedx_search_api/drivers/__init__.py index 6494f44..c0c5b6a 100644 --- a/openedx_search_api/drivers/__init__.py +++ b/openedx_search_api/drivers/__init__.py @@ -34,7 +34,7 @@ def indexes(self): """ raise NotImplementedError("Method 'indexes' not implemented") - def index(self, index_name, payload): + def index(self, index_name, index_settings): """ Index the provided payload in the specified index. @@ -66,7 +66,7 @@ def get_search_engine(self): return getattr( settings, 'SEARCH_ENGINE', - 'django_search_api.drivers.meilisearch.MeiliSearchEngine' + 'openedx_search_api.drivers.meilisearch.MeiliSearchEngine' ) @classmethod @@ -80,7 +80,7 @@ def get_client(cls, request, *args, **kwargs) -> BaseDriver: search_driver = getattr( settings, 'SEARCH_ENGINE', - 'django_search_api.drivers.meilisearch.MeiliSearchEngine' + 'openedx_search_api.drivers.meilisearch.MeiliSearchEngine' ) klass = import_string(search_driver) return klass.get_instance(request, *args, **kwargs) diff --git a/openedx_search_api/drivers/meilisearch.py b/openedx_search_api/drivers/meilisearch.py index 3a2f253..1c83147 100644 --- a/openedx_search_api/drivers/meilisearch.py +++ b/openedx_search_api/drivers/meilisearch.py @@ -66,7 +66,7 @@ def __init__( meilisearch_master_api_key, expiry_days=7 ): # pylint: disable=too-many-arguments - self.index = None + self._index = None self.api_key_id = meilisearch_api_id self.api_key = meilisearch_api_key self.url = meilisearch_url @@ -160,7 +160,7 @@ def _get_search_rules_class(self, *args, **kwargs) -> BaseIndexConfiguration: index_config = getattr( settings, 'INDEX_CONFIGURATION_CLASS', - 'django_search_api.drivers.meilisearch.BaseIndexConfiguration' + 'openedx_search_api.drivers.meilisearch.BaseIndexConfiguration' ) klass = import_string(index_config) return klass(self.request, *args, **kwargs) @@ -174,14 +174,14 @@ def get_search_rules(self, search_rules=None): rules_instance = self._get_search_rules_class() return rules_instance.get_search_rules(search_rules=search_rules) - def index(self, index_name, _settings=None, options=None): + def index(self, index_name, index_settings=None, options=None): """ Get or create an index in MeiliSearch. """ - self.index = self.client.index(index_name) + self._index = self.client.index(index_name) try: - self.index.fetch_info() + self._index.fetch_info() except errors.MeilisearchApiError: self.client.create_index(index_name, options or {}) - self.index.update_settings(_settings or {}) - return self.index + self._index.update_settings(index_settings or {}) + return self._index diff --git a/openedx_search_api/indexers/base.py b/openedx_search_api/indexers/base.py index 9eab3c6..43e33c7 100644 --- a/openedx_search_api/indexers/base.py +++ b/openedx_search_api/indexers/base.py @@ -12,6 +12,7 @@ class BaseIndexer: """ Base class for indexing documents in MeiliSearch. """ + def __init__(self, index_name: str, queryset: QuerySet, serializer_class: type(Serializer), client: MeiliSearchEngine): """ @@ -36,7 +37,7 @@ def index(self, settings=None, options=None): :return: Response from MeiliSearch add_documents API. """ serializer: Serializer = self.serializer_class(self.queryset, many=True) - index = self.client.index(self.index_name, settings=settings, options=options) + index = self.client.index(self.index_name, index_settings=settings, options=options) return index.add_documents(serializer.data) def index_documents(self, documents: list, settings=None, options=None): @@ -48,5 +49,5 @@ def index_documents(self, documents: list, settings=None, options=None): :param options: Optional options for the index creation. :return: Response from MeiliSearch add_documents API. """ - index = self.client.index(self.index_name, settings=settings, options=options) + index = self.client.index(self.index_name, index_settings=settings, options=options) return index.add_documents(documents) diff --git a/openedx_search_api/management/commands/load_indexes.py b/openedx_search_api/management/commands/load_indexes.py index f8847c0..453a22c 100644 --- a/openedx_search_api/management/commands/load_indexes.py +++ b/openedx_search_api/management/commands/load_indexes.py @@ -11,7 +11,7 @@ from django.utils.module_loading import import_string from rest_framework import serializers -from django_search_api.drivers import DriverFactory # pylint: disable=import-error +from openedx_search_api.drivers import DriverFactory # pylint: disable=import-error log = logging.getLogger(__name__) @@ -56,7 +56,7 @@ def handle(self, *args, **kwargs): # pylint: disable=unused-argument """ client = DriverFactory.get_client(None) indexer_class = getattr( - self, 'INDEXER_CLASS', 'django_search_api.indexers.base.BaseIndexer' + self, 'INDEXER_CLASS', 'openedx_search_api.indexers.base.BaseIndexer' ) klass = import_string(indexer_class) index_configurations = getattr(settings, 'INDEX_CONFIGURATIONS', {}) diff --git a/openedx_search_api/urls.py b/openedx_search_api/urls.py index b951e9f..799e1de 100644 --- a/openedx_search_api/urls.py +++ b/openedx_search_api/urls.py @@ -1,5 +1,5 @@ """ -URL configuration for django_search project. +URL configuration for openedx_search project. The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/5.0/topics/http/urls/ diff --git a/setup.py b/setup.py index 531e9ab..4b9aae4 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ def is_requirement(line): setup( - name='django-search', + name='openedx-search', version='0.0.0', packages=[ 'openedx_search_api',