diff --git a/shop/__init__.py b/shop/__init__.py index 0a6bbcbb4..2c212332d 100644 --- a/shop/__init__.py +++ b/shop/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals """ See PEP 386 (http://www.python.org/dev/peps/pep-0386/) @@ -17,6 +15,6 @@ 11. git commit -m 'Start with ' 12. git push """ -__version__ = '1.1.1' +__version__ = '1.2.dev' default_app_config = 'shop.apps.ShopConfig' diff --git a/shop/apps.py b/shop/apps.py index 71b41fc33..b2df32ffe 100644 --- a/shop/apps.py +++ b/shop/apps.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.apps import AppConfig from django.utils.translation import ugettext_lazy as _ diff --git a/shop/search/indexes.py b/shop/search/indexes.py index 8a3495567..a7a30e007 100644 --- a/shop/search/indexes.py +++ b/shop/search/indexes.py @@ -1,13 +1,17 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.conf import settings from django.template.loader import select_template from django.utils import translation from django.utils.html import strip_spaces_between_tags from django.utils.safestring import mark_safe from haystack import indexes + +from elasticsearch_dsl import analyzer +from django_elasticsearch_dsl import Document, Index, fields +from django_elasticsearch_dsl.fields import TextField +from django_elasticsearch_dsl.registries import registry + from shop.models.product import ProductModel +from myshop.models import Product, SmartCard class ProductIndex(indexes.SearchIndex): @@ -62,3 +66,46 @@ def index_queryset(self, using=None): else: self.language = settings.LANGUAGE_CODE return self.get_model().objects.indexable() + + +html_strip = analyzer( + 'html_strip', + tokenizer="standard", + filter=["standard", "lowercase", "stop", "snowball"], + char_filter=["html_strip"] +) + + +products = Index('products') +products.settings( + number_of_shards=1, + number_of_replicas=0 +) + +@registry.register_document +@products.document +class ProductDocument(Document): + # product_name = fields.TextField( + # analyzer=html_strip, + # fields={ + # 'raw': fields.TextField(analyzer='keyword'), + # } + # ) + + # product_url = indexes.CharField(stored=True, indexed=False, model_attr='get_absolute_url') + + # description = fields.TextField( + # analyzer=html_strip, + # fields={ + # 'raw': fields.TextField(analyzer='keyword'), + # } + # ) + # class Index: + # # Name of the Elasticsearch index + # name = 'product' + # # See Elasticsearch Indices API reference for available settings + # settings = {'number_of_shards': 1, 'number_of_replicas': 0} + + class Django: + model = ProductModel + fields = ['product_name']