diff --git a/common/index.py b/common/index.py index a31bc922..63b607e7 100644 --- a/common/index.py +++ b/common/index.py @@ -8,10 +8,11 @@ from django.db.models.signals import post_save, post_delete # search result translate back to model INDEX_NAME = 'items' INDEX_SEARCHABLE_ATTRIBUTES = ['title', 'orig_title', 'other_title', 'subtitle', 'artist', 'author', 'translator', 'developer', 'brief', 'contents', 'track_list', 'pub_house', 'company', 'publisher', 'isbn', 'imdb_code', 'UPC', 'TMDB_ID', 'BANDCAMP_ALBUM_ID'] -INDEXABLE_DIRECT_TYPES = ['BigAutoField', 'BooleanField', 'CharField', 'DecimalField', 'PositiveIntegerField', 'PositiveSmallIntegerField', 'TextField', 'ArrayField'] +INDEXABLE_DIRECT_TYPES = ['BigAutoField', 'BooleanField', 'CharField', 'PositiveIntegerField', 'PositiveSmallIntegerField', 'TextField', 'ArrayField'] INDEXABLE_TIME_TYPES = ['DateTimeField'] INDEXABLE_DICT_TYPES = ['JSONField'] -# NONINDEXABLE_TYPES = ['ForeignKey', 'FileField'] +INDEXABLE_FLOAT_TYPES = ['DecimalField'] +# NONINDEXABLE_TYPES = ['ForeignKey', 'FileField',] def item_post_save_handler(sender, instance, **kwargs): @@ -52,6 +53,7 @@ class Indexer: model.indexable_fields = ['tags'] model.indexable_fields_time = [] model.indexable_fields_dict = [] + model.indexable_fields_float = [] for field in model._meta.get_fields(): type = field.get_internal_type() if type in INDEXABLE_DIRECT_TYPES: @@ -60,6 +62,8 @@ class Indexer: model.indexable_fields_time.append(field.name) elif type in INDEXABLE_DICT_TYPES: model.indexable_fields_dict.append(field.name) + elif type in INDEXABLE_FLOAT_TYPES: + model.indexable_fields_float.append(field.name) post_save.connect(item_post_save_handler, sender=model) post_delete.connect(item_post_delete_handler, sender=model) @@ -75,6 +79,8 @@ class Indexer: item[field] = getattr(obj, field) for field in obj.__class__.indexable_fields_time: item[field] = getattr(obj, field).timestamp() + for field in obj.__class__.indexable_fields_float: + item[field] = float(getattr(obj, field)) if getattr(obj, field) else None for field in obj.__class__.indexable_fields_dict: d = getattr(obj, field) if d.__class__ is dict: diff --git a/common/models.py b/common/models.py index 0b1ec8d7..9365b336 100644 --- a/common/models.py +++ b/common/models.py @@ -137,12 +137,12 @@ class Entity(models.Model): raise NotImplementedError("Subclass should implement this method.") @property - def tag_list(self): + def all_tag_list(self): return self.get_tags_manager().values('content').annotate(frequency=Count('content')).order_by('-frequency') @property def tags(self): - return list(map(lambda t:t['content'], self.tag_list)) + return list(map(lambda t: t['content'], self.all_tag_list)) @classmethod def get_category_mapping_dict(cls): diff --git a/requirements.txt b/requirements.txt index 562ae082..744ac60d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ django-markdownx django-sass django-rq django-hijack +meilisearch easy-thumbnails lxml openpyxl