Skip to content

Commit d489c7c

Browse files
committed
Add full text filter for organization name
1 parent aaa6b66 commit d489c7c

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/components/organization/dto/list-organization.dto.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InputType, ObjectType } from '@nestjs/graphql';
1+
import { Field, InputType, ObjectType } from '@nestjs/graphql';
22
import {
33
FilterField,
44
ID,
@@ -10,6 +10,11 @@ import { Organization } from './organization.dto';
1010

1111
@InputType()
1212
export abstract class OrganizationFilters {
13+
@Field({
14+
nullable: true,
15+
})
16+
readonly name?: string;
17+
1318
readonly userId?: ID;
1419
}
1520

src/components/organization/organization.repository.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import {
77
Session,
88
UnsecuredDto,
99
} from '~/common';
10-
import { DtoRepository } from '~/core/database';
10+
import { DtoRepository, OnIndex } from '~/core/database';
1111
import {
1212
ACTIVE,
1313
createNode,
1414
defineSorters,
1515
filter,
16+
FullTextIndex,
1617
matchProjectScopedRoles,
1718
matchProjectSens,
1819
matchProps,
@@ -140,6 +141,11 @@ export class OrganizationRepository extends DtoRepository<
140141
.apply(paginate(input, this.hydrate(session)));
141142
return (await query.first())!; // result from paginate() will always have 1 row.
142143
}
144+
145+
@OnIndex('schema')
146+
private async createSchemaIndexes() {
147+
await this.db.query().apply(OrgNameIndex.create()).run();
148+
}
143149
}
144150

145151
export const organizationFilters = filter.define(() => OrganizationFilters, {
@@ -148,6 +154,23 @@ export const organizationFilters = filter.define(() => OrganizationFilters, {
148154
relation('in', '', 'organization', ACTIVE),
149155
node('', 'User', { id }),
150156
]),
157+
name: filter.fullText({
158+
index: () => OrgNameIndex,
159+
matchToNode: (q) =>
160+
q.match([
161+
node('node', 'Organization'),
162+
relation('out', '', 'name', ACTIVE),
163+
node('match'),
164+
]),
165+
minScore: 0.8,
166+
}),
151167
});
152168

153169
export const organizationSorters = defineSorters(Organization, {});
170+
171+
const OrgNameIndex = FullTextIndex({
172+
indexName: 'OrganizationName',
173+
labels: 'OrgName',
174+
properties: 'value',
175+
analyzer: 'standard-folding',
176+
});

0 commit comments

Comments
 (0)