From 3565f540f893c48339cde2516fddbadff0be218e Mon Sep 17 00:00:00 2001 From: ffont Date: Tue, 16 Apr 2024 15:25:35 +0200 Subject: [PATCH] Add similarity space search option This includes layout improvements, including updates in how facets are defined and sorted --- freesound/settings.py | 28 ++++----- .../bw-frontend/styles/pages/search.scss | 10 +++- search/templatetags/search.py | 12 ++-- search/views.py | 5 +- templates/search/facet.html | 4 +- templates/search/search.html | 59 +++++-------------- templates/search/search_option.html | 6 +- utils/clustering_utilities.py | 2 +- utils/search/search_query_processor.py | 18 +++++- utils/tests/test_search_query_processor.py | 1 + 10 files changed, 69 insertions(+), 76 deletions(-) diff --git a/freesound/settings.py b/freesound/settings.py index f432179ce..7ac6e7297 100644 --- a/freesound/settings.py +++ b/freesound/settings.py @@ -615,24 +615,24 @@ SEARCH_SOUNDS_SORT_DEFAULT = SEARCH_SOUNDS_SORT_OPTION_AUTOMATIC SEARCH_SOUNDS_DEFAULT_FACETS = { - SEARCH_SOUNDS_FIELD_SAMPLERATE: {}, - SEARCH_SOUNDS_FIELD_PACK_GROUPING: {'limit': 10}, - SEARCH_SOUNDS_FIELD_USER_NAME: {'limit': 30}, - SEARCH_SOUNDS_FIELD_TAGS: {'limit': 30}, - SEARCH_SOUNDS_FIELD_BITRATE: {}, - SEARCH_SOUNDS_FIELD_BITDEPTH: {}, + SEARCH_SOUNDS_FIELD_SAMPLERATE: {'sort': 'index asc'}, + 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: {}, + SEARCH_SOUNDS_FIELD_CHANNELS: {'sort': 'index asc'}, SEARCH_SOUNDS_FIELD_LICENSE_NAME: {'limit': 10}, } SEARCH_SOUNDS_BETA_FACETS = { - 'fsdsinet_detected_class': {'limit': 30}, - 'ac_brightness': {'type': 'range', 'start': 0, 'end': 100, 'gap': 20}, - 'ac_depth': {'type': 'range', 'start': 0, 'end': 100, 'gap': 20}, - 'ac_warmth': {'type': 'range', 'start': 0, 'end': 100, 'gap': 20}, - 'ac_hardness': {'type': 'range', 'start': 0, 'end': 100, 'gap': 20}, - 'ac_boominess': {'type': 'range', 'start': 0, 'end': 100, 'gap': 20}, + 'fsdsinet_detected_class': {'limit': 30, 'title': 'FSD-SINet class'}, + 'ac_brightness': {'type': 'range', 'start': 0, 'end': 100, 'gap': 20, 'widget': 'range', 'title': 'Brightness'}, + 'ac_depth': {'type': 'range', 'start': 0, 'end': 100, 'gap': 20, 'widget': 'range', 'title': 'Depth'}, + 'ac_warmth': {'type': 'range', 'start': 0, 'end': 100, 'gap': 20, 'widget': 'range', 'title': 'Warmth'}, + 'ac_hardness': {'type': 'range', 'start': 0, 'end': 100, 'gap': 20, 'widget': 'range', 'title': 'Hardness'}, + 'ac_boominess': {'type': 'range', 'start': 0, 'end': 100, 'gap': 20, 'widget': 'range', 'title': 'Boominess'}, } SEARCH_FORUM_SORT_OPTION_THREAD_DATE_FIRST = "Thread creation (newest first)" @@ -766,8 +766,6 @@ # Timeout for returning clustering results to the user CLUSTERING_TASK_TIMEOUT = 30 -CLUSTERING_SIMILARITY_ANALYZER = FSDSINET_ANALYZER_NAME - # ------------------------------------------------------------------------------- # Rate limiting diff --git a/freesound/static/bw-frontend/styles/pages/search.scss b/freesound/static/bw-frontend/styles/pages/search.scss index cb9021873..2553f604e 100644 --- a/freesound/static/bw-frontend/styles/pages/search.scss +++ b/freesound/static/bw-frontend/styles/pages/search.scss @@ -5,7 +5,8 @@ } .bw-search__filter-tags-list { - margin: 13px 0; + margin-top: $tiny-spacing; + margin-bottom: $small-spacing; } .bw-search__filter-value { @@ -48,6 +49,13 @@ } } +#collapsable-filters { + .bw-search__filter-section { + margin-bottom: $tiny-spacing; + border-bottom: 1px solid $dividers-color; + } +} + .bw-search__player-small { flex: 0 0 120px; } diff --git a/search/templatetags/search.py b/search/templatetags/search.py index 63318fdba..051e09c02 100644 --- a/search/templatetags/search.py +++ b/search/templatetags/search.py @@ -31,15 +31,14 @@ @register.inclusion_tag('search/facet.html', takes_context=True) -def display_facet(context, facet_name, facet_title=None, facet_type='list'): +def display_facet(context, facet_name, facet_title=None): sqp = context['sqp'] facets = context['facets'] - if facet_title is None: - facet_title = facet_name.capitalize() - solr_fieldname = FIELD_NAMES_MAP.get(facet_name, facet_name) - if facet_name in facets: + facet_title = sqp.facets[facet_name].get('title', facet_name.capitalize()) + facet_type = sqp.facets[facet_name].get('widget', 'list') + # If a facet contains a value which is already used in a filter (this can hapen with facets with multiple values like # tags), then we remove it from the list of options so we don't show redundant information facet_values_to_skip = [] @@ -55,7 +54,8 @@ def display_facet(context, facet_name, facet_title=None, facet_type='list'): else: facet = [{'value': value, 'count': count, 'size': -1} for value, count in facets[facet_name]] else: - facet = [] + # Return "empty" data (facet will not be displayed) + return {'type': 'list', 'title': facet_name, 'facet': []} # If the filter is grouping_pack and there are elements which do not contain the character "_" means that # these sounds do not belong to any pack (as grouping pack values should by "packId_packName" if there is a pack diff --git a/search/views.py b/search/views.py index c61f9499e..cc8e1433f 100644 --- a/search/views.py +++ b/search/views.py @@ -91,7 +91,7 @@ def search_view_helper(request): # Run the query and post-process the results try: - query_params = sqp.as_query_params() + query_params = sqp.as_query_params() results, paginator = perform_search_engine_query(query_params) if not sqp.map_mode_active(): if not sqp.display_as_packs_active(): @@ -171,6 +171,7 @@ def search_view_helper(request): 'facets': results.facets, 'non_grouped_number_of_results': results.non_grouped_number_of_results, 'show_beta_search_options': allow_beta_search_features(request), + 'experimental_facets': settings.SEARCH_SOUNDS_BETA_FACETS, } except SearchEngineException as e: @@ -179,7 +180,7 @@ def search_view_helper(request): return {'error_text': 'There was an error while searching, is your query correct?'} except Exception as e: search_logger.info(f'Could probably not connect to Solr - {e}') - sentry_sdk.capture_exception(e) # Manually capture exception so it has mroe info and Sentry can organize it properly + sentry_sdk.capture_exception(e) # Manually capture exception so it has more info and Sentry can organize it properly return {'error_text': 'The search server could not be reached, please try again later.'} diff --git a/templates/search/facet.html b/templates/search/facet.html index e4645e83e..eeeaacdb9 100644 --- a/templates/search/facet.html +++ b/templates/search/facet.html @@ -5,7 +5,7 @@ {% ifequal type "list" %}