feat: Improved search results when finding links in document editor (#1573)

* feat: Improved search results when finding links in document editor

* chore(deps): Bump RME for smoother link search
This commit is contained in:
Tom Moor
2020-09-26 11:07:49 -07:00
committed by GitHub
parent 6f1f855083
commit f1a95e5e79
6 changed files with 131 additions and 15 deletions

View File

@ -551,6 +551,52 @@ router.post("documents.restore", auth(), async (ctx) => {
};
});
router.post("documents.search_titles", auth(), pagination(), async (ctx) => {
const { query } = ctx.body;
const { offset, limit } = ctx.state.pagination;
const user = ctx.state.user;
ctx.assertPresent(query, "query is required");
const collectionIds = await user.collectionIds();
const documents = await Document.scope(
{
method: ["withViews", user.id],
},
{
method: ["withCollection", user.id],
}
).findAll({
where: {
title: {
[Op.iLike]: `%${query}%`,
},
collectionId: collectionIds,
archivedAt: {
[Op.eq]: null,
},
},
order: [["updatedAt", "DESC"]],
include: [
{ model: User, as: "createdBy", paranoid: false },
{ model: User, as: "updatedBy", paranoid: false },
],
offset,
limit,
});
const policies = presentPolicies(user, documents);
const data = await Promise.all(
documents.map((document) => presentDocument(document))
);
ctx.body = {
pagination: ctx.state.pagination,
data,
policies,
};
});
router.post("documents.search", auth(), pagination(), async (ctx) => {
const {
query,