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

Allow paging through search results #1222

Closed
humphd opened this issue Oct 21, 2020 · 3 comments · Fixed by #1384
Closed

Allow paging through search results #1222

humphd opened this issue Oct 21, 2020 · 3 comments · Fixed by #1384
Assignees
Labels
area: back-end area: elasticsearch Elasticsearch Related issues and pull requests area: front-end type: bug Something isn't working

Comments

@humphd
Copy link
Contributor

humphd commented Oct 21, 2020

In #1217 I'm adding some data fetching paging logic using https://swr.vercel.app. It could also be used for our search front-end (e.g., SearchPage.jsx) to allow us to page through the results we get back from our backend.

To do this, we need to pass the data to our <Timeline> component in "pages" like this:

<Timeline pages={arrayOfArraysOfPosts} nextPage={functionToGetNextPage />

The data we get back from the server for a query looks like this:

{
  results: 1436
  values: [
    {
      id: '0f8021a157',
      text: 'full text of post....................'
      score: 4.913031
    },
    ...
  ]
}

See #1221, where this might change a bit. We know the number of results, and could request chunks of it using the from and size options in our elasticsearch query. We'd have to update our /query route to accept params with this info, and then do something like this https://swr.vercel.app/docs/pagination#example-2-cursor-or-offset-based-paginated-api.

@humphd humphd added type: bug Something isn't working area: back-end area: front-end area: elasticsearch Elasticsearch Related issues and pull requests labels Oct 21, 2020
@humphd
Copy link
Contributor Author

humphd commented Oct 21, 2020

I'm doing something pretty similar in #1217 if you want to see more code like this, and https://codesandbox.io/s/swr-infinite-z6r0r?from-embed=&file=/src/App.js is helpful

@c3ho c3ho assigned c3ho and unassigned c3ho Oct 29, 2020
@joelazwar joelazwar self-assigned this Nov 15, 2020
@joelazwar
Copy link
Contributor

@humphd I looked into PR #1343 and saw the changes for the search page. So I made a new branch based on that and added on to it to get the paging functionality working. Once that PR gets merged I'll rebase and make a PR for this. Here's the branch for now issue-1222

@humphd
Copy link
Contributor Author

humphd commented Nov 17, 2020

@joelazwar #1343 is merged, go ahead and rebase onto master.

humphd pushed a commit that referenced this issue Nov 19, 2020
* added paging functionality for search results

* some requested changes made

* minor changes

* edited ELASTIC_MAX_RESULTS

* edited query validation

* more requested changes

* added validation tests, and edited express validation logic for new params

* minor query test js changes

* no search results message changed

* default max search perpage to 5

* edited prod/staging env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: back-end area: elasticsearch Elasticsearch Related issues and pull requests area: front-end type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants