Skip to content

Commit

Permalink
use more intuitive layout for Elasticsearch indices
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed May 5, 2020
1 parent ee76193 commit 257630f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions shop/search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,16 @@ class ProductDocument:
Factory for building an elasticsearch-dsl Document class. This class
"""
def __new__(cls, language=None, settings=None):
index_name_parts = [app_settings.SHOP_APP_LABEL]
if language:
index_name = '{0}.products-{1}'.format(app_settings.SHOP_APP_LABEL, language.lower())
index_name_parts.append(language.lower())
doc_name = 'ProductDocument{}'.format(language.title())
analyzer = body_analyzers.get(language, body_analyzers['default'])
else:
index_name = '{}.products'.format(app_settings.SHOP_APP_LABEL)
doc_name = 'ProductDocument'
analyzer = body_analyzers['default']
products_index = Index(index_name)
index_name_parts.append('products')
products_index = Index('.'.join(index_name_parts))
if settings:
products_index.settings(**settings)
attrs = {'_language': language, 'body': fields.TextField(analyzer=analyzer)}
Expand Down

0 comments on commit 257630f

Please sign in to comment.