Commit 453f9ae8 authored by Markus Opolka's avatar Markus Opolka
Browse files

Refactor feature search endpoint

parent e3fc3783
......@@ -177,34 +177,28 @@ app.get('/api/features/:letter?', function (req, res) {
}
let data = []
const DOC = req.params.letter + '.xml'
let documents = []
console.time('> Search Features')
// TODO: Refactor this shice
if (req.params.letter) {
console.time('> Search Features - Letter')
let obj = loadDocument(DOC)
documents.push(req.params.letter + '.xml')
} else {
documents = cache.keys()
}
for (let doc of documents) {
let obj = loadDocument(doc)
if (obj.valid) {
let results = lib.features(obj, query)
if (results !== null) {
data.push(results)
}
}
console.timeEnd('> Search Features - Letter')
} else {
console.time('> Search Features')
for (let item of cache.keys()) {
let obj = loadDocument(item)
if (obj.valid) {
let results = lib.features(obj, query)
if (results !== null) {
data.push(results)
}
}
}
console.timeEnd('> Search Features')
}
res.send(data.sort(lib.compare))
console.timeEnd('> Search Features')
})
app.get('/api/letters/:letter?', function (req, res) {
......
......@@ -162,8 +162,8 @@ function metadataTable (objs) {
gender: meta.gender._text,
date: meta.date._text,
place: meta.place._text,
url: item.url,
link: item.link,
url: item.url,
link: item.link,
valid: true
})
} catch (err) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment