@backstage/plugin-search-backend-node
Advanced tools
Comparing version 0.0.0-nightly-202111222339 to 0.0.0-nightly-2021112322755
@@ -12,3 +12,3 @@ 'use strict'; | ||
class IndexBuilder { | ||
constructor({logger, searchEngine}) { | ||
constructor({ logger, searchEngine }) { | ||
this.collators = {}; | ||
@@ -32,3 +32,3 @@ this.decorators = {}; | ||
} | ||
addDecorator({decorator}) { | ||
addDecorator({ decorator }) { | ||
const types = decorator.types || ["*"]; | ||
@@ -45,3 +45,3 @@ this.logger.info(`Added decorator ${decorator.constructor.name} to types ${types.join(", ")}`); | ||
async build() { | ||
const scheduler = new Scheduler({logger: this.logger}); | ||
const scheduler = new Scheduler({ logger: this.logger }); | ||
Object.keys(this.collators).forEach((type) => { | ||
@@ -106,3 +106,3 @@ scheduler.addToSchedule(async () => { | ||
class Scheduler { | ||
constructor({logger}) { | ||
constructor({ logger }) { | ||
this.runningTasks = []; | ||
@@ -116,7 +116,7 @@ this.logger = logger; | ||
} | ||
this.schedule.push({task, interval}); | ||
this.schedule.push({ task, interval }); | ||
} | ||
start() { | ||
this.logger.info("Starting all scheduled search tasks."); | ||
this.schedule.forEach(({task, interval}) => { | ||
this.schedule.forEach(({ task, interval }) => { | ||
this.runningTasks.push(runPeriodically(() => task(), interval)); | ||
@@ -135,3 +135,3 @@ }); | ||
class LunrSearchEngine { | ||
constructor({logger}) { | ||
constructor({ logger }) { | ||
this.lunrIndices = {}; | ||
@@ -146,3 +146,3 @@ this.translator = ({ | ||
lunrQueryBuilder: (q) => { | ||
const termToken = lunr__default['default'].tokenizer(term); | ||
const termToken = lunr__default["default"].tokenizer(term); | ||
q.term(termToken, { | ||
@@ -155,3 +155,3 @@ usePipeline: true, | ||
boost: 10, | ||
wildcard: lunr__default['default'].Query.wildcard.TRAILING | ||
wildcard: lunr__default["default"].Query.wildcard.TRAILING | ||
}); | ||
@@ -170,4 +170,4 @@ q.term(termToken, { | ||
if (["string", "number", "boolean"].includes(typeof value)) { | ||
q.term(lunr__default['default'].tokenizer(value == null ? void 0 : value.toString()), { | ||
presence: lunr__default['default'].Query.presence.REQUIRED, | ||
q.term(lunr__default["default"].tokenizer(value == null ? void 0 : value.toString()), { | ||
presence: lunr__default["default"].Query.presence.REQUIRED, | ||
fields: [field] | ||
@@ -177,4 +177,4 @@ }); | ||
this.logger.warn(`Non-scalar filter value used for field ${field}. Consider using a different Search Engine for better results.`); | ||
q.term(lunr__default['default'].tokenizer(value), { | ||
presence: lunr__default['default'].Query.presence.OPTIONAL, | ||
q.term(lunr__default["default"].tokenizer(value), { | ||
presence: lunr__default["default"].Query.presence.OPTIONAL, | ||
fields: [field] | ||
@@ -199,5 +199,5 @@ }); | ||
async index(type, documents) { | ||
const lunrBuilder = new lunr__default['default'].Builder(); | ||
lunrBuilder.pipeline.add(lunr__default['default'].trimmer, lunr__default['default'].stopWordFilter, lunr__default['default'].stemmer); | ||
lunrBuilder.searchPipeline.add(lunr__default['default'].stemmer); | ||
const lunrBuilder = new lunr__default["default"].Builder(); | ||
lunrBuilder.pipeline.add(lunr__default["default"].trimmer, lunr__default["default"].stopWordFilter, lunr__default["default"].stemmer); | ||
lunrBuilder.searchPipeline.add(lunr__default["default"].stemmer); | ||
Object.keys(documents[0]).forEach((field) => { | ||
@@ -214,3 +214,3 @@ lunrBuilder.field(field); | ||
async query(query) { | ||
const {lunrQueryBuilder, documentTypes, pageSize} = this.translator(query); | ||
const { lunrQueryBuilder, documentTypes, pageSize } = this.translator(query); | ||
const results = []; | ||
@@ -235,11 +235,11 @@ Object.keys(this.lunrIndices).filter((type) => !documentTypes || documentTypes.includes(type)).forEach((type) => { | ||
}); | ||
const {page} = decodePageCursor(query.pageCursor); | ||
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 nextPageCursor = hasNextPage ? encodePageCursor({ page: page + 1 }) : void 0; | ||
const previousPageCursor = hasPreviousPage ? encodePageCursor({ page: page - 1 }) : void 0; | ||
const realResultSet = { | ||
results: results.slice(offset, offset + pageSize).map((d) => { | ||
return {type: d.type, document: this.docStore[d.result.ref]}; | ||
return { type: d.type, document: this.docStore[d.result.ref] }; | ||
}), | ||
@@ -254,3 +254,3 @@ nextPageCursor, | ||
if (!pageCursor) { | ||
return {page: 0}; | ||
return { page: 0 }; | ||
} | ||
@@ -261,3 +261,3 @@ return { | ||
} | ||
function encodePageCursor({page}) { | ||
function encodePageCursor({ page }) { | ||
return Buffer.from(`${page}`, "utf-8").toString("base64"); | ||
@@ -264,0 +264,0 @@ } |
{ | ||
"name": "@backstage/plugin-search-backend-node", | ||
"description": "A library for Backstage backend plugins that want to interact with the search backend plugin", | ||
"version": "0.0.0-nightly-202111222339", | ||
"version": "0.0.0-nightly-2021112322755", | ||
"main": "dist/index.cjs.js", | ||
@@ -23,3 +23,3 @@ "types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@backstage/search-common": "^0.0.0-nightly-202111222339", | ||
"@backstage/search-common": "^0.2.1", | ||
"winston": "^3.2.1", | ||
@@ -30,4 +30,4 @@ "lunr": "^2.3.9", | ||
"devDependencies": { | ||
"@backstage/backend-common": "^0.0.0-nightly-202111222339", | ||
"@backstage/cli": "^0.0.0-nightly-202111222339" | ||
"@backstage/backend-common": "^0.0.0-nightly-2021112322755", | ||
"@backstage/cli": "^0.0.0-nightly-2021112322755" | ||
}, | ||
@@ -34,0 +34,0 @@ "files": [ |
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
42851
+ 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@0.1.31.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/search-common@0.0.0-nightly-20220923026(transitive)
- Removed@backstage/types@0.0.0-nightly-20230919021144(transitive)