UNPKG

atriusmaps-node-sdk

Version:

This project provides an API to Atrius Personal Wayfinder maps within a Node environment. See the README.md for more information

54 lines (48 loc) 1.86 kB
'use strict'; var R = require('ramda'); var utils = require('./utils.js'); function _interopNamespaceDefault(e) { var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n.default = e; return Object.freeze(n); } var R__namespace = /*#__PURE__*/_interopNamespaceDefault(R); const DEFAULT_RESULTS_LIMIT = 5e3; function createPOISearch(pois, lang) { const index = utils.getFlexSearchInstance({ lang }); prepareIndexEntries(pois).forEach(([id, content]) => index.add(id, content)); function prepareIndexEntries(pois2) { return Object.values(pois2).map((poi) => { const { poiId, category = "", name, staticName, keywords = [], roomId = "" } = poi; const grabTags = R__namespace.path(["dynamicData", "grab", "tags"], poi) || []; const searchKeywords = keywords.filter(R__namespace.prop("isUserSearchable")).map(R__namespace.prop("name")); const staticNamePart = staticName && staticName !== name ? staticName : ""; const content = `${name} ${staticNamePart} ${category.split(".").join(" ")} ${roomId} ${searchKeywords.join(" ")} ${grabTags.join(" ")}`; return [Number(poiId), content]; }); } function search(queryParams) { const options = { ...queryParams }; if (!options.limit) { options.limit = DEFAULT_RESULTS_LIMIT; } const ids = index.search(options); return Object.values(R__namespace.pick(ids, pois)); } function updateMultiple(pois2) { prepareIndexEntries(pois2).forEach(([id, content]) => index.update(id, content)); } return { search, updateMultiple }; } module.exports = createPOISearch;