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
2 lines (1 loc) • 1.19 kB
JavaScript
import{pipe as e,values as t,chain as r,prop as n,filter as a,pluck as o}from"ramda";import{getFlexSearchInstance as s}from"./utils.js";function i(e,t,r){const n=function(e,t){let r=e,{keywords:n,index:a}=d(e,t);const o=e=>{r=e;const o=d(e,t);n=o.keywords,a=o.index};return{search:e=>a.search(e).map(e=>n[e]),add:e=>{n.push(e),a.add(n.length-1,e)},update:o,getAllPois:()=>r}}(e,r);return{query:(e,r)=>{const a=n.search({query:e,limit:r}),o=!(e.length<3)&&a.length,s=r-a.length,i=o?function(e,r){const n=t({query:e,limit:r}),a=t({query:e,suggest:!0,limit:r}),o=n.map(e=>e.poiId),s=a.filter(e=>-1===o.indexOf(e.poiId));return n.concat(s)}(e,s):[];return{keywords:a,pois:i}},addKeyword:e=>{n.add(e)},updatePOIs:e=>{const t={...n.getAllPois()};for(const r of e)t[r.poiId]=r;n.update(t)}}}function d(i,d){const c=function(e){return Object.values(e).map(e=>e.category).map(e=>e.split(".")).map(e=>e[0])}(i),u=[...c,...e(t,r(n("keywords")),a(n("isUserSearchable")),o("name"))(i),...e(t,o("name"))(i),...e(t,a(e=>e.staticName&&e.staticName!==e.name),o("staticName"))(i)],m=Array.from(new Set([...u])),l=s({lang:d});return m.forEach((e,t)=>l.add(t,e)),{keywords:m,index:l}}export{i as default};