mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 11:31:57 +03:00
Merge pull request #1003 from hcengineering/search_query_fix
Search query fix
This commit is contained in:
commit
cb313f9b93
@ -228,6 +228,15 @@ export class LiveQuery extends TxProcessor implements Client {
|
|||||||
}
|
}
|
||||||
const pos = q.result.findIndex((p) => p._id === tx.objectId)
|
const pos = q.result.findIndex((p) => p._id === tx.objectId)
|
||||||
if (pos !== -1) {
|
if (pos !== -1) {
|
||||||
|
// If query contains search we must check use fulltext
|
||||||
|
if (q.query.$search != null && q.query.$search.length > 0) {
|
||||||
|
const match = await this.findOne(q._class, { $search: q.query.$search, _id: tx.objectId }, q.options)
|
||||||
|
if (match === undefined) {
|
||||||
|
q.result.splice(pos, 1)
|
||||||
|
} else {
|
||||||
|
q.result[pos] = match
|
||||||
|
}
|
||||||
|
} else {
|
||||||
const updatedDoc = q.result[pos]
|
const updatedDoc = q.result[pos]
|
||||||
await this.__updateDoc(q, updatedDoc, tx)
|
await this.__updateDoc(q, updatedDoc, tx)
|
||||||
if (!this.match(q, updatedDoc)) {
|
if (!this.match(q, updatedDoc)) {
|
||||||
@ -235,8 +244,9 @@ export class LiveQuery extends TxProcessor implements Client {
|
|||||||
} else {
|
} else {
|
||||||
q.result[pos] = updatedDoc
|
q.result[pos] = updatedDoc
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.sort(q, tx)
|
this.sort(q, tx)
|
||||||
await this.callback(updatedDoc, q)
|
await this.callback(q.result[pos], q)
|
||||||
} else if (this.matchQuery(q, tx)) {
|
} else if (this.matchQuery(q, tx)) {
|
||||||
return await this.refresh(q)
|
return await this.refresh(q)
|
||||||
}
|
}
|
||||||
@ -383,6 +393,12 @@ export class LiveQuery extends TxProcessor implements Client {
|
|||||||
// No need to update, document already in results.
|
// No need to update, document already in results.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If query contains search we must check use fulltext
|
||||||
|
if (q.query.$search != null && q.query.$search.length > 0) {
|
||||||
|
const match = await this.findOne(q._class, { $search: q.query.$search, _id: doc._id }, q.options)
|
||||||
|
if (match === undefined) return
|
||||||
|
}
|
||||||
q.result.push(doc)
|
q.result.push(doc)
|
||||||
|
|
||||||
if (q.options?.sort !== undefined) {
|
if (q.options?.sort !== undefined) {
|
||||||
|
@ -16,17 +16,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Vacancy } from '@anticrm/recruit'
|
import type { Vacancy } from '@anticrm/recruit'
|
||||||
import recruit from '../plugin'
|
import recruit from '../plugin'
|
||||||
import { closeTooltip, Icon } from '@anticrm/ui'
|
import { Icon } from '@anticrm/ui'
|
||||||
import { showPanel } from '@anticrm/ui/src/panelup'
|
import { showPanel } from '@anticrm/ui/src/panelup'
|
||||||
import { createEventDispatcher } from 'svelte'
|
|
||||||
|
|
||||||
export let value: Vacancy
|
export let value: Vacancy
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
|
||||||
|
|
||||||
function show () {
|
function show () {
|
||||||
dispatch('click')
|
|
||||||
closeTooltip()
|
|
||||||
showPanel(recruit.component.EditVacancy, value._id, value._class, 'right')
|
showPanel(recruit.component.EditVacancy, value._id, value._class, 'right')
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -28,6 +28,7 @@ import core, {
|
|||||||
IndexKind,
|
IndexKind,
|
||||||
MeasureContext,
|
MeasureContext,
|
||||||
Obj,
|
Obj,
|
||||||
|
ObjQueryType,
|
||||||
PropertyType,
|
PropertyType,
|
||||||
Ref,
|
Ref,
|
||||||
Tx,
|
Tx,
|
||||||
@ -148,7 +149,8 @@ export class FullTextIndex implements WithFind {
|
|||||||
ids.add(doc.attachedTo)
|
ids.add(doc.attachedTo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return await this.dbStorage.findAll(ctx, _class, { _id: { $in: Array.from(ids) as any }, ...mainQuery }, options) // TODO: remove `as any`
|
const resultIds = getResultIds(ids, _id)
|
||||||
|
return await this.dbStorage.findAll(ctx, _class, { _id: { $in: resultIds }, ...mainQuery }, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
private getFullTextAttributes (clazz: Ref<Class<Obj>>, parentDoc?: Doc): AnyAttribute[] {
|
private getFullTextAttributes (clazz: Ref<Class<Obj>>, parentDoc?: Doc): AnyAttribute[] {
|
||||||
@ -309,3 +311,25 @@ function isFullTextAttribute (attr: AnyAttribute): boolean {
|
|||||||
(attr.type._class === core.class.TypeString || attr.type._class === core.class.TypeMarkup)
|
(attr.type._class === core.class.TypeString || attr.type._class === core.class.TypeMarkup)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getResultIds (ids: Set<Ref<Doc>>, _id: ObjQueryType<Ref<Doc>> | undefined): Ref<Doc>[] {
|
||||||
|
let result = []
|
||||||
|
if (_id !== undefined) {
|
||||||
|
if (typeof _id === 'string') {
|
||||||
|
if (!ids.has(_id)) {
|
||||||
|
return []
|
||||||
|
} else {
|
||||||
|
result = [_id]
|
||||||
|
}
|
||||||
|
} else if (_id.$in !== undefined) {
|
||||||
|
for (const id of _id.$in) {
|
||||||
|
if (ids.has(id)) {
|
||||||
|
result.push(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = Array.from(ids)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user