From 74460b30600b00c532c11eda02f2dcd92d0e094d Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Thu, 10 Oct 2019 14:28:42 +0300 Subject: [PATCH 1/3] Fix imports issue --- apps/establishment/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/establishment/models.py b/apps/establishment/models.py index 5c2a0ff0..690eb8a2 100644 --- a/apps/establishment/models.py +++ b/apps/establishment/models.py @@ -11,7 +11,7 @@ from django.db import models from django.db.models import When, Case, F, ExpressionWrapper, Subquery, Q from django.utils import timezone from django.utils.translation import gettext_lazy as _ -from elasticsearch_dsl import Q +from elasticsearch_dsl import Q as Elastic_Q from phonenumber_field.modelfields import PhoneNumberField from collection.models import Collection @@ -103,8 +103,8 @@ class EstablishmentQuerySet(models.QuerySet): """Search text via ElasticSearch.""" from search_indexes.documents import EstablishmentDocument search = EstablishmentDocument.search().filter( - Q('match', name=value) | - Q('match', **{f'description.{locale}': value}) + Elastic_Q('match', name=value) | + Elastic_Q('match', **{f'description.{locale}': value}) ).execute() ids = [result.meta.id for result in search] return self.filter(id__in=ids) From 2aa51b93d3d2b72ab72e9cbb40ad3192cd153e29 Mon Sep 17 00:00:00 2001 From: evgeniy-st Date: Thu, 10 Oct 2019 14:42:42 +0300 Subject: [PATCH 2/3] hide es search --- apps/establishment/models.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/apps/establishment/models.py b/apps/establishment/models.py index 690eb8a2..5290f368 100644 --- a/apps/establishment/models.py +++ b/apps/establishment/models.py @@ -11,7 +11,6 @@ from django.db import models from django.db.models import When, Case, F, ExpressionWrapper, Subquery, Q from django.utils import timezone from django.utils.translation import gettext_lazy as _ -from elasticsearch_dsl import Q as Elastic_Q from phonenumber_field.modelfields import PhoneNumberField from collection.models import Collection @@ -99,15 +98,15 @@ class EstablishmentQuerySet(models.QuerySet): else: return self.none() - def es_search(self, value, locale=None): - """Search text via ElasticSearch.""" - from search_indexes.documents import EstablishmentDocument - search = EstablishmentDocument.search().filter( - Elastic_Q('match', name=value) | - Elastic_Q('match', **{f'description.{locale}': value}) - ).execute() - ids = [result.meta.id for result in search] - return self.filter(id__in=ids) + # def es_search(self, value, locale=None): + # """Search text via ElasticSearch.""" + # from search_indexes.documents import EstablishmentDocument + # search = EstablishmentDocument.search().filter( + # Elastic_Q('match', name=value) | + # Elastic_Q('match', **{f'description.{locale}': value}) + # ).execute() + # ids = [result.meta.id for result in search] + # return self.filter(id__in=ids) def by_country_code(self, code): """Return establishments by country code""" From a25d8460285a4f4e78e3fc66005f4b044b16f4c4 Mon Sep 17 00:00:00 2001 From: Anatoly Date: Thu, 10 Oct 2019 21:02:56 +0300 Subject: [PATCH 3/3] fixed bug with duplicated records in similar establishments --- apps/establishment/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/establishment/models.py b/apps/establishment/models.py index 5290f368..1ff82e72 100644 --- a/apps/establishment/models.py +++ b/apps/establishment/models.py @@ -14,8 +14,8 @@ from django.utils.translation import gettext_lazy as _ from phonenumber_field.modelfields import PhoneNumberField from collection.models import Collection -from main.models import Award, MetaDataContent from location.models import Address +from main.models import Award, MetaDataContent from review.models import Review from utils.models import (ProjectBaseMixin, TJSONField, URLImageMixin, TranslatedFieldsMixin, BaseAttributes) @@ -180,7 +180,8 @@ class EstablishmentQuerySet(models.QuerySet): return self.filter(id__in=subquery_filter_by_distance) \ .annotate_intermediate_public_mark() \ .annotate_mark_similarity(mark=establishment.public_mark) \ - .order_by('mark_similarity') + .order_by('mark_similarity') \ + .distinct('mark_similarity', 'id') else: return self.none()