refactor: apply review suggestions

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2022-10-03 13:50:14 +02:00
parent a799972bb1
commit 4ed1fa2480
6 changed files with 34 additions and 14 deletions
+28
View File
@@ -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
<SearchResults query={{ pageLimit: 30 }}>
{results => {
// Item rendering logic is omitted
}}
</SearchResults>
```
_With context_
```jsx
<SearchContextProvider initialState={{ pageLimit: 30 }}>
<SearchResults>
{results => {
// Item rendering logic is omitted
}}
</SearchResults>
</SearchContextProvider>
```
+4 -2
View File
@@ -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.
-5
View File
@@ -1,5 +0,0 @@
---
'@backstage/plugin-search-react': minor
---
Added new page boundary to search query context and results state.
-5
View File
@@ -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.
+1 -1
View File
@@ -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.
@@ -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