Fix documents search (#6818)

This commit is contained in:
Denis Bykhov 2024-10-07 07:59:34 +05:00 committed by GitHub
parent a78ec1bc19
commit c9a032eb0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 5 deletions

View File

@ -33,7 +33,7 @@ export function createModel (builder: Builder): void {
component: document.component.DocumentSearchIcon,
props: ['icon', 'color']
},
title: 'name'
title: 'title'
}
})
}

View File

@ -68,7 +68,7 @@ async function queryDocument (
search: string,
filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }
): Promise<ObjectSearchResult[]> {
const q: DocumentQuery<Document> = { name: { $like: `%${search}%` } }
const q: DocumentQuery<Document> = { title: { $like: `%${search}%` } }
if (filter?.in !== undefined || filter?.nin !== undefined) {
q._id = {}
if (filter.in !== undefined) {

View File

@ -22,8 +22,12 @@
const client = getClient()
function hasParent (doc: Doc | AttachedDoc): boolean {
return 'parent' in doc && doc.parent != null
}
async function getParents (doc: Doc | AttachedDoc): Promise<readonly Doc[]> {
if (!isAttachedDoc(doc)) {
if (!isAttachedDoc(doc) && !hasParent(doc)) {
return []
}
@ -31,8 +35,10 @@
let currentDoc: Doc | undefined = doc
while (currentDoc && isAttachedDoc(currentDoc)) {
const parent: Doc | undefined = await client.findOne(currentDoc.attachedToClass, { _id: currentDoc.attachedTo })
while (currentDoc && (isAttachedDoc(currentDoc) || hasParent(currentDoc))) {
const parent: Doc | undefined = isAttachedDoc(currentDoc)
? await client.findOne(currentDoc.attachedToClass, { _id: currentDoc.attachedTo })
: await client.findOne(currentDoc._class, { _id: (currentDoc as any).parent })
if (parent) {
currentDoc = parent