Include code snippets in full-text search (#6)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
2020-10-13 09:24:28 -05:00
parent 34586b3b90
commit 604753b3ff
4 changed files with 31 additions and 3 deletions

View File

@@ -66,7 +66,7 @@ class FormCode extends Controller {
if ( !code ) return res.status(404).message('Unable to find code with that ID.').api({})
code.code = req.body.code
code.language = req.body.language
code.Language = req.body.Language
code.NodeId = node.UUID
code.PageId = page.UUID
await code.save()

View File

@@ -32,6 +32,7 @@ class Misc extends Controller {
const Page = this.models.get('api:Page')
const Node = this.models.get('api:Node')
const Codium = this.models.get('api:Codium')
const all_user_page_ids = (await req.user.get_accessible_pages()).map(x => x.UUID)
const results = []
@@ -73,6 +74,27 @@ class Misc extends Controller {
})
}
const matching_codiums = await Codium.find({
PageId: { $in: all_user_page_ids },
$text: { $search: query },
});
for ( const codium of matching_codiums ) {
const page = await codium.page
results.push({
title: codium.code,
short_title: `${codium.code.slice(0, snip_length)}${codium.code.length > snip_length ? '...' : ''}`,
type: 'code',
id: codium.NodeId,
associated: {
title: page.Name,
short_title: `${page.Name.slice(0, snip_length)}${page.Name.length > snip_length ? '...' : ''}`,
type: 'page',
id: page.UUID,
}
})
}
return res.api({results})
}
}