-
Notifications
You must be signed in to change notification settings - Fork 3
/
indexer.js
44 lines (38 loc) · 1.21 KB
/
indexer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const lunr = require('lunr');
const _ = require('lodash');
// ## index
// Indexes the building data in `data` and returns an object with list of all
// buildings, serialized lunr store, and serialized kdtree
function index (data) {
const buildings = _.reduce(data, (acc, building) => {
const idx = acc.idx,
all = acc.all,
// Use building number + id as unique identifier
identifier = building.building_number + "_" + building.building_id + building.title;
building.id = identifier;
idx.add({
title: building.title,
num: building.building_number,
descr: building.description,
code: building.building_code,
depts: building.offices? building.offices.join(', ') : '',
id: identifier
});
all[identifier] = building;
return acc;
}, {
idx: lunr(function () {
this.field('title');
//this.field('descr');
this.ref('id');
this.field('code');
this.field('depts');
}),
all: {}
});
return {
lunr: buildings.idx.toJSON(),
all: buildings.all
};
}
module.exports = index;