fix: broken draw io diagram on rtl mode, improve elasticsearch config (#2647)

* - Modify elastic settings
- Add tags field to index
- Modify elastic search query
- Remove empty entities from build suggests list

* Fix map parser error

* - Fix broken drawio svg diagram (rtl issue)

* - Restore the spaces in objects to respect the project formatting rules.
- Omit explanation line
This commit is contained in:
avioral 2020-11-02 18:58:12 +02:00 committed by NGPixel
parent a3513b1bdf
commit 089b7850d9
2 changed files with 36 additions and 29 deletions

View File

@ -583,6 +583,9 @@
.diagram { .diagram {
margin-top: 1rem; margin-top: 1rem;
svg:first-child {
direction: ltr;
}
} }
// --------------------------------- // ---------------------------------

View File

@ -57,11 +57,12 @@ module.exports = {
const idxBody = { const idxBody = {
properties: { properties: {
suggest: { type: 'completion' }, suggest: { type: 'completion' },
title: { type: 'text', boost: 4.0 }, title: { type: 'text', boost: 10.0 },
description: { type: 'text', boost: 3.0 }, description: { type: 'text', boost: 3.0 },
content: { type: 'text', boost: 1.0 }, content: { type: 'text', boost: 1.0 },
locale: { type: 'keyword' }, locale: { type: 'keyword' },
path: { type: 'text' } path: { type: 'text' },
tags: { type: 'text', boost: 8.0 }
} }
} }
await this.client.indices.create({ await this.client.indices.create({
@ -92,26 +93,11 @@ module.exports = {
index: this.config.indexName, index: this.config.indexName,
body: { body: {
query: { query: {
bool: {
filter: [
{
bool: {
should: [
{
simple_query_string: { simple_query_string: {
query: q query: `*${q}*`,
} fields: ['title^20', 'description^3', 'tags^8', 'content^1'],
}, default_operator: 'and',
{ analyze_wildcard: true
query_string: {
query: `*${q}*`
}
}
],
minimum_should_match: 1
}
}
]
} }
}, },
from: 0, from: 0,
@ -145,14 +131,26 @@ module.exports = {
WIKI.logger.warn('Search Engine Error: ', _.get(err, 'meta.body.error', err)) WIKI.logger.warn('Search Engine Error: ', _.get(err, 'meta.body.error', err))
} }
}, },
/**
* Build tags field
* @param id
* @returns {Promise<*|*[]>}
*/
async buildTags(id) {
const tags = await WIKI.models.pages.query().findById(id).select('*').withGraphJoined('tags')
return (tags.tags && tags.tags.length > 0) ? tags.tags.map(function (tag) {
return tag.title
}) : []
},
/** /**
* Build suggest field * Build suggest field
*/ */
buildSuggest(page) { buildSuggest(page) {
return _.uniq(_.concat( return _.reject(_.uniq(_.concat(
page.title.split(' ').map(s => ({ page.title.split(' ').map(s => ({
input: s, input: s,
weight: 4 weight: 10
})), })),
page.description.split(' ').map(s => ({ page.description.split(' ').map(s => ({
input: s, input: s,
@ -162,7 +160,7 @@ module.exports = {
input: s, input: s,
weight: 1 weight: 1
})) }))
)) )), ['input', ''])
}, },
/** /**
* CREATE * CREATE
@ -180,7 +178,8 @@ module.exports = {
path: page.path, path: page.path,
title: page.title, title: page.title,
description: page.description, description: page.description,
content: page.safeContent content: page.safeContent,
tags: await this.buildTags(page.id)
}, },
refresh: true refresh: true
}) })
@ -201,7 +200,8 @@ module.exports = {
path: page.path, path: page.path,
title: page.title, title: page.title,
description: page.description, description: page.description,
content: page.safeContent content: page.safeContent,
tags: await this.buildTags(page.id)
}, },
refresh: true refresh: true
}) })
@ -241,7 +241,8 @@ module.exports = {
path: page.destinationPath, path: page.destinationPath,
title: page.title, title: page.title,
description: page.description, description: page.description,
content: page.safeContent content: page.safeContent,
tags: await this.buildTags(page.id)
}, },
refresh: true refresh: true
}) })
@ -266,6 +267,7 @@ module.exports = {
if (doc) { if (doc) {
const docBytes = Buffer.from(JSON.stringify(doc)).byteLength const docBytes = Buffer.from(JSON.stringify(doc)).byteLength
doc['tags'] = await this.buildTags(doc.realId)
// -> Current batch exceeds size limit, flush // -> Current batch exceeds size limit, flush
if (docBytes + COMMA_BYTES + bytes >= MAX_INDEXING_BYTES) { if (docBytes + COMMA_BYTES + bytes >= MAX_INDEXING_BYTES) {
await flushBuffer() await flushBuffer()
@ -307,6 +309,7 @@ module.exports = {
doc.safeContent = WIKI.models.pages.cleanHTML(doc.render) doc.safeContent = WIKI.models.pages.cleanHTML(doc.render)
result.push({ result.push({
suggest: this.buildSuggest(doc), suggest: this.buildSuggest(doc),
tags: doc.tags,
locale: doc.locale, locale: doc.locale,
path: doc.path, path: doc.path,
title: doc.title, title: doc.title,
@ -324,8 +327,9 @@ module.exports = {
bytes = 0 bytes = 0
} }
// Added real id in order to fetch page tags from the query
await pipeline( await pipeline(
WIKI.models.knex.column({ id: 'hash' }, 'path', { locale: 'localeCode' }, 'title', 'description', 'render').select().from('pages').where({ WIKI.models.knex.column({ id: 'hash' }, 'path', { locale: 'localeCode' }, 'title', 'description', 'render', { realId: 'id' }).select().from('pages').where({
isPublished: true, isPublished: true,
isPrivate: false isPrivate: false
}).stream(), }).stream(),