feat: postgres search engine
This commit is contained in:
@@ -13,28 +13,6 @@ module.exports = {
|
||||
init() {
|
||||
// not used
|
||||
},
|
||||
/**
|
||||
* SUGGEST
|
||||
*
|
||||
* @param {String} q Query
|
||||
* @param {Object} opts Additional options
|
||||
*/
|
||||
async suggest(q, opts) {
|
||||
const results = await WIKI.models.pages.query()
|
||||
.column('title')
|
||||
.where(builder => {
|
||||
builder.where('isPublished', true)
|
||||
if (opts.locale) {
|
||||
builder.andWhere('locale', opts.locale)
|
||||
}
|
||||
if (opts.path) {
|
||||
builder.andWhere('path', 'like', `${opts.path}%`)
|
||||
}
|
||||
builder.andWhere('title', 'like', `%${q}%`)
|
||||
})
|
||||
.limit(10)
|
||||
return _.uniq(_.filter(_.flatten(results.map(r => r.title.split(' '))), w => w.indexOf(q) >= 0))
|
||||
},
|
||||
/**
|
||||
* QUERY
|
||||
*
|
||||
|
Reference in New Issue
Block a user