Include code snippets in full-text search (#6)
This commit is contained in:
parent
34586b3b90
commit
604753b3ff
@ -43,8 +43,10 @@ class IonicUnit extends Unit {
|
|||||||
|
|
||||||
const databases = this.scaffold.collection('api_db_Database')
|
const databases = this.scaffold.collection('api_db_Database')
|
||||||
await databases.createIndex({ Name: 'text' })
|
await databases.createIndex({ Name: 'text' })
|
||||||
}
|
|
||||||
|
|
||||||
|
const codiums = this.scaffold.collection('api_Codium')
|
||||||
|
await codiums.createIndex({ code: 'text' })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = exports = IonicUnit
|
module.exports = exports = IonicUnit
|
||||||
|
@ -66,7 +66,7 @@ class FormCode extends Controller {
|
|||||||
if ( !code ) return res.status(404).message('Unable to find code with that ID.').api({})
|
if ( !code ) return res.status(404).message('Unable to find code with that ID.').api({})
|
||||||
|
|
||||||
code.code = req.body.code
|
code.code = req.body.code
|
||||||
code.language = req.body.language
|
code.Language = req.body.Language
|
||||||
code.NodeId = node.UUID
|
code.NodeId = node.UUID
|
||||||
code.PageId = page.UUID
|
code.PageId = page.UUID
|
||||||
await code.save()
|
await code.save()
|
||||||
|
@ -32,6 +32,7 @@ class Misc extends Controller {
|
|||||||
|
|
||||||
const Page = this.models.get('api:Page')
|
const Page = this.models.get('api:Page')
|
||||||
const Node = this.models.get('api:Node')
|
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 all_user_page_ids = (await req.user.get_accessible_pages()).map(x => x.UUID)
|
||||||
const results = []
|
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})
|
return res.api({results})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ class Codium extends Model {
|
|||||||
static get schema() {
|
static get schema() {
|
||||||
// Return a flitter-orm schema here.
|
// Return a flitter-orm schema here.
|
||||||
return {
|
return {
|
||||||
language: {type: String, default: 'javascript'},
|
Language: {type: String, default: 'javascript'},
|
||||||
NodeId: String,
|
NodeId: String,
|
||||||
PageId: String,
|
PageId: String,
|
||||||
code: String,
|
code: String,
|
||||||
@ -19,6 +19,10 @@ class Codium extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Static and instance methods can go here
|
// Static and instance methods can go here
|
||||||
|
get page() {
|
||||||
|
const Page = require('./Page.model')
|
||||||
|
return this.belongs_to_one(Page, 'PageId', 'UUID')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = exports = Codium
|
module.exports = exports = Codium
|
||||||
|
Loading…
Reference in New Issue
Block a user