From 4ed1fa24809f93844325f6ac0a38490a5acf12f3 Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Mon, 3 Oct 2022 13:50:14 +0200 Subject: [PATCH] refactor: apply review suggestions Signed-off-by: Camila Belo --- .changeset/search-bobcats-love.md | 28 +++++++++++++++++++ .changeset/search-cycles-sniff.md | 6 ++-- .changeset/search-days-pull.md | 5 ---- .changeset/search-otters-destroy.md | 5 ---- .changeset/search-rats-grin.md | 2 +- .../src/PgSearchEngine/PgSearchEngine.ts | 2 +- 6 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 .changeset/search-bobcats-love.md delete mode 100644 .changeset/search-days-pull.md delete mode 100644 .changeset/search-otters-destroy.md diff --git a/.changeset/search-bobcats-love.md b/.changeset/search-bobcats-love.md new file mode 100644 index 0000000000..f562961c1b --- /dev/null +++ b/.changeset/search-bobcats-love.md @@ -0,0 +1,28 @@ +--- +'@backstage/plugin-search-react': minor +--- + +The search query state now has an optional `pageLimit` property that determines how many results will be requested per page, it defaults to 25. + +Examples: +_Basic_ + +```jsx + + {results => { + // Item rendering logic is omitted + }} + +``` + +_With context_ + +```jsx + + + {results => { + // Item rendering logic is omitted + }} + + +``` diff --git a/.changeset/search-cycles-sniff.md b/.changeset/search-cycles-sniff.md index e422d50806..350e499a18 100644 --- a/.changeset/search-cycles-sniff.md +++ b/.changeset/search-cycles-sniff.md @@ -1,5 +1,7 @@ --- -'@backstage/plugin-search-backend-module-elasticsearch': minor +'@backstage/plugin-search-backend-node': patch +'@backstage/plugin-search-backend-module-pg': patch +'@backstage/plugin-search-backend-module-elasticsearch': patch --- -The `Elastic Search` search engine query now contains a property called `pageLimit`, this new property specifies how many results to return per page and its default value is 25. +The search engine has been updated to take advantage of the `pageLimit` property on search queries. If none is provided, the search engine will continue to use its default value of 25 results per page. diff --git a/.changeset/search-days-pull.md b/.changeset/search-days-pull.md deleted file mode 100644 index 3a3c09d5bb..0000000000 --- a/.changeset/search-days-pull.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@backstage/plugin-search-react': minor ---- - -Added new page boundary to search query context and results state. diff --git a/.changeset/search-otters-destroy.md b/.changeset/search-otters-destroy.md deleted file mode 100644 index b91b98c173..0000000000 --- a/.changeset/search-otters-destroy.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@backstage/plugin-search-backend-node': minor ---- - -The `Lunr` search engine query now contains a property called `pageLimit`, this new property specifies how many results to return per page and its default value is 25. diff --git a/.changeset/search-rats-grin.md b/.changeset/search-rats-grin.md index 16d4e293c0..7b561d9c19 100644 --- a/.changeset/search-rats-grin.md +++ b/.changeset/search-rats-grin.md @@ -11,4 +11,4 @@ _Returns up to 30 results per page_ GET /query?pageLimit=30 ``` -It is worth mentioning that only the Lunr and Elastic Search engines currently use this new property in their implementations. So that means you can't use it with Postgres for now. The search backend doesn't set a default value for the page limit parameter, it leaves it up to each search engine to set this, so Lunr and Elastic Search set 25 results per page as a default value. +The search backend validates the page limit and this value must not exceed 100, but it doesn't set a default value for the page limit parameter, it leaves it up to each search engine to set this, so Lunr, Postgres and Elastic Search set 25 results per page as a default value. diff --git a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts index 01fe0fff82..f53c433c2f 100644 --- a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts +++ b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts @@ -137,7 +137,7 @@ export class PgSearchEngine implements SearchEngine { query: SearchQuery, options: PgSearchQueryTranslatorOptions, ): ConcretePgSearchQuery { - const pageSize = 25; + const pageSize = query.pageLimit || 25; const { page } = decodePageCursor(query.pageCursor); const offset = page * pageSize; // We request more result to know whether there is another page