Skip to content

fix: pagination fix for `--fields and `--all-pages combination - #9

Open
adarshdigievo wants to merge 1 commit into
mainfrom
fix/fields-all-pages-pagination
Open

fix: pagination fix for `--fields and `--all-pages combination#9
adarshdigievo wants to merge 1 commit into
mainfrom
fix/fields-all-pages-pagination

Conversation

@adarshdigievo

Copy link
Copy Markdown
Member

Fix --fields preventing --all-pages from fetching subsequent pages by preserving the internal pagination restrictor across requests.

Fixes #8

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes pagination when --fields is combined with --all-pages by ensuring the internal pagination field (serpapi_pagination.next) is preserved in the server-side projection and by reapplying the restrictor on subsequent page requests.

Changes:

  • Injects serpapi_pagination.next into json_restrictor during --all-pages runs and reapplies it when following serpapi_pagination.next URLs.
  • Adds unit tests for the restrictor helper and for carrying json_restrictor through pagination URLs.
  • Adds an end-to-end regression test for --fields + --all-pages ensuring multi-page merging while keeping output limited to requested fields.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pkg/cmd/search.go Preserves pagination metadata under --fields and reapplies json_restrictor when following next URLs.
pkg/cmd/search_test.go Adds coverage for the new restrictor behavior and updated parseNextParams signature.
tests/e2e_test.go Adds a live regression test for --fields + --all-pages output shape and multi-page merging.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/cmd/search.go
Comment on lines +156 to +160
if restrictor == "" {
return ""
}
return restrictor + "," + paginationRestrictorPath
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this with live API calls and confirmed that duplicate and overlapping JSON Restrictor paths do not cause errors. Our API returns the requested union of fields.

Comment thread tests/e2e_test.go
Comment on lines +176 to +179
out, err := cmd.Output()
if err != nil {
t.Fatalf("search all pages with fields failed: %v", err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--fields silently disables --all-pages: only page 1 is returned

2 participants