Skip to content

Commit 8904da9

Browse files
authored
Merge pull request #1824 from MTG/tag-browse-no-solr
Report an error during tag browse if there are no sounds in solr
2 parents 5cbc844 + 6c492c0 commit 8904da9

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

tags/views.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
from django.http import Http404, HttpResponsePermanentRedirect, HttpResponseRedirect
2626
from django.shortcuts import render
2727
from django.urls import reverse
28+
import sentry_sdk
2829

2930
from search.views import search_view_helper
3031
from tags.models import Tag, FS1Tag
32+
from utils.search import SearchEngineException
3133
from utils.search.search_sounds import perform_search_engine_query
3234

3335
search_logger = logging.getLogger("search")
@@ -62,18 +64,26 @@ def tags(request, multiple_tags=None):
6264
if 'sqp' in tvars and not tvars['sqp'].get_tags_in_filters():
6365
initial_tagcloud = cache.get('initial_tagcloud')
6466
if initial_tagcloud is None:
65-
# If tagcloud is not cached, make a query to retrieve it and save it to cache
66-
results, _ = perform_search_engine_query(dict(
67-
textual_query='',
68-
query_filter= "*:*",
69-
num_sounds=1,
70-
facets={settings.SEARCH_SOUNDS_FIELD_TAGS: {'limit': 200}},
71-
group_by_pack=True,
72-
group_counts_as_one_in_facets=False,
73-
))
74-
initial_tagcloud = [dict(name=f[0], count=f[1], browse_url=reverse('tags', args=[f[0]])) for f in results.facets[settings.SEARCH_SOUNDS_FIELD_TAGS]]
75-
cache.set('initial_tagcloud', initial_tagcloud, 60 * 60 * 12) # cache for 12 hours
76-
tvars.update({'initial_tagcloud': initial_tagcloud})
67+
try:
68+
# If tagcloud is not cached, make a query to retrieve it and save it to cache
69+
results, _ = perform_search_engine_query(dict(
70+
textual_query='',
71+
query_filter= "*:*",
72+
num_sounds=1,
73+
facets={settings.SEARCH_SOUNDS_FIELD_TAGS: {'limit': 200}},
74+
group_by_pack=True,
75+
group_counts_as_one_in_facets=False,
76+
))
77+
if settings.SEARCH_SOUNDS_FIELD_TAGS in results.facets:
78+
initial_tagcloud = [dict(name=f[0], count=f[1], browse_url=reverse('tags', args=[f[0]])) for f in results.facets.get(settings.SEARCH_SOUNDS_FIELD_TAGS, [])]
79+
cache.set('initial_tagcloud', initial_tagcloud, 60 * 60 * 12) # cache for 12 hours
80+
tvars.update({'initial_tagcloud': initial_tagcloud})
81+
else:
82+
tvars.update({'error_text': 'There was an error while loading results, please try again later.'})
83+
except SearchEngineException as e:
84+
search_logger.info(f'Tag browse error: Could probably not connect to Solr - {e}')
85+
sentry_sdk.capture_exception(e) # Manually capture exception so it has more info and Sentry can organize it properly
86+
tvars.update({'error_text': 'The search server could not be reached, please try again later.'})
7787

7888
return render(request, 'search/search.html', tvars)
7989

0 commit comments

Comments
 (0)