Skip to content

Commit 79ab857

Browse files
committed
Add fulltext index & filter for project name
1 parent 11ffadc commit 79ab857

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/components/project/dto/list-projects.dto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import {
2323

2424
@InputType()
2525
export abstract class ProjectFilters {
26+
@Field({
27+
nullable: true,
28+
})
29+
readonly name?: string;
30+
2631
@Field(() => [ProjectType], {
2732
description: 'Only projects of these types',
2833
nullable: true,

src/components/project/project-filters.query.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import { greaterThan, inArray, node, relation } from 'cypher-query-builder';
22
import { ACTIVE, filter, matchProjectSens, path } from '~/core/database/query';
33
import { ProjectFilters } from './dto';
4+
import { ProjectNameIndex } from './project.repository';
45

56
export const projectFilters = filter.define(() => ProjectFilters, {
7+
name: filter.fullText({
8+
index: () => ProjectNameIndex,
9+
matchToNode: (q) =>
10+
q.match([
11+
node('node', 'Project'),
12+
relation('out', '', 'name', ACTIVE),
13+
node('match'),
14+
]),
15+
}),
616
type: filter.stringListBaseNodeProp(),
717
status: filter.stringListProp(),
818
onlyMultipleEngagements:

src/components/project/project.repository.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
createNode,
1818
createRelationships,
1919
defineSorters,
20+
FullTextIndex,
2021
matchChangesetAndChangedProps,
2122
matchProjectSens,
2223
matchPropsAndProjectSensAndScopedRoles,
@@ -323,8 +324,19 @@ export class ProjectRepository extends CommonRepository {
323324
private createIndexes() {
324325
return this.getConstraintsFor(IProject);
325326
}
327+
@OnIndex('schema')
328+
private async createSchemaIndexes() {
329+
await this.db.query().apply(ProjectNameIndex.create()).run();
330+
}
326331
}
327332

333+
export const ProjectNameIndex = FullTextIndex({
334+
indexName: 'ProjectName',
335+
labels: 'ProjectName',
336+
properties: 'value',
337+
analyzer: 'standard-folding',
338+
});
339+
328340
export const projectSorters = defineSorters(IProject, {
329341
sensitivity: (query) =>
330342
query

0 commit comments

Comments
 (0)