2019-02-05 08:37:44 -05:00
|
|
|
/**
|
|
|
|
* Search table access
|
|
|
|
* - to support navigation around the map
|
|
|
|
* - some separation from building attributes - here we might use other points of interest
|
|
|
|
* or cues to broadly locate the user (postcode, borough name...)
|
|
|
|
* - this DOES expose geometry, another reason to keep this clearly separated from building
|
|
|
|
* data
|
|
|
|
*/
|
2019-08-14 05:54:13 -04:00
|
|
|
import db from '../../db';
|
2019-02-05 08:37:44 -05:00
|
|
|
|
2019-02-24 14:28:11 -05:00
|
|
|
function queryLocation(term) {
|
2019-05-27 13:26:29 -04:00
|
|
|
const limit = 5;
|
2019-02-05 08:37:44 -05:00
|
|
|
return db.manyOrNone(
|
|
|
|
`SELECT
|
|
|
|
search_str, search_class, ST_AsGeoJSON(center), zoom,
|
|
|
|
search_str <-> $1 AS dist
|
|
|
|
FROM
|
|
|
|
search_locations
|
|
|
|
ORDER BY
|
|
|
|
dist
|
|
|
|
LIMIT $2;`,
|
2019-05-27 13:26:29 -04:00
|
|
|
[term, limit]
|
2019-02-05 08:37:44 -05:00
|
|
|
).catch((error) => {
|
|
|
|
console.error(error);
|
|
|
|
return undefined;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
queryLocation
|
|
|
|
};
|