Skip to content
Snippets Groups Projects

Display num of results when searching/filtering tags

Open kenc requested to merge _kenc/tildes:search_results_num into master
2 unresolved threads

Implements #408. Some screenshots to illustrate:

Jun16-21_26_16

Jun16-21_47_48

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Maintainer

    I believe this isn't the completely correct way to do it because the results are limited to the amount of topics that are paginated. So if you set the query parameter per_page=1 and try the search again, it will show as "1 result" with a "Next" button at the bottom.

    Ideally it would show in total how many there are, so if there are 1000 topics matching the search but only 20 are shown on the page, it still says "1000 results".

  • kenc added 1 commit

    added 1 commit

    • cac110c2 - Fix to display total number of results

    Compare with previous version

  • Thanks, I missed that the queries were performed on a paginated basis, instead of paginating the full set of results after.

    To fix it, I introduced a method to remove all before and after restrictions from the query and use it to retrieve the total number of results. I think it's the cleanest way to do it, rather than trying to keep track of the page number.

    I'm not too familiar with sqlalchemy and Pyramid so please let me know if I neglected anything.

    Edited by kenc
  • kenc added 1 commit

    added 1 commit

    • ee3dc6f7 - Fix to remove stray pasted line

    Compare with previous version

  • Deimos
  • kenc added 1 commit

    added 1 commit

    Compare with previous version

  • Deimos
    Deimos @Deimorz started a thread on the diff
  • 229 236 self.has_next_page = False
    230 237 self.has_prev_page = False
    231 238
    239 # fetch total number of results without pagination
    240 self.total_count = (
    241 query.request.db_session.query(func.count())
    242 .select_from(query.remove_before_after().statement)
    • The SQL query this produces looks good and should be efficient, but I think this is going to actually modify the query by removing the before/after restrictions, right?

      That feels wrong to me - if you do anything that generates results (such as calling .get_page() on the query), if you were to use the query again afterwards it would produce different results. Is there some way that this could work that doesn't actually modify the query? For example, it might be possible to make a copy of it somehow and only modify the copy so it doesn't alter the original query (I don't know offhand how to do this).

    • Please register or sign in to reply
  • Deimos
    Deimos @Deimorz started a thread on the diff
  • 229 236 self.has_next_page = False
    230 237 self.has_prev_page = False
    231 238
    239 # fetch total number of results without pagination
    240 self.total_count = (
    • I think it would be best for this to be done in a separate function that needs to be called explicitly when you're going to use the count of results. Currently, everything that goes through PaginatedResults (including its subclasses) will start doing an extra query to fetch the count of results, but it's not used or displayed in almost all cases. That means that many pages (user pages, notifications page, all topic listings, etc.) will increase their database traffic for no reason, so we should only do this extra query when it's actually needed.

    • Please register or sign in to reply
    Please register or sign in to reply
    Loading