Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination #26

Open
simonw opened this issue Sep 21, 2020 · 7 comments
Open

Pagination #26

simonw opened this issue Sep 21, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Collaborator

simonw commented Sep 21, 2020

Useful for #16 (timeline view) since you can now filter to just the items on a specific day - but if there are more than 50 items you can't see them all.

@simonw simonw added the enhancement New feature or request label Sep 21, 2020
@simonw
Copy link
Collaborator Author

simonw commented Sep 21, 2020

Should I do this with offset/limit or should I do proper keyset pagination?

I think keyset because then it will work well for the full search interface with no filters or search string.

@simonw
Copy link
Collaborator Author

simonw commented Sep 21, 2020

It feels a bit weird to implement keyset pagination against results sorted by rank because the ranks could change substantially if the search index gets updated while the user is paginating.

I may just ignore that though. If you want reliable pagination you can get it by sorting by date. Maybe it doesn't even make sense to offer pagination if you sort by relevance?

@simonw
Copy link
Collaborator Author

simonw commented Sep 21, 2020

I'm going to try for keyset pagination sorted by relevance just as a learning exercise.

@simonw
Copy link
Collaborator Author

simonw commented Sep 21, 2020

It's a shame Datasette doesn't currently have an easy way to implement sorted-by-rank keyset-paginated using a TableView or QueryView. I'll have to do this using the custom SQL query constructed in the plugin:

TIMELINE_SQL = """
select
search_index.rowid,
search_index.type,
search_index.key,
search_index.title,
search_index.category,
search_index.timestamp,
search_index.search_1
from
search_index
{where}
{where_clauses}
order by
{order_by}
limit 40
"""
SEARCH_SQL = """
select
search_index_fts.rank,
search_index.rowid,
search_index.type,
search_index.key,
search_index.title,
search_index.category,
search_index.timestamp,
search_index.search_1
from
search_index join search_index_fts on search_index.rowid = search_index_fts.rowid
{where}
{where_clauses}
order by
{order_by}
limit 100
"""

@simonw simonw changed the title Search pagination Pagination Sep 21, 2020
@simonw
Copy link
Collaborator Author

simonw commented Sep 21, 2020

Datasette's implementation is complex because it has to support compound primary keys: https://github.com/simonw/datasette/blob/a258339a935d8d29a95940ef1db01e98bb85ae63/datasette/utils/__init__.py#L88-L114 - but that's not something that's needed for dogsheep-beta.

@simonw
Copy link
Collaborator Author

simonw commented Sep 21, 2020

If previous page ended at 2018-02-11T16:32:53+00:00:

select
  search_index.rowid,
  search_index.type,
  search_index.key,
  search_index.title,
  search_index.category,
  search_index.timestamp,
  search_index.search_1
from
  search_index
 where 
  date("timestamp") = '2018-02-11'
 and timestamp < '2018-02-11T16:32:53+00:00'
order by
  search_index.timestamp desc, rowid
limit 41

@simonw
Copy link
Collaborator Author

simonw commented Sep 21, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant