feat: postgres search engine

This commit is contained in:
Nick
2019-03-09 18:43:32 -05:00
parent b5db531234
commit ab42e5e1ab
8 changed files with 122 additions and 55 deletions

View File

@@ -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
*