Skip to content

Commit

Permalink
fix: rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
qasimgulzar committed Aug 13, 2024
1 parent 682a6be commit b0f79c0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
6 changes: 3 additions & 3 deletions openedx_search_api/drivers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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)
14 changes: 7 additions & 7 deletions openedx_search_api/drivers/meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
5 changes: 3 additions & 2 deletions openedx_search_api/indexers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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):
Expand All @@ -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)
4 changes: 2 additions & 2 deletions openedx_search_api/management/commands/load_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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', {})
Expand Down
2 changes: 1 addition & 1 deletion openedx_search_api/urls.py
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def is_requirement(line):


setup(
name='django-search',
name='openedx-search',
version='0.0.0',
packages=[
'openedx_search_api',
Expand Down

0 comments on commit b0f79c0

Please sign in to comment.