Skip to content

Commit d7f1b1f

Browse files
committed
improve boost
1 parent ef3d3eb commit d7f1b1f

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

por/dashboard/search.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,14 @@ def query(items):
234234

235235
def _do_search(self, sort_by=None):
236236
si = SolrInterface(self.solr_endpoint)
237-
query = si.query().field_limit(score=True)
238237

239-
for searchterm in self.searchable:
240-
query = query.query(searchterm)
238+
searchquery = si.Q(*[si.Q(s) for s in self.searchable])
239+
query = si.query(searchquery).field_limit(score=True)
241240

242241
realm_query = self._build_realm_filter(si)
243242
if realm_query:
244243
query = query.filter(realm_query)
245244

246-
# boosting
247-
query = query.boost_relevancy(5, realm="ticket")\
248-
.boost_relevancy(5, status="new")\
249-
.boost_relevancy(5, status="assigned")\
250-
.boost_relevancy(10, status="reopened")\
251-
.boost_relevancy(3, status="reviewing")\
252-
.boost_relevancy(5, status="accepted")
253-
254245
author_query = self._build_author_filter(si)
255246
if author_query:
256247
query = query.filter(author_query)
@@ -262,13 +253,20 @@ def _do_search(self, sort_by=None):
262253
for field in sort_by or []:
263254
query = query.sort_by(field)
264255

265-
return query.paginate(start=self.page_start, rows=self.page_size)\
256+
query = query.paginate(start=self.page_start, rows=self.page_size)\
266257
.highlight('oneline',
267258
**{'simple.pre':'<span class="highlight">',
268259
'snippets': 3,
269260
'fragsize': 600,
270-
'simple.post':'</span>'})\
271-
.execute()
261+
'simple.post':'</span>'})
262+
263+
# boosting - super hacky but sunburnt is not support bq
264+
options = query.options()
265+
options['bq'] = ['realm:ticket^999','status:new^100', 'status:assigned^100',
266+
'status:reopened^999', 'status:reviewing^100',
267+
'status:accepted^100','(*:* -xxx)^999']
268+
result = query.interface.search(**options)
269+
return query.transform_result(result, dict)
272270

273271

274272
class FullTextSearchObject(object):

0 commit comments

Comments
 (0)