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
66 lines (53 loc) • 1.87 kB
JavaScript
;
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 = 5000;
function createPOISearch (pois, lang) {
const index = utils.getFlexSearchInstance({ lang });
// index.addMatcher({
// '[\'.,]': ''
// })
prepareIndexEntries(pois)
.forEach(([id, content]) => index.add(id, content));
function prepareIndexEntries (pois) {
return Object.values(pois).map((poi) => {
const { poiId, category = '', name, 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 content = `${name} ${category.split('.').join(' ')} ${roomId} ${searchKeywords.join(' ')} ${grabTags.join(' ')}`;
return [Number(poiId), content]
})
}
function search (queryParams) {
const options = { ...queryParams };
if (!options.limit) // sometimes limit is NaN or undefined!
options.limit = DEFAULT_RESULTS_LIMIT;
const ids = index.search(options);
return Object.values(R__namespace.pick(ids, pois))
}
function updateMultiple (pois) {
prepareIndexEntries(pois)
.forEach(([id, content]) => index.update(id, content));
}
return { search, updateMultiple }
}
module.exports = createPOISearch;