We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[beta][v23] Erreur 500 via opensearch
Bonjour,

**Lien incriminé** : https://beta.zestedesavoir.com/rechercher/opensearch.xml

**Problème** : j'ai une erreur 500 en allant sur cette url.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `zds/searchv2/views.py`
Content:
```
1 # coding: utf-8
2 import operator
3 
4 from elasticsearch_dsl import Search
5 from elasticsearch_dsl.query import Match, MultiMatch, FunctionScore, Term, Terms, Range
6 
7 from django.conf import settings
8 from django.core.exceptions import PermissionDenied
9 from django.contrib import messages
10 from django.utils.translation import ugettext_lazy as _
11 from django.shortcuts import render
12 from django.core.urlresolvers import reverse
13 
14 from zds.searchv2.forms import SearchForm
15 from zds.searchv2.models import ESIndexManager
16 from zds.utils.paginator import ZdSPagingListView
17 from zds.forum.models import Forum
18 
19 
20 class SearchView(ZdSPagingListView):
21     """Research view
22     """
23 
24     template_name = 'searchv2/search.html'
25     paginate_by = settings.ZDS_APP['search']['results_per_page']
26 
27     search_form_class = SearchForm
28     search_form = None
29     search_query = None
30 
31     authorized_forums = ''
32 
33     index_manager = None
34 
35     def __init__(self, **kwargs):
36         """Overridden because index manager must NOT be initialized elsewhere
37         """
38 
39         super(SearchView, self).__init__(**kwargs)
40         self.index_manager = ESIndexManager(**settings.ES_SEARCH_INDEX)
41 
42     def get(self, request, *args, **kwargs):
43         """Overridden to catch the request and fill the form.
44         """
45 
46         if 'q' in request.GET:
47             self.search_query = ''.join(request.GET['q'])
48 
49         self.search_form = self.search_form_class(data=self.request.GET)
50 
51         if self.search_query and not self.search_form.is_valid():
52             raise PermissionDenied('research form is invalid')
53 
54         return super(SearchView, self).get(request, *args, **kwargs)
55 
56     def get_queryset(self):
57         if not self.index_manager.connected_to_es:
58             messages.warning(self.request, _(u'Impossible de se connecter à Elasticsearch'))
59             return []
60 
61         if self.search_query:
62 
63             # find forums the user is allowed to visit
64             user = self.request.user
65 
66             forums_pub = Forum.objects.filter(group__isnull=True).all()
67             if user and user.is_authenticated():
68                 forums_private = Forum \
69                     .objects \
70                     .filter(group__isnull=False, group__in=user.groups.all()) \
71                     .all()
72                 list_forums = list(forums_pub | forums_private)
73             else:
74                 list_forums = list(forums_pub)
75 
76             self.authorized_forums = [f.pk for f in list_forums]
77 
78             search_queryset = Search()
79 
80             # setting the different querysets (according to the selected models, if any)
81             part_querysets = []
82             chosen_groups = self.search_form.cleaned_data['models']
83 
84             if chosen_groups:
85                 models = []
86                 for group in chosen_groups:
87                     if group in settings.ZDS_APP['search']['search_groups']:
88                         models.append(settings.ZDS_APP['search']['search_groups'][group][1])
89             else:
90                 models = [v[1] for k, v in settings.ZDS_APP['search']['search_groups'].iteritems()]
91 
92             models = reduce(operator.concat, models)
93 
94             for model in models:
95                 part_querysets.append(getattr(self, 'get_queryset_{}s'.format(model))())
96 
97             queryset = part_querysets[0]
98             for query in part_querysets[1:]:
99                 queryset |= query
100 
101             # weighting:
102             weight_functions = []
103             for _type, weights in settings.ZDS_APP['search']['boosts'].items():
104                 if _type in models:
105                     weight_functions.append({'filter': Match(_type=_type), 'weight': weights['global']})
106 
107             scored_queryset = FunctionScore(query=queryset, boost_mode='multiply', functions=weight_functions)
108             search_queryset = search_queryset.query(scored_queryset)
109 
110             # highlighting:
111             search_queryset = search_queryset.highlight_options(
112                 fragment_size=150, number_of_fragments=5, pre_tags=['[hl]'], post_tags=['[/hl]'])
113             search_queryset = search_queryset.highlight('text').highlight('text_html')
114 
115             # executing:
116             return self.index_manager.setup_search(search_queryset)
117 
118         return []
119 
120     def get_queryset_publishedcontents(self):
121         """Find in PublishedContents.
122         """
123 
124         query = Match(_type='publishedcontent') \
125             & MultiMatch(query=self.search_query, fields=['title', 'description', 'categories', 'tags', 'text'])
126 
127         functions_score = [
128             {
129                 'filter': Match(content_type='TUTORIAL'),
130                 'weight': settings.ZDS_APP['search']['boosts']['publishedcontent']['if_tutorial']
131             },
132             {
133                 'filter': Match(content_type='ARTICLE'),
134                 'weight': settings.ZDS_APP['search']['boosts']['publishedcontent']['if_article']
135             },
136         ]
137 
138         scored_query = FunctionScore(query=query, boost_mode='multiply', functions=functions_score)
139 
140         return scored_query
141 
142     def get_queryset_chapters(self):
143         """Find in chapters.
144         """
145 
146         query = Match(_type='chapter') \
147             & MultiMatch(query=self.search_query, fields=['title', 'text'])
148 
149         return query
150 
151     def get_queryset_topics(self):
152         """Find in topics, and remove result if the forum is not allowed for the user.
153 
154         Score is modified if :
155 
156         + topic is solved ;
157         + Topic is sticky ;
158         + Topic is locked.
159 
160         """
161 
162         query = Match(_type='topic') \
163             & Terms(forum_pk=self.authorized_forums) \
164             & MultiMatch(query=self.search_query, fields=['title', 'subtitle', 'tags'])
165 
166         functions_score = [
167             {'filter': Match(is_solved=True), 'weight': settings.ZDS_APP['search']['boosts']['topic']['if_solved']},
168             {'filter': Match(is_sticky=True), 'weight': settings.ZDS_APP['search']['boosts']['topic']['if_sticky']},
169             {'filter': Match(is_locked=True), 'weight': settings.ZDS_APP['search']['boosts']['topic']['if_locked']}
170         ]
171 
172         scored_query = FunctionScore(query=query, boost_mode='multiply', functions=functions_score)
173 
174         return scored_query
175 
176     def get_queryset_posts(self):
177         """Find in posts, and remove result if the forum is not allowed for the user or if the message is invisible.
178 
179         Score is modified if :
180 
181         + Post is the first one in a topic ;
182         + Post is marked as "useful" ;
183         + Post has a like/dislike ratio above (more like than dislike) or below (the other way around) 1.0.
184         """
185 
186         query = Match(_type='post') \
187             & Terms(forum_pk=self.authorized_forums) \
188             & Term(is_visible=True) \
189             & MultiMatch(query=self.search_query, fields=['text_html'])
190 
191         functions_score = [
192             {'filter': Match(position=1), 'weight': settings.ZDS_APP['search']['boosts']['post']['if_first']},
193             {'filter': Match(is_useful=True), 'weight': settings.ZDS_APP['search']['boosts']['post']['if_useful']},
194             {
195                 'filter': Range(like_dislike_ratio={'gt': 1}),
196                 'weight': settings.ZDS_APP['search']['boosts']['post']['ld_ratio_above_1']
197             },
198             {
199                 'filter': Range(like_dislike_ratio={'lt': 1}),
200                 'weight': settings.ZDS_APP['search']['boosts']['post']['ld_ratio_below_1']
201             }
202         ]
203 
204         scored_query = FunctionScore(query=query, boost_mode='multiply', functions=functions_score)
205 
206         return scored_query
207 
208     def get_context_data(self, **kwargs):
209         context = super(SearchView, self).get_context_data(**kwargs)
210         context['form'] = self.search_form
211         context['query'] = self.search_query is not None
212 
213         return context
214 
215 
216 def opensearch(request):
217     """Generate OpenSearch Description file"""
218 
219     return render(request, 'search/opensearch.xml', {
220         'site_name': settings.ZDS_APP['site']['litteral_name'],
221         'site_url': settings.ZDS_APP['site']['url'],
222         'email_contact': settings.ZDS_APP['site']['email_contact'],
223         'language': settings.LANGUAGE_CODE,
224         'search_url': settings.ZDS_APP['site']['url'] + reverse('search:query')
225     }, content_type='application/opensearchdescription+xml')
226
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/zds/searchv2/views.py b/zds/searchv2/views.py
--- a/zds/searchv2/views.py
+++ b/zds/searchv2/views.py
@@ -216,7 +216,7 @@
 def opensearch(request):
     """Generate OpenSearch Description file"""
 
-    return render(request, 'search/opensearch.xml', {
+    return render(request, 'searchv2/opensearch.xml', {
         'site_name': settings.ZDS_APP['site']['litteral_name'],
         'site_url': settings.ZDS_APP['site']['url'],
         'email_contact': settings.ZDS_APP['site']['email_contact'],

{"golden_diff": "diff --git a/zds/searchv2/views.py b/zds/searchv2/views.py\n--- a/zds/searchv2/views.py\n+++ b/zds/searchv2/views.py\n@@ -216,7 +216,7 @@\n def opensearch(request):\n     \"\"\"Generate OpenSearch Description file\"\"\"\n \n-    return render(request, 'search/opensearch.xml', {\n+    return render(request, 'searchv2/opensearch.xml', {\n         'site_name': settings.ZDS_APP['site']['litteral_name'],\n         'site_url': settings.ZDS_APP['site']['url'],\n         'email_contact': settings.ZDS_APP['site']['email_contact'],\n", "issue": "[beta][v23] Erreur 500 via opensearch\nBonjour,\r\n\r\n**Lien incrimin\u00e9** : https://beta.zestedesavoir.com/rechercher/opensearch.xml\r\n\r\n**Probl\u00e8me** : j'ai une erreur 500 en allant sur cette url.\n", "before_files": [{"content": "# coding: utf-8\nimport operator\n\nfrom elasticsearch_dsl import Search\nfrom elasticsearch_dsl.query import Match, MultiMatch, FunctionScore, Term, Terms, Range\n\nfrom django.conf import settings\nfrom django.core.exceptions import PermissionDenied\nfrom django.contrib import messages\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.shortcuts import render\nfrom django.core.urlresolvers import reverse\n\nfrom zds.searchv2.forms import SearchForm\nfrom zds.searchv2.models import ESIndexManager\nfrom zds.utils.paginator import ZdSPagingListView\nfrom zds.forum.models import Forum\n\n\nclass SearchView(ZdSPagingListView):\n    \"\"\"Research view\n    \"\"\"\n\n    template_name = 'searchv2/search.html'\n    paginate_by = settings.ZDS_APP['search']['results_per_page']\n\n    search_form_class = SearchForm\n    search_form = None\n    search_query = None\n\n    authorized_forums = ''\n\n    index_manager = None\n\n    def __init__(self, **kwargs):\n        \"\"\"Overridden because index manager must NOT be initialized elsewhere\n        \"\"\"\n\n        super(SearchView, self).__init__(**kwargs)\n        self.index_manager = ESIndexManager(**settings.ES_SEARCH_INDEX)\n\n    def get(self, request, *args, **kwargs):\n        \"\"\"Overridden to catch the request and fill the form.\n        \"\"\"\n\n        if 'q' in request.GET:\n            self.search_query = ''.join(request.GET['q'])\n\n        self.search_form = self.search_form_class(data=self.request.GET)\n\n        if self.search_query and not self.search_form.is_valid():\n            raise PermissionDenied('research form is invalid')\n\n        return super(SearchView, self).get(request, *args, **kwargs)\n\n    def get_queryset(self):\n        if not self.index_manager.connected_to_es:\n            messages.warning(self.request, _(u'Impossible de se connecter \u00e0 Elasticsearch'))\n            return []\n\n        if self.search_query:\n\n            # find forums the user is allowed to visit\n            user = self.request.user\n\n            forums_pub = Forum.objects.filter(group__isnull=True).all()\n            if user and user.is_authenticated():\n                forums_private = Forum \\\n                    .objects \\\n                    .filter(group__isnull=False, group__in=user.groups.all()) \\\n                    .all()\n                list_forums = list(forums_pub | forums_private)\n            else:\n                list_forums = list(forums_pub)\n\n            self.authorized_forums = [f.pk for f in list_forums]\n\n            search_queryset = Search()\n\n            # setting the different querysets (according to the selected models, if any)\n            part_querysets = []\n            chosen_groups = self.search_form.cleaned_data['models']\n\n            if chosen_groups:\n                models = []\n                for group in chosen_groups:\n                    if group in settings.ZDS_APP['search']['search_groups']:\n                        models.append(settings.ZDS_APP['search']['search_groups'][group][1])\n            else:\n                models = [v[1] for k, v in settings.ZDS_APP['search']['search_groups'].iteritems()]\n\n            models = reduce(operator.concat, models)\n\n            for model in models:\n                part_querysets.append(getattr(self, 'get_queryset_{}s'.format(model))())\n\n            queryset = part_querysets[0]\n            for query in part_querysets[1:]:\n                queryset |= query\n\n            # weighting:\n            weight_functions = []\n            for _type, weights in settings.ZDS_APP['search']['boosts'].items():\n                if _type in models:\n                    weight_functions.append({'filter': Match(_type=_type), 'weight': weights['global']})\n\n            scored_queryset = FunctionScore(query=queryset, boost_mode='multiply', functions=weight_functions)\n            search_queryset = search_queryset.query(scored_queryset)\n\n            # highlighting:\n            search_queryset = search_queryset.highlight_options(\n                fragment_size=150, number_of_fragments=5, pre_tags=['[hl]'], post_tags=['[/hl]'])\n            search_queryset = search_queryset.highlight('text').highlight('text_html')\n\n            # executing:\n            return self.index_manager.setup_search(search_queryset)\n\n        return []\n\n    def get_queryset_publishedcontents(self):\n        \"\"\"Find in PublishedContents.\n        \"\"\"\n\n        query = Match(_type='publishedcontent') \\\n            & MultiMatch(query=self.search_query, fields=['title', 'description', 'categories', 'tags', 'text'])\n\n        functions_score = [\n            {\n                'filter': Match(content_type='TUTORIAL'),\n                'weight': settings.ZDS_APP['search']['boosts']['publishedcontent']['if_tutorial']\n            },\n            {\n                'filter': Match(content_type='ARTICLE'),\n                'weight': settings.ZDS_APP['search']['boosts']['publishedcontent']['if_article']\n            },\n        ]\n\n        scored_query = FunctionScore(query=query, boost_mode='multiply', functions=functions_score)\n\n        return scored_query\n\n    def get_queryset_chapters(self):\n        \"\"\"Find in chapters.\n        \"\"\"\n\n        query = Match(_type='chapter') \\\n            & MultiMatch(query=self.search_query, fields=['title', 'text'])\n\n        return query\n\n    def get_queryset_topics(self):\n        \"\"\"Find in topics, and remove result if the forum is not allowed for the user.\n\n        Score is modified if :\n\n        + topic is solved ;\n        + Topic is sticky ;\n        + Topic is locked.\n\n        \"\"\"\n\n        query = Match(_type='topic') \\\n            & Terms(forum_pk=self.authorized_forums) \\\n            & MultiMatch(query=self.search_query, fields=['title', 'subtitle', 'tags'])\n\n        functions_score = [\n            {'filter': Match(is_solved=True), 'weight': settings.ZDS_APP['search']['boosts']['topic']['if_solved']},\n            {'filter': Match(is_sticky=True), 'weight': settings.ZDS_APP['search']['boosts']['topic']['if_sticky']},\n            {'filter': Match(is_locked=True), 'weight': settings.ZDS_APP['search']['boosts']['topic']['if_locked']}\n        ]\n\n        scored_query = FunctionScore(query=query, boost_mode='multiply', functions=functions_score)\n\n        return scored_query\n\n    def get_queryset_posts(self):\n        \"\"\"Find in posts, and remove result if the forum is not allowed for the user or if the message is invisible.\n\n        Score is modified if :\n\n        + Post is the first one in a topic ;\n        + Post is marked as \"useful\" ;\n        + Post has a like/dislike ratio above (more like than dislike) or below (the other way around) 1.0.\n        \"\"\"\n\n        query = Match(_type='post') \\\n            & Terms(forum_pk=self.authorized_forums) \\\n            & Term(is_visible=True) \\\n            & MultiMatch(query=self.search_query, fields=['text_html'])\n\n        functions_score = [\n            {'filter': Match(position=1), 'weight': settings.ZDS_APP['search']['boosts']['post']['if_first']},\n            {'filter': Match(is_useful=True), 'weight': settings.ZDS_APP['search']['boosts']['post']['if_useful']},\n            {\n                'filter': Range(like_dislike_ratio={'gt': 1}),\n                'weight': settings.ZDS_APP['search']['boosts']['post']['ld_ratio_above_1']\n            },\n            {\n                'filter': Range(like_dislike_ratio={'lt': 1}),\n                'weight': settings.ZDS_APP['search']['boosts']['post']['ld_ratio_below_1']\n            }\n        ]\n\n        scored_query = FunctionScore(query=query, boost_mode='multiply', functions=functions_score)\n\n        return scored_query\n\n    def get_context_data(self, **kwargs):\n        context = super(SearchView, self).get_context_data(**kwargs)\n        context['form'] = self.search_form\n        context['query'] = self.search_query is not None\n\n        return context\n\n\ndef opensearch(request):\n    \"\"\"Generate OpenSearch Description file\"\"\"\n\n    return render(request, 'search/opensearch.xml', {\n        'site_name': settings.ZDS_APP['site']['litteral_name'],\n        'site_url': settings.ZDS_APP['site']['url'],\n        'email_contact': settings.ZDS_APP['site']['email_contact'],\n        'language': settings.LANGUAGE_CODE,\n        'search_url': settings.ZDS_APP['site']['url'] + reverse('search:query')\n    }, content_type='application/opensearchdescription+xml')\n", "path": "zds/searchv2/views.py"}], "after_files": [{"content": "# coding: utf-8\nimport operator\n\nfrom elasticsearch_dsl import Search\nfrom elasticsearch_dsl.query import Match, MultiMatch, FunctionScore, Term, Terms, Range\n\nfrom django.conf import settings\nfrom django.core.exceptions import PermissionDenied\nfrom django.contrib import messages\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.shortcuts import render\nfrom django.core.urlresolvers import reverse\n\nfrom zds.searchv2.forms import SearchForm\nfrom zds.searchv2.models import ESIndexManager\nfrom zds.utils.paginator import ZdSPagingListView\nfrom zds.forum.models import Forum\n\n\nclass SearchView(ZdSPagingListView):\n    \"\"\"Research view\n    \"\"\"\n\n    template_name = 'searchv2/search.html'\n    paginate_by = settings.ZDS_APP['search']['results_per_page']\n\n    search_form_class = SearchForm\n    search_form = None\n    search_query = None\n\n    authorized_forums = ''\n\n    index_manager = None\n\n    def __init__(self, **kwargs):\n        \"\"\"Overridden because index manager must NOT be initialized elsewhere\n        \"\"\"\n\n        super(SearchView, self).__init__(**kwargs)\n        self.index_manager = ESIndexManager(**settings.ES_SEARCH_INDEX)\n\n    def get(self, request, *args, **kwargs):\n        \"\"\"Overridden to catch the request and fill the form.\n        \"\"\"\n\n        if 'q' in request.GET:\n            self.search_query = ''.join(request.GET['q'])\n\n        self.search_form = self.search_form_class(data=self.request.GET)\n\n        if self.search_query and not self.search_form.is_valid():\n            raise PermissionDenied('research form is invalid')\n\n        return super(SearchView, self).get(request, *args, **kwargs)\n\n    def get_queryset(self):\n        if not self.index_manager.connected_to_es:\n            messages.warning(self.request, _(u'Impossible de se connecter \u00e0 Elasticsearch'))\n            return []\n\n        if self.search_query:\n\n            # find forums the user is allowed to visit\n            user = self.request.user\n\n            forums_pub = Forum.objects.filter(group__isnull=True).all()\n            if user and user.is_authenticated():\n                forums_private = Forum \\\n                    .objects \\\n                    .filter(group__isnull=False, group__in=user.groups.all()) \\\n                    .all()\n                list_forums = list(forums_pub | forums_private)\n            else:\n                list_forums = list(forums_pub)\n\n            self.authorized_forums = [f.pk for f in list_forums]\n\n            search_queryset = Search()\n\n            # setting the different querysets (according to the selected models, if any)\n            part_querysets = []\n            chosen_groups = self.search_form.cleaned_data['models']\n\n            if chosen_groups:\n                models = []\n                for group in chosen_groups:\n                    if group in settings.ZDS_APP['search']['search_groups']:\n                        models.append(settings.ZDS_APP['search']['search_groups'][group][1])\n            else:\n                models = [v[1] for k, v in settings.ZDS_APP['search']['search_groups'].iteritems()]\n\n            models = reduce(operator.concat, models)\n\n            for model in models:\n                part_querysets.append(getattr(self, 'get_queryset_{}s'.format(model))())\n\n            queryset = part_querysets[0]\n            for query in part_querysets[1:]:\n                queryset |= query\n\n            # weighting:\n            weight_functions = []\n            for _type, weights in settings.ZDS_APP['search']['boosts'].items():\n                if _type in models:\n                    weight_functions.append({'filter': Match(_type=_type), 'weight': weights['global']})\n\n            scored_queryset = FunctionScore(query=queryset, boost_mode='multiply', functions=weight_functions)\n            search_queryset = search_queryset.query(scored_queryset)\n\n            # highlighting:\n            search_queryset = search_queryset.highlight_options(\n                fragment_size=150, number_of_fragments=5, pre_tags=['[hl]'], post_tags=['[/hl]'])\n            search_queryset = search_queryset.highlight('text').highlight('text_html')\n\n            # executing:\n            return self.index_manager.setup_search(search_queryset)\n\n        return []\n\n    def get_queryset_publishedcontents(self):\n        \"\"\"Find in PublishedContents.\n        \"\"\"\n\n        query = Match(_type='publishedcontent') \\\n            & MultiMatch(query=self.search_query, fields=['title', 'description', 'categories', 'tags', 'text'])\n\n        functions_score = [\n            {\n                'filter': Match(content_type='TUTORIAL'),\n                'weight': settings.ZDS_APP['search']['boosts']['publishedcontent']['if_tutorial']\n            },\n            {\n                'filter': Match(content_type='ARTICLE'),\n                'weight': settings.ZDS_APP['search']['boosts']['publishedcontent']['if_article']\n            },\n        ]\n\n        scored_query = FunctionScore(query=query, boost_mode='multiply', functions=functions_score)\n\n        return scored_query\n\n    def get_queryset_chapters(self):\n        \"\"\"Find in chapters.\n        \"\"\"\n\n        query = Match(_type='chapter') \\\n            & MultiMatch(query=self.search_query, fields=['title', 'text'])\n\n        return query\n\n    def get_queryset_topics(self):\n        \"\"\"Find in topics, and remove result if the forum is not allowed for the user.\n\n        Score is modified if :\n\n        + topic is solved ;\n        + Topic is sticky ;\n        + Topic is locked.\n\n        \"\"\"\n\n        query = Match(_type='topic') \\\n            & Terms(forum_pk=self.authorized_forums) \\\n            & MultiMatch(query=self.search_query, fields=['title', 'subtitle', 'tags'])\n\n        functions_score = [\n            {'filter': Match(is_solved=True), 'weight': settings.ZDS_APP['search']['boosts']['topic']['if_solved']},\n            {'filter': Match(is_sticky=True), 'weight': settings.ZDS_APP['search']['boosts']['topic']['if_sticky']},\n            {'filter': Match(is_locked=True), 'weight': settings.ZDS_APP['search']['boosts']['topic']['if_locked']}\n        ]\n\n        scored_query = FunctionScore(query=query, boost_mode='multiply', functions=functions_score)\n\n        return scored_query\n\n    def get_queryset_posts(self):\n        \"\"\"Find in posts, and remove result if the forum is not allowed for the user or if the message is invisible.\n\n        Score is modified if :\n\n        + Post is the first one in a topic ;\n        + Post is marked as \"useful\" ;\n        + Post has a like/dislike ratio above (more like than dislike) or below (the other way around) 1.0.\n        \"\"\"\n\n        query = Match(_type='post') \\\n            & Terms(forum_pk=self.authorized_forums) \\\n            & Term(is_visible=True) \\\n            & MultiMatch(query=self.search_query, fields=['text_html'])\n\n        functions_score = [\n            {'filter': Match(position=1), 'weight': settings.ZDS_APP['search']['boosts']['post']['if_first']},\n            {'filter': Match(is_useful=True), 'weight': settings.ZDS_APP['search']['boosts']['post']['if_useful']},\n            {\n                'filter': Range(like_dislike_ratio={'gt': 1}),\n                'weight': settings.ZDS_APP['search']['boosts']['post']['ld_ratio_above_1']\n            },\n            {\n                'filter': Range(like_dislike_ratio={'lt': 1}),\n                'weight': settings.ZDS_APP['search']['boosts']['post']['ld_ratio_below_1']\n            }\n        ]\n\n        scored_query = FunctionScore(query=query, boost_mode='multiply', functions=functions_score)\n\n        return scored_query\n\n    def get_context_data(self, **kwargs):\n        context = super(SearchView, self).get_context_data(**kwargs)\n        context['form'] = self.search_form\n        context['query'] = self.search_query is not None\n\n        return context\n\n\ndef opensearch(request):\n    \"\"\"Generate OpenSearch Description file\"\"\"\n\n    return render(request, 'searchv2/opensearch.xml', {\n        'site_name': settings.ZDS_APP['site']['litteral_name'],\n        'site_url': settings.ZDS_APP['site']['url'],\n        'email_contact': settings.ZDS_APP['site']['email_contact'],\n        'language': settings.LANGUAGE_CODE,\n        'search_url': settings.ZDS_APP['site']['url'] + reverse('search:query')\n    }, content_type='application/opensearchdescription+xml')\n", "path": "zds/searchv2/views.py"}]}