Skip to content
This repository has been archived by the owner on Feb 28, 2018. It is now read-only.

Commit

Permalink
Merge pull request #255 from datasciencebr/cuducos-combine-full-text-…
Browse files Browse the repository at this point in the history
…search-ans-filters

Fix bug when using full text search w/ filters
  • Loading branch information
anaschwendler authored Oct 6, 2017
2 parents ce92342 + a460674 commit 10f48a9
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions jarbas/dashboard/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,17 @@ def formfield_for_dbfield(self, db_field, **kwargs):
return super().formfield_for_dbfield(db_field, **kwargs)

def get_search_results(self, request, queryset, search_term):
if not search_term:
return super(ReimbursementModelAdmin, self) \
.get_search_results(request, queryset, search_term)
queryset, distinct = super(ReimbursementModelAdmin, self) \
.get_search_results(request, queryset, None)

query = SearchQuery(search_term, config='portuguese')
rank = SearchRank(F('search_vector'), query)
queryset = Reimbursement.objects.annotate(rank=rank) \
.filter(search_vector=query) \
.order_by('-rank')
if search_term:
query = SearchQuery(search_term, config='portuguese')
rank = SearchRank(F('search_vector'), query)
queryset = queryset.annotate(rank=rank) \
.filter(search_vector=query) \
.order_by('-rank')

return queryset, False
return queryset, distinct


dashboard.register(Reimbursement, ReimbursementModelAdmin)

0 comments on commit 10f48a9

Please sign in to comment.