@backstage/plugin-search-backend-node
Advanced tools
Comparing version 0.4.1 to 0.4.2
# @backstage/plugin-search-backend-node | ||
## 0.4.2 | ||
### Patch Changes | ||
- a13f21cdc: Implement optional `pageCursor` based paging in search. | ||
To use paging in your app, add a `<SearchResultPager />` to your | ||
`SearchPage.tsx`. | ||
- Updated dependencies | ||
- @backstage/search-common@0.2.0 | ||
## 0.4.1 | ||
@@ -4,0 +16,0 @@ |
@@ -137,2 +137,3 @@ 'use strict'; | ||
}) => { | ||
const pageSize = 25; | ||
return { | ||
@@ -177,3 +178,4 @@ lunrQueryBuilder: (q) => { | ||
}, | ||
documentTypes: types | ||
documentTypes: types, | ||
pageSize | ||
}; | ||
@@ -202,3 +204,3 @@ }; | ||
async query(query) { | ||
const {lunrQueryBuilder, documentTypes} = this.translator(query); | ||
const {lunrQueryBuilder, documentTypes, pageSize} = this.translator(query); | ||
const results = []; | ||
@@ -223,6 +225,14 @@ Object.keys(this.lunrIndices).filter((type) => !documentTypes || documentTypes.includes(type)).forEach((type) => { | ||
}); | ||
const {page} = decodePageCursor(query.pageCursor); | ||
const offset = page * pageSize; | ||
const hasPreviousPage = page > 0; | ||
const hasNextPage = results.length > offset + pageSize; | ||
const nextPageCursor = hasNextPage ? encodePageCursor({page: page + 1}) : void 0; | ||
const previousPageCursor = hasPreviousPage ? encodePageCursor({page: page - 1}) : void 0; | ||
const realResultSet = { | ||
results: results.map((d) => { | ||
results: results.slice(offset, offset + pageSize).map((d) => { | ||
return {type: d.type, document: this.docStore[d.result.ref]}; | ||
}) | ||
}), | ||
nextPageCursor, | ||
previousPageCursor | ||
}; | ||
@@ -232,2 +242,13 @@ return realResultSet; | ||
} | ||
function decodePageCursor(pageCursor) { | ||
if (!pageCursor) { | ||
return {page: 0}; | ||
} | ||
return { | ||
page: Number(Buffer.from(pageCursor, "base64").toString("utf-8")) | ||
}; | ||
} | ||
function encodePageCursor({page}) { | ||
return Buffer.from(`${page}`, "utf-8").toString("base64"); | ||
} | ||
@@ -234,0 +255,0 @@ exports.IndexBuilder = IndexBuilder; |
@@ -89,2 +89,3 @@ import { DocumentCollator, DocumentDecorator, SearchEngine, IndexableDocument, QueryTranslator, SearchQuery, SearchResultSet } from '@backstage/search-common'; | ||
documentTypes?: string[]; | ||
pageSize: number; | ||
}; | ||
@@ -91,0 +92,0 @@ declare type LunrQueryTranslator = (query: SearchQuery) => ConcreteLunrQuery; |
{ | ||
"name": "@backstage/plugin-search-backend-node", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"main": "dist/index.cjs.js", | ||
@@ -22,3 +22,3 @@ "types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@backstage/search-common": "^0.1.3", | ||
"@backstage/search-common": "^0.2.0", | ||
"@types/lunr": "^2.3.3", | ||
@@ -29,4 +29,4 @@ "lunr": "^2.3.9", | ||
"devDependencies": { | ||
"@backstage/backend-common": "^0.8.8", | ||
"@backstage/cli": "^0.7.7" | ||
"@backstage/backend-common": "^0.9.1", | ||
"@backstage/cli": "^0.7.10" | ||
}, | ||
@@ -36,3 +36,3 @@ "files": [ | ||
], | ||
"gitHead": "0cbbc971f3894862bf5a248603b5b997f8052da1" | ||
"gitHead": "174a8b532e8b6dda0e733ec943d1aa7187a3821a" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52874
344
+ Added@backstage/config@1.2.0(transitive)
+ Added@backstage/errors@1.2.4(transitive)
+ Added@backstage/plugin-permission-common@0.5.3(transitive)
+ Added@backstage/search-common@0.2.4(transitive)
+ Added@backstage/types@1.1.1(transitive)
+ Addedcross-fetch@3.1.8(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedserialize-error@8.1.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedtype-fest@0.20.2(transitive)
+ Addeduuid@8.3.2(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedzod@3.23.8(transitive)
- Removed@backstage/config@0.1.15(transitive)
- Removed@backstage/search-common@0.1.3(transitive)
- Removedlodash@4.17.21(transitive)