2019-03-24 04:27:42 +00:00
|
|
|
/* global WIKI */
|
2019-03-09 05:51:02 +00:00
|
|
|
|
2018-09-01 03:42:14 +00:00
|
|
|
module.exports = {
|
|
|
|
activate() {
|
2019-03-09 05:51:02 +00:00
|
|
|
// not used
|
2018-09-01 03:42:14 +00:00
|
|
|
},
|
|
|
|
deactivate() {
|
2019-03-09 05:51:02 +00:00
|
|
|
// not used
|
2018-09-01 03:42:14 +00:00
|
|
|
},
|
2019-03-09 05:51:02 +00:00
|
|
|
/**
|
|
|
|
* INIT
|
|
|
|
*/
|
|
|
|
init() {
|
|
|
|
// not used
|
2018-09-01 03:42:14 +00:00
|
|
|
},
|
2019-03-09 05:51:02 +00:00
|
|
|
/**
|
|
|
|
* QUERY
|
|
|
|
*
|
|
|
|
* @param {String} q Query
|
|
|
|
* @param {Object} opts Additional options
|
|
|
|
*/
|
|
|
|
async query(q, opts) {
|
|
|
|
const results = await WIKI.models.pages.query()
|
2020-09-13 17:53:31 +00:00
|
|
|
.column('pages.id', 'title', 'description', 'path', 'localeCode as locale')
|
|
|
|
.withGraphJoined('tags') // Adding page tags since they can be used to check resource access permissions
|
|
|
|
.modifyGraph('tags', builder => {
|
|
|
|
builder.select('tag')
|
|
|
|
})
|
2019-03-09 05:51:02 +00:00
|
|
|
.where(builder => {
|
|
|
|
builder.where('isPublished', true)
|
|
|
|
if (opts.locale) {
|
|
|
|
builder.andWhere('localeCode', opts.locale)
|
|
|
|
}
|
|
|
|
if (opts.path) {
|
|
|
|
builder.andWhere('path', 'like', `${opts.path}%`)
|
|
|
|
}
|
2019-09-08 16:39:05 +00:00
|
|
|
builder.andWhere(builderSub => {
|
2019-11-02 20:04:43 +00:00
|
|
|
if (WIKI.config.db.type === 'postgres') {
|
|
|
|
builderSub.where('title', 'ILIKE', `%${q}%`)
|
|
|
|
builderSub.orWhere('description', 'ILIKE', `%${q}%`)
|
2020-04-11 04:19:23 +00:00
|
|
|
builderSub.orWhere('path', 'ILIKE', `%${q.toLowerCase()}%`)
|
2019-11-02 20:04:43 +00:00
|
|
|
} else {
|
|
|
|
builderSub.where('title', 'LIKE', `%${q}%`)
|
|
|
|
builderSub.orWhere('description', 'LIKE', `%${q}%`)
|
2020-04-11 04:19:23 +00:00
|
|
|
builderSub.orWhere('path', 'LIKE', `%${q.toLowerCase()}%`)
|
2019-03-09 05:51:02 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.limit(WIKI.config.search.maxHits)
|
|
|
|
return {
|
|
|
|
results,
|
|
|
|
suggestions: [],
|
|
|
|
totalHits: results.length
|
|
|
|
}
|
2018-09-01 03:42:14 +00:00
|
|
|
},
|
2019-03-09 05:51:02 +00:00
|
|
|
/**
|
|
|
|
* CREATE
|
|
|
|
*
|
|
|
|
* @param {Object} page Page to create
|
|
|
|
*/
|
|
|
|
async created(page) {
|
|
|
|
// not used
|
2018-09-01 03:42:14 +00:00
|
|
|
},
|
2019-03-09 05:51:02 +00:00
|
|
|
/**
|
|
|
|
* UPDATE
|
|
|
|
*
|
|
|
|
* @param {Object} page Page to update
|
|
|
|
*/
|
|
|
|
async updated(page) {
|
|
|
|
// not used
|
2018-09-01 03:42:14 +00:00
|
|
|
},
|
2019-03-09 05:51:02 +00:00
|
|
|
/**
|
|
|
|
* DELETE
|
|
|
|
*
|
|
|
|
* @param {Object} page Page to delete
|
|
|
|
*/
|
|
|
|
async deleted(page) {
|
|
|
|
// not used
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* RENAME
|
|
|
|
*
|
|
|
|
* @param {Object} page Page to rename
|
|
|
|
*/
|
|
|
|
async renamed(page) {
|
|
|
|
// not used
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* REBUILD INDEX
|
|
|
|
*/
|
|
|
|
async rebuild() {
|
|
|
|
// not used
|
2018-09-01 03:42:14 +00:00
|
|
|
}
|
|
|
|
}
|