|
25 | 25 | from django.http import Http404, HttpResponsePermanentRedirect, HttpResponseRedirect
|
26 | 26 | from django.shortcuts import render
|
27 | 27 | from django.urls import reverse
|
| 28 | +import sentry_sdk |
28 | 29 |
|
29 | 30 | from search.views import search_view_helper
|
30 | 31 | from tags.models import Tag, FS1Tag
|
| 32 | +from utils.search import SearchEngineException |
31 | 33 | from utils.search.search_sounds import perform_search_engine_query
|
32 | 34 |
|
33 | 35 | search_logger = logging.getLogger("search")
|
@@ -62,18 +64,26 @@ def tags(request, multiple_tags=None):
|
62 | 64 | if 'sqp' in tvars and not tvars['sqp'].get_tags_in_filters():
|
63 | 65 | initial_tagcloud = cache.get('initial_tagcloud')
|
64 | 66 | 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.'}) |
77 | 87 |
|
78 | 88 | return render(request, 'search/search.html', tvars)
|
79 | 89 |
|
|
0 commit comments