Skip to content

Commit

Permalink
Fix search ordered by best match (#3706)
Browse files Browse the repository at this point in the history
* Don't force an order by created date - any usecases that want
this already request it explicitly and it breaks the search
function that wants to order by best match.

* Fix the logic so that we fall back to a default search order when there's
no search term, rather than when there is one and we should use the
best-match ordering.

* Remove accidentially added blank line
  • Loading branch information
Jakdaw authored and arikfr committed Apr 14, 2019
1 parent 63e052c commit af168c6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions redash/handlers/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get(self):
# order results according to passed order parameter,
# special-casing search queries where the database
# provides an order by search rank
ordered_results = order_results(results, fallback=bool(search_term))
ordered_results = order_results(results, fallback=not bool(search_term))

page = request.args.get('page', 1, type=int)
page_size = request.args.get('page_size', 25, type=int)
Expand Down Expand Up @@ -334,7 +334,7 @@ def get(self):
# order results according to passed order parameter,
# special-casing search queries where the database
# provides an order by search rank
favorites = order_results(favorites, fallback=bool(search_term))
favorites = order_results(favorites, fallback=not bool(search_term))

page = request.args.get('page', 1, type=int)
page_size = request.args.get('page_size', 25, type=int)
Expand Down
6 changes: 3 additions & 3 deletions redash/handlers/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def get(self):
# order results according to passed order parameter,
# special-casing search queries where the database
# provides an order by search rank
ordered_results = order_results(results, fallback=bool(search_term))
ordered_results = order_results(results, fallback=not bool(search_term))

page = request.args.get('page', 1, type=int)
page_size = request.args.get('page_size', 25, type=int)
Expand Down Expand Up @@ -290,7 +290,7 @@ def get(self):
# order results according to passed order parameter,
# special-casing search queries where the database
# provides an order by search rank
ordered_results = order_results(results, fallback=bool(search_term))
ordered_results = order_results(results, fallback=not bool(search_term))

page = request.args.get('page', 1, type=int)
page_size = request.args.get('page_size', 25, type=int)
Expand Down Expand Up @@ -464,7 +464,7 @@ def get(self):
# order results according to passed order parameter,
# special-casing search queries where the database
# provides an order by search rank
ordered_favorites = order_results(favorites, fallback=bool(search_term))
ordered_favorites = order_results(favorites, fallback=not bool(search_term))

page = request.args.get('page', 1, type=int)
page_size = request.args.get('page_size', 25, type=int)
Expand Down
2 changes: 1 addition & 1 deletion redash/handlers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_users(self, disabled, pending, search_term):
# order results according to passed order parameter,
# special-casing search queries where the database
# provides an order by search rank
return order_results(users, fallback=bool(search_term))
return order_results(users, fallback=not bool(search_term))

@require_permission('list_users')
def get(self):
Expand Down
1 change: 0 additions & 1 deletion redash/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ def all_queries(cls, group_ids, user_id=None, include_drafts=False, include_arch
contains_eager(Query.user),
contains_eager(Query.latest_query_data),
)
.order_by(Query.created_at.desc())
)

if not include_drafts:
Expand Down

0 comments on commit af168c6

Please sign in to comment.