mirror of https://github.com/requarks/wiki
parent
17034040ac
commit
c87f4ce770
@ -1,16 +0,0 @@
|
||||
import { generateError, generateSuccess } from '../../helpers/graph.mjs'
|
||||
|
||||
export default {
|
||||
Mutation: {
|
||||
async rebuildSearchIndex (obj, args, context) {
|
||||
try {
|
||||
await WIKI.data.searchEngine.rebuild()
|
||||
return {
|
||||
responseResult: generateSuccess('Index rebuilt successfully')
|
||||
}
|
||||
} catch (err) {
|
||||
return generateError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
# ===============================================
|
||||
# SEARCH
|
||||
# ===============================================
|
||||
|
||||
extend type Mutation {
|
||||
rebuildSearchIndex: DefaultResponse
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# TYPES
|
||||
# -----------------------------------------------
|
@ -0,0 +1,13 @@
|
||||
export async function task (payload) {
|
||||
WIKI.logger.info('Refreshing autocomplete word index...')
|
||||
|
||||
try {
|
||||
await WIKI.db.pages.refreshAutocompleteIndex()
|
||||
|
||||
WIKI.logger.info('Refreshed autocomplete word index: [ COMPLETED ]')
|
||||
} catch (err) {
|
||||
WIKI.logger.error('Refreshing autocomplete word index: [ FAILED ]')
|
||||
WIKI.logger.error(err.message)
|
||||
throw err
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
import { pipeline } from 'node:stream/promises'
|
||||
import { Transform } from 'node:stream'
|
||||
|
||||
export async function task ({ payload }) {
|
||||
WIKI.logger.info('Rebuilding search index...')
|
||||
|
||||
try {
|
||||
await WIKI.ensureDb()
|
||||
|
||||
let idx = 0
|
||||
await pipeline(
|
||||
WIKI.db.knex.select('id', 'title', 'description', 'localeCode', 'render', 'password').from('pages').stream(),
|
||||
new Transform({
|
||||
objectMode: true,
|
||||
transform: async (page, enc, cb) => {
|
||||
idx++
|
||||
await WIKI.db.pages.updatePageSearchVector({ page })
|
||||
if (idx % 50 === 0) {
|
||||
WIKI.logger.info(`Rebuilding search index... (${idx} processed)`)
|
||||
}
|
||||
cb()
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
WIKI.logger.info('Refreshing autocomplete index...')
|
||||
await WIKI.db.pages.refreshAutocompleteIndex()
|
||||
|
||||
WIKI.logger.info('Rebuilt search index: [ COMPLETED ]')
|
||||
} catch (err) {
|
||||
WIKI.logger.error('Rebuilding search index: [ FAILED ]')
|
||||
WIKI.logger.error(err.message)
|
||||
throw err
|
||||
}
|
||||
}
|
Loading…
Reference in new issue