@@ -25,9 +25,9 @@ def search_project(request, query, language=None):
25
25
]
26
26
},
27
27
},
28
- "facets " : {
28
+ "aggs " : {
29
29
"language" : {
30
- "terms" : {"field" : "lang" },
30
+ "terms" : {"field" : "lang.keyword " },
31
31
},
32
32
},
33
33
"highlight" : {
@@ -36,13 +36,12 @@ def search_project(request, query, language=None):
36
36
"description" : {},
37
37
}
38
38
},
39
- "fields " : ["name" , "slug" , "description" , "lang" , "url" ],
39
+ "_source " : ["name" , "slug" , "description" , "lang" , "url" ],
40
40
"size" : 50 # TODO: Support pagination.
41
41
}
42
42
43
43
if language :
44
- body ['facets' ]['language' ]['facet_filter' ] = {"term" : {"lang" : language }}
45
- body ['filter' ] = {"term" : {"lang" : language }}
44
+ body ['query' ]['bool' ]['filter' ] = {"term" : {"lang" : language }}
46
45
47
46
before_project_search .send (request = request , sender = ProjectIndex , body = body )
48
47
@@ -89,15 +88,15 @@ def search_file(request, query, project_slug=None, version_slug=LATEST, taxonomy
89
88
]
90
89
}
91
90
},
92
- "facets " : {
91
+ "aggs " : {
93
92
"taxonomy" : {
94
- "terms" : {"field" : "taxonomy" },
93
+ "terms" : {"field" : "taxonomy.keyword " },
95
94
},
96
95
"project" : {
97
- "terms" : {"field" : "project" },
96
+ "terms" : {"field" : "project.keyword " },
98
97
},
99
98
"version" : {
100
- "terms" : {"field" : "version" },
99
+ "terms" : {"field" : "version.keyword " },
101
100
},
102
101
},
103
102
"highlight" : {
@@ -107,12 +106,12 @@ def search_file(request, query, project_slug=None, version_slug=LATEST, taxonomy
107
106
"content" : {},
108
107
}
109
108
},
110
- "fields " : ["title" , "project" , "version" , "path" ],
109
+ "_source " : ["title" , "project" , "version" , "path" ],
111
110
"size" : 50 # TODO: Support pagination.
112
111
}
113
112
114
113
if project_slug or version_slug or taxonomy :
115
- final_filter = { "and" : []}
114
+ final_filter = []
116
115
117
116
if project_slug :
118
117
try :
@@ -126,7 +125,7 @@ def search_file(request, query, project_slug=None, version_slug=LATEST, taxonomy
126
125
in Project .objects .public (
127
126
request .user ).filter (
128
127
superprojects__parent__slug = project .slug ))
129
- final_filter [ 'and' ] .append ({"terms" : {"project" : project_slugs }})
128
+ final_filter .append ({"terms" : {"project" : project_slugs }})
130
129
131
130
# Add routing to optimize search by hitting the right shard.
132
131
# This purposely doesn't apply routing if the project has more
@@ -141,15 +140,12 @@ def search_file(request, query, project_slug=None, version_slug=LATEST, taxonomy
141
140
return None
142
141
143
142
if version_slug :
144
- final_filter [ 'and' ] .append ({'term' : {'version' : version_slug }})
143
+ final_filter .append ({'term' : {'version' : version_slug }})
145
144
146
145
if taxonomy :
147
- final_filter [ 'and' ] .append ({'term' : {'taxonomy' : taxonomy }})
146
+ final_filter .append ({'term' : {'taxonomy' : taxonomy }})
148
147
149
- body ['filter' ] = final_filter
150
- body ['facets' ]['project' ]['facet_filter' ] = final_filter
151
- body ['facets' ]['version' ]['facet_filter' ] = final_filter
152
- body ['facets' ]['taxonomy' ]['facet_filter' ] = final_filter
148
+ body ['query' ]['bool' ]['filter' ] = final_filter
153
149
154
150
if settings .DEBUG :
155
151
print ("Before Signal" )
@@ -167,9 +163,9 @@ def search_section(request, query, project_slug=None, version_slug=LATEST,
167
163
"""
168
164
Search for a section of content.
169
165
170
- When you search, you will have a ``project`` facet, which includes the
166
+ When you search, you will have a ``project`` facet (aggs) , which includes the
171
167
number of matching sections per project. When you search inside a project,
172
- the ``path`` facet will show the number of matching sections per page.
168
+ the ``path`` aggs will show the number of matching sections per page.
173
169
174
170
:param request: Request instance
175
171
:param query: string to use in query
@@ -198,12 +194,9 @@ def search_section(request, query, project_slug=None, version_slug=LATEST,
198
194
]
199
195
}
200
196
},
201
- "facets " : {
197
+ "aggs " : {
202
198
"project" : {
203
- "terms" : {"field" : "project" },
204
- "facet_filter" : {
205
- "term" : {"version" : version_slug },
206
- }
199
+ "terms" : {"field" : "project.keyword" },
207
200
},
208
201
},
209
202
"highlight" : {
@@ -212,36 +205,29 @@ def search_section(request, query, project_slug=None, version_slug=LATEST,
212
205
"content" : {},
213
206
}
214
207
},
215
- "fields " : ["title" , "project" , "version" , "path" , "page_id" , "content" ],
208
+ "_source " : ["title" , "project" , "version" , "path" , "page_id" , "content" ],
216
209
"size" : 10 # TODO: Support pagination.
217
210
}
218
211
219
212
if project_slug :
220
- body ['filter' ] = {
221
- "and" : [
222
- {"term" : {"project" : project_slug }},
223
- {"term" : {"version" : version_slug }},
224
- ]
225
- }
226
- body ['facets' ]['path' ] = {
213
+ body ['query' ]['bool' ]['filter' ] = [
214
+ {"term" : {"project" : project_slug }},
215
+ {"term" : {"version" : version_slug }},
216
+ ]
217
+ body ['aggs' ]['path' ] = {
227
218
"terms" : {"field" : "path" },
228
- "facet_filter" : {
229
- "term" : {"project" : project_slug },
230
- }
231
219
},
232
220
# Add routing to optimize search by hitting the right shard.
233
221
kwargs ['routing' ] = project_slug
234
222
235
223
if path :
236
- body ['filter' ] = {
237
- "and" : [
238
- {"term" : {"path" : path }},
239
- ]
240
- }
224
+ body ['query' ]['bool' ]['filter' ] = [
225
+ {"term" : {"path" : path }},
226
+ ]
241
227
242
228
if path and not project_slug :
243
229
# Show facets when we only have a path
244
- body ['facets ' ]['path' ] = {
230
+ body ['aggs ' ]['path' ] = {
245
231
"terms" : {"field" : "path" }
246
232
}
247
233
0 commit comments