@@ -7,12 +7,13 @@ import {
7
7
Session ,
8
8
UnsecuredDto ,
9
9
} from '~/common' ;
10
- import { DtoRepository } from '~/core/database' ;
10
+ import { DtoRepository , OnIndex } from '~/core/database' ;
11
11
import {
12
12
ACTIVE ,
13
13
createNode ,
14
14
defineSorters ,
15
15
filter ,
16
+ FullTextIndex ,
16
17
matchProjectScopedRoles ,
17
18
matchProjectSens ,
18
19
matchProps ,
@@ -140,6 +141,11 @@ export class OrganizationRepository extends DtoRepository<
140
141
. apply ( paginate ( input , this . hydrate ( session ) ) ) ;
141
142
return ( await query . first ( ) ) ! ; // result from paginate() will always have 1 row.
142
143
}
144
+
145
+ @OnIndex ( 'schema' )
146
+ private async createSchemaIndexes ( ) {
147
+ await this . db . query ( ) . apply ( OrgNameIndex . create ( ) ) . run ( ) ;
148
+ }
143
149
}
144
150
145
151
export const organizationFilters = filter . define ( ( ) => OrganizationFilters , {
@@ -148,6 +154,23 @@ export const organizationFilters = filter.define(() => OrganizationFilters, {
148
154
relation ( 'in' , '' , 'organization' , ACTIVE ) ,
149
155
node ( '' , 'User' , { id } ) ,
150
156
] ) ,
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
+ } ) ,
151
167
} ) ;
152
168
153
169
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