Skip to content

Commit

Permalink
Improvements in numeric facets
Browse files Browse the repository at this point in the history
  • Loading branch information
ffont committed Apr 16, 2024
1 parent 5978d64 commit 57b2c27
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 4 additions & 4 deletions freesound/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,14 +615,14 @@
SEARCH_SOUNDS_SORT_DEFAULT = SEARCH_SOUNDS_SORT_OPTION_AUTOMATIC

SEARCH_SOUNDS_DEFAULT_FACETS = {
SEARCH_SOUNDS_FIELD_SAMPLERATE: {'sort': 'index asc'},
SEARCH_SOUNDS_FIELD_SAMPLERATE: {'resort_by_value_as_int': True, 'skip_value_0': True},
SEARCH_SOUNDS_FIELD_BITRATE: {'resort_by_value_as_int': True, 'skip_value_0': True},
SEARCH_SOUNDS_FIELD_BITDEPTH: {'resort_by_value_as_int': True, 'skip_value_0': True},
SEARCH_SOUNDS_FIELD_CHANNELS: {'resort_by_value_as_int': True, 'skip_value_0': True},
SEARCH_SOUNDS_FIELD_PACK_GROUPING: {'limit': 10, 'title': 'Packs'},
SEARCH_SOUNDS_FIELD_USER_NAME: {'limit': 10, 'widget': 'cloud', 'title': 'Users'},
SEARCH_SOUNDS_FIELD_TAGS: {'limit': 30, 'widget': 'cloud'},
SEARCH_SOUNDS_FIELD_BITRATE: {'sort': 'index asc'},
SEARCH_SOUNDS_FIELD_BITDEPTH: {'sort': 'index asc'},
SEARCH_SOUNDS_FIELD_TYPE: {'limit': len(SOUND_TYPE_CHOICES)},
SEARCH_SOUNDS_FIELD_CHANNELS: {'sort': 'index asc'},
SEARCH_SOUNDS_FIELD_LICENSE_NAME: {'limit': 10},
}

Expand Down
12 changes: 10 additions & 2 deletions search/templatetags/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,20 @@ def display_facet(context, facet_name, facet_title=None):
filter_str = f'{solr_fieldname}:[{element["value"]} TO {float(element["value"]) + gap}]'
element['add_filter_url'] = sqp.get_url(add_filters=[filter_str])

# We sort the facets by count. Also, we apply an opacity filter on "could" type facets
if facet:
# We compute weight for the opacity filter on "could" type facets
if facet_type == 'cloud':
max_count = max([element['count'] for element in facet])
for element in facet:
element['weight'] = element['count'] / max_count

# For facets with "resort" option, carry out the sorting based on the value
if sqp.facets[facet_name].get('resort_by_value_as_int', False):
facet = sorted(facet, key=lambda x: int(x['value']))

# Skip value of "0" if indicated
if sqp.facets[facet_name].get('skip_value_0', False):
facet = [f for f in facet if int(f['value']) != 0]

# We also add icons to license facets
if facet_name == 'license':
for element in facet:
Expand Down
2 changes: 1 addition & 1 deletion templates/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ <h3>
{% display_facet "tags"%}
{% endif %}
{% display_facet "type" %}
{% display_facet "samplerate" %}
{% display_facet "channels" %}
{% display_facet "samplerate" %}
{% if not sqp.display_as_packs_active %}
{% display_facet "pack_grouping" %}
{% endif %}
Expand Down

0 comments on commit 57b2c27

Please sign in to comment.