Skip to content

Commit 38c0931

Browse files
committed
Add UserFilters.name
1 parent fe70d06 commit 38c0931

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

src/components/user/dto/list-users.dto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { User } from './user.dto';
44

55
@InputType()
66
export abstract class UserFilters {
7+
@Field({
8+
nullable: true,
9+
})
10+
readonly name?: string;
11+
712
@Field({
813
description: 'Only users that are pinned/unpinned by the requesting user',
914
nullable: true,

src/components/user/user.repository.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import {
1010
Session,
1111
UnsecuredDto,
1212
} from '~/common';
13-
import { DtoRepository, UniquenessError } from '~/core/database';
13+
import { DtoRepository, OnIndex, UniquenessError } from '~/core/database';
1414
import {
1515
ACTIVE,
1616
createNode,
1717
createProperty,
1818
deactivateProperty,
1919
defineSorters,
2020
filter,
21+
FullTextIndex,
2122
matchProps,
2223
merge,
2324
paginate,
@@ -32,6 +33,7 @@ import {
3233
SystemAgent,
3334
UpdateUser,
3435
User,
36+
UserFilters,
3537
UserListInput,
3638
} from './dto';
3739

@@ -224,11 +226,7 @@ export class UserRepository extends DtoRepository<typeof User, [Session | ID]>(
224226
.query()
225227
.matchNode('node', 'User')
226228
.match(requestingUser(session))
227-
.apply(
228-
filter.builder(input.filter ?? {}, {
229-
pinned: filter.isPinned,
230-
}),
231-
)
229+
.apply(userFilters(input.filter))
232230
.apply(this.privileges.forUser(session).filterToReadable())
233231
.apply(sortWith(userSorters, input))
234232
.apply(paginate(input, this.hydrate(session.userId)))
@@ -364,6 +362,36 @@ export class UserRepository extends DtoRepository<typeof User, [Session | ID]>(
364362
hydrateAsNeo4j(session: Session | ID) {
365363
return this.hydrate(session);
366364
}
365+
366+
@OnIndex('schema')
367+
private async createSchemaIndexes() {
368+
await this.db.query().apply(NameIndex.create()).run();
369+
}
367370
}
368371

372+
export const userFilters = filter.define(() => UserFilters, {
373+
pinned: filter.isPinned,
374+
name: filter.fullText({
375+
index: () => NameIndex,
376+
matchToNode: (q) =>
377+
q.match([
378+
node('node', 'User'),
379+
relation('out', '', undefined, ACTIVE),
380+
node('match'),
381+
]),
382+
// Treat each word as a separate search term
383+
// Each word could point to a different node
384+
// i.e. "first last"
385+
separateQueryForEachWord: true,
386+
minScore: 0.9,
387+
}),
388+
});
389+
369390
export const userSorters = defineSorters(User, {});
391+
392+
const NameIndex = FullTextIndex({
393+
indexName: 'UserName',
394+
labels: 'UserName',
395+
properties: 'value',
396+
analyzer: 'standard-folding',
397+
});

0 commit comments

Comments
 (0)