mirror of
https://github.com/urbit/developers.urbit.org.git
synced 2024-08-17 01:30:31 +03:00
api/search: return pair of glossary and search results
This commit is contained in:
parent
dbd73ba7d1
commit
40c9708dc9
@ -1,15 +0,0 @@
|
||||
import { glossary } from "../../lib/glossary";
|
||||
const levenSort = require("leven-sort");
|
||||
|
||||
export default (req, res) => {
|
||||
const entries = glossary.filter((entry) => {
|
||||
return (
|
||||
entry.name.includes(req.query.q.toLowerCase()) ||
|
||||
entry.symbol.includes(req.query.q)
|
||||
);
|
||||
});
|
||||
const sorted = levenSort(entries, req.query.q, ["symbol"]);
|
||||
res.statusCode = 200;
|
||||
res.setHeader("Content-Type", "application/json");
|
||||
res.end(JSON.stringify({ results: sorted }));
|
||||
};
|
@ -1,4 +1,5 @@
|
||||
import { index } from "../../cache/data";
|
||||
import { glossary } from "../../cache/glossary";
|
||||
const levenSort = require("leven-sort");
|
||||
|
||||
export default (req, res) => {
|
||||
@ -24,6 +25,15 @@ export default (req, res) => {
|
||||
.map((e) => ({ ...e, foundOnPage: true }))
|
||||
);
|
||||
|
||||
const entries = glossary.filter((entry) => {
|
||||
return (
|
||||
entry.name.includes(req.query.q.toLowerCase()) ||
|
||||
entry.symbol.includes(req.query.q)
|
||||
);
|
||||
});
|
||||
const sortedEntries = levenSort(entries, req.query.q, ["symbol"]);
|
||||
|
||||
|
||||
const sorted = levenSort(results, req.q, [
|
||||
"title",
|
||||
"slug",
|
||||
@ -32,5 +42,5 @@ export default (req, res) => {
|
||||
]);
|
||||
res.statusCode = 200;
|
||||
res.setHeader("Content-Type", "application/json");
|
||||
res.end(JSON.stringify({ results: sorted }));
|
||||
res.end(JSON.stringify({ results: sorted, glossary: sortedEntries }));
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user