tags dynamic filters #4 (boost search via ES)
This commit is contained in:
parent
f9fb2aa17e
commit
9f882ca656
|
|
@ -1,6 +1,7 @@
|
||||||
from search_indexes.documents.establishment import EstablishmentDocument
|
from search_indexes.documents.establishment import EstablishmentDocument
|
||||||
from search_indexes.documents.news import NewsDocument
|
from search_indexes.documents.news import NewsDocument
|
||||||
from search_indexes.documents.product import ProductDocument
|
from search_indexes.documents.product import ProductDocument
|
||||||
|
from search_indexes.documents.tag_category import TagCategoryDocument
|
||||||
from search_indexes.tasks import es_update
|
from search_indexes.tasks import es_update
|
||||||
|
|
||||||
# todo: make signal to update documents on related fields
|
# todo: make signal to update documents on related fields
|
||||||
|
|
@ -8,5 +9,6 @@ __all__ = [
|
||||||
'EstablishmentDocument',
|
'EstablishmentDocument',
|
||||||
'NewsDocument',
|
'NewsDocument',
|
||||||
'ProductDocument',
|
'ProductDocument',
|
||||||
|
'TagCategoryDocument',
|
||||||
'es_update',
|
'es_update',
|
||||||
]
|
]
|
||||||
33
apps/search_indexes/documents/tag_category.py
Normal file
33
apps/search_indexes/documents/tag_category.py
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
"""Product app documents."""
|
||||||
|
from django.conf import settings
|
||||||
|
from django_elasticsearch_dsl import Document, Index, fields
|
||||||
|
from tag import models
|
||||||
|
|
||||||
|
TagCategoryIndex = Index(settings.ELASTICSEARCH_INDEX_NAMES.get(__name__, 'tag_category'))
|
||||||
|
TagCategoryIndex.settings(number_of_shards=2, number_of_replicas=2)
|
||||||
|
|
||||||
|
|
||||||
|
@TagCategoryIndex.doc_type
|
||||||
|
class TagCategoryDocument(Document):
|
||||||
|
"""TagCategory document."""
|
||||||
|
|
||||||
|
tags = fields.ListField(fields.ObjectField(
|
||||||
|
properties={
|
||||||
|
'id': fields.IntegerField(),
|
||||||
|
'value': fields.KeywordField(),
|
||||||
|
},
|
||||||
|
))
|
||||||
|
|
||||||
|
class Django:
|
||||||
|
model = models.TagCategory
|
||||||
|
fields = (
|
||||||
|
'id',
|
||||||
|
'index_name',
|
||||||
|
'public',
|
||||||
|
'value_type'
|
||||||
|
)
|
||||||
|
related_models = [models.Tag]
|
||||||
|
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return super().get_queryset().with_base_related()
|
||||||
|
|
@ -4,6 +4,7 @@ from django_elasticsearch_dsl_drf.filter_backends import SearchFilterBackend, \
|
||||||
FacetedSearchFilterBackend, GeoSpatialFilteringFilterBackend
|
FacetedSearchFilterBackend, GeoSpatialFilteringFilterBackend
|
||||||
from search_indexes.utils import OBJECT_FIELD_PROPERTIES
|
from search_indexes.utils import OBJECT_FIELD_PROPERTIES
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
from search_indexes.documents import TagCategoryDocument
|
||||||
from tag.models import TagCategory
|
from tag.models import TagCategory
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -118,9 +119,11 @@ class CustomFacetedSearchFilterBackend(FacetedSearchFilterBackend):
|
||||||
tag_facets = []
|
tag_facets = []
|
||||||
preserve_ids = []
|
preserve_ids = []
|
||||||
facet_name = '_filter_' + __field
|
facet_name = '_filter_' + __field
|
||||||
for category in TagCategory.objects.prefetch_related('tags').filter(public=True,
|
all_tag_categories = TagCategoryDocument.search() \
|
||||||
value_type=TagCategory.LIST):
|
.filter('term', public=True) \
|
||||||
tags_to_remove = list(map(lambda t: str(t.id), category.tags.all()))
|
.filter('term', value_type=TagCategory.LIST)
|
||||||
|
for category in all_tag_categories:
|
||||||
|
tags_to_remove = list(map(lambda t: str(t.id), category.tags))
|
||||||
qs = queryset.__copy__()
|
qs = queryset.__copy__()
|
||||||
qs.query = queryset.query._clone()
|
qs.query = queryset.query._clone()
|
||||||
filterer = make_tags_filter(__facet, tags_to_remove)
|
filterer = make_tags_filter(__facet, tags_to_remove)
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ ELASTICSEARCH_INDEX_NAMES = {
|
||||||
'search_indexes.documents.news': 'development_news',
|
'search_indexes.documents.news': 'development_news',
|
||||||
'search_indexes.documents.establishment': 'development_establishment',
|
'search_indexes.documents.establishment': 'development_establishment',
|
||||||
'search_indexes.documents.product': 'development_product',
|
'search_indexes.documents.product': 'development_product',
|
||||||
|
'search_indexes.documents.tag_category': 'development_tag_category',
|
||||||
}
|
}
|
||||||
|
|
||||||
# ELASTICSEARCH_DSL_AUTOSYNC = False
|
# ELASTICSEARCH_DSL_AUTOSYNC = False
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,7 @@ ELASTICSEARCH_INDEX_NAMES = {
|
||||||
# 'search_indexes.documents.news': 'local_news',
|
# 'search_indexes.documents.news': 'local_news',
|
||||||
'search_indexes.documents.establishment': 'local_establishment',
|
'search_indexes.documents.establishment': 'local_establishment',
|
||||||
'search_indexes.documents.product': 'local_product',
|
'search_indexes.documents.product': 'local_product',
|
||||||
|
'search_indexes.documents.tag_category': 'local_tag_category',
|
||||||
}
|
}
|
||||||
ELASTICSEARCH_DSL_AUTOSYNC = False
|
ELASTICSEARCH_DSL_AUTOSYNC = False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ ELASTICSEARCH_INDEX_NAMES = {
|
||||||
'search_indexes.documents.news': 'development_news', # temporarily disabled
|
'search_indexes.documents.news': 'development_news', # temporarily disabled
|
||||||
'search_indexes.documents.establishment': 'development_establishment',
|
'search_indexes.documents.establishment': 'development_establishment',
|
||||||
'search_indexes.documents.product': 'development_product',
|
'search_indexes.documents.product': 'development_product',
|
||||||
|
'search_indexes.documents.tag_category': 'development_tag_category',
|
||||||
}
|
}
|
||||||
|
|
||||||
sentry_sdk.init(
|
sentry_sdk.init(
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ ELASTICSEARCH_DSL = {
|
||||||
ELASTICSEARCH_INDEX_NAMES = {
|
ELASTICSEARCH_INDEX_NAMES = {
|
||||||
# 'search_indexes.documents.news': 'stage_news', #temporarily disabled
|
# 'search_indexes.documents.news': 'stage_news', #temporarily disabled
|
||||||
'search_indexes.documents.establishment': 'stage_establishment',
|
'search_indexes.documents.establishment': 'stage_establishment',
|
||||||
|
'search_indexes.documents.tag_category': 'stage_tag_category',
|
||||||
}
|
}
|
||||||
|
|
||||||
COOKIE_DOMAIN = '.id-east.ru'
|
COOKIE_DOMAIN = '.id-east.ru'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user