checkpoint

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-09-13 21:50:43 +02:00
parent 28ca1ff5de
commit 9479ce0f5c
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
13 changed files with 716 additions and 668 deletions

4
deploy/README.md Normal file
View File

@ -0,0 +1,4 @@
helm upgrade dev --set master.persistence.size=10Gi,data.persistence.size=10Gi,image.repository=anticrm/elasticsearch bitnami/elasticsearch
helm upgrade dev --set master.persistence.size=10Gi,data.persistence.size=10Gi,image.repository=anticrm/elasticsearch,ingest.enabled=true bitnami/elasticsearch

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -14,8 +14,8 @@
//
import type { Domain, Type, Ref } from '@anticrm/core'
import { DOMAIN_MODEL } from '@anticrm/core'
import { Builder, Model, Prop, TypeString, UX } from '@anticrm/model'
import { DOMAIN_MODEL, IndexKind } from '@anticrm/core'
import { Builder, Model, Prop, TypeString, UX, Index } from '@anticrm/model'
import type { IntlString, Asset } from '@anticrm/platform'
import core, { TAccount, TDoc, TType } from '@anticrm/model-core'
@ -53,6 +53,7 @@ export class TContact extends TDoc implements Contact {
@UX('Person' as IntlString)
export class TPerson extends TContact implements Person {
@Prop(TypeString(), 'First name' as IntlString)
@Index(IndexKind.FullText)
firstName!: string
@Prop(TypeString(), 'Last name' as IntlString)

View File

@ -36,6 +36,8 @@ export type ObjQueryType<T> = T | QuerySelector<T>
*/
export type DocumentQuery<T extends Doc> = {
[P in keyof T]?: ObjQueryType<T[P]>
} & {
$search?: string
}
/**

View File

@ -24,7 +24,7 @@
</script>
<div class="editbox" style={width ? 'width: ' + width : ''}>
<input type="text" bind:value {placeholder} />
<input type="text" bind:value {placeholder} on:change/>
<div class="icon">
{#if typeof (icon) === 'string'}
<Icon {icon} size={'small'} />

View File

@ -27,11 +27,12 @@
export let space: Ref<Space>
export let options: FindOptions<Doc> | undefined
export let config: string[]
export let search: string
let objects: Doc[]
const query = createQuery()
$: query.query(_class, { space }, result => { objects = result }, options)
$: query.query(_class, search === '' ? { space } : { $search: search }, result => { objects = result }, options)
function getValue(doc: Doc, key: string): any {
if (key.length === 0)

View File

@ -48,6 +48,12 @@ function onSpace(space: Ref<Space>) {
$: onSpace(space)
let search = ''
function onSearch(ev: Event) {
search = (ev.target as HTMLInputElement).value
}
</script>
{#await getViewlets(client, _class)}
@ -56,7 +62,7 @@ $: onSpace(space)
{#if viewlets.length > 0}
<div class="toolbar">
<EditWithIcon icon={IconSearch} placeholder={'Search for something'} />
<EditWithIcon icon={IconSearch} placeholder={'Search for something'} on:change={onSearch}/>
<div class="flex">
{#each viewlets as viewlet, i}
@ -75,7 +81,8 @@ $: onSpace(space)
space,
open: viewlets[selected].open,
options: viewlets[selected].options,
config: viewlets[selected].config
config: viewlets[selected].config,
search
} } />
</div>

View File

@ -14,14 +14,14 @@
// limitations under the License.
//
import type { TxCreateDoc, Doc, Ref, Class, Obj, Hierarchy, AnyAttribute } from '@anticrm/core'
import { TxProcessor, IndexKind } from '@anticrm/core'
import { TxCreateDoc, Doc, Ref, Class, Obj, Hierarchy, AnyAttribute, Storage, DocumentQuery, FindOptions, FindResult, TxProcessor, IndexKind } from '@anticrm/core'
import type { IndexedContent, FullTextAdapter } from './types'
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const NO_INDEX = {} as AnyAttribute
export class FullTextIndex extends TxProcessor {
export class FullTextIndex extends TxProcessor implements Storage {
private readonly indexes = new Map<Ref<Class<Obj>>, AnyAttribute>()
constructor (
@ -31,6 +31,13 @@ export class FullTextIndex extends TxProcessor {
super()
}
async findAll<T extends Doc> (_class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T>): Promise<FindResult<T>> {
console.log('search', query)
const docs = await this.adapter.search(query)
console.log('indexed docs', docs)
return []
}
private findFullTextAttribute (clazz: Ref<Class<Obj>>): AnyAttribute | undefined {
const attribute = this.indexes.get(clazz)
if (attribute === undefined) {

View File

@ -100,6 +100,10 @@ class TServerStorage implements ServerStorage {
options?: FindOptions<T>
): Promise<FindResult<T>> {
const domain = this.hierarchy.getDomain(clazz)
console.log('server findall', query)
if (Object.keys(query)[0] === '$search') {
return await this.fulltext.findAll(clazz, query, options)
}
return await this.getAdapter(domain).findAll(clazz, query, options)
}

View File

@ -14,7 +14,7 @@
// limitations under the License.
//
import type { FullTextAdapter, IndexedDoc, SearchQuery } from '@anticrm/server-core'
import type { FullTextAdapter, IndexedAttachment, IndexedDoc, SearchQuery } from '@anticrm/server-core'
import { Client } from '@elastic/elasticsearch'
@ -30,20 +30,39 @@ class ElasticAdapter implements FullTextAdapter {
): Promise<IndexedDoc[]> {
const result = await this.client.search({
index: this.db,
type: '_doc',
body: {
query: {
match: {
// content: query.$search,
'att.content': query.$search
}
}
}
})
console.log(result)
const hits = result.body.hits.hits as any[]
return hits.map(hit => hit._source)
}
async index (doc: IndexedDoc): Promise<void> {
await this.client.index({
index: this.db,
type: '_doc',
body: doc
})
console.log('eastic: index', doc)
if ((doc as IndexedAttachment).attachment === undefined) {
const resp = await this.client.index({
index: this.db,
type: '_doc',
body: doc
})
console.log(resp)
} else {
console.log('attachment pipeline')
const resp = await this.client.index({
index: this.db,
type: '_doc',
pipeline: 'attachment',
body: doc
})
console.log(resp)
}
}
}

View File

@ -8,7 +8,7 @@
"start": "ts-node src/__start.ts",
"build": "heft build",
"lint:fix": "eslint --fix src",
"bundle": "esbuild src/__start.ts --bundle --minify --platform=node > bundle.js",
"bundle": "esbuild src/__start.ts --bundle --platform=node > bundle.js",
"docker:build": "docker build -t anticrm/transactor .",
"docker:push": "docker push anticrm/transactor"
},

File diff suppressed because it is too large Load Diff