@@ -16,6 +16,7 @@ import { identity, isFunction } from 'lodash';
16
16
import { AbstractClass , ConditionalKeys } from 'type-fest' ;
17
17
import { DateTimeFilter } from '~/common' ;
18
18
import { variable } from '../query-augmentation/condition-variables' ;
19
+ import { intersects } from './comparators' ;
19
20
import { collect } from './cypher-functions' ;
20
21
import { escapeLuceneSyntax , FullTextIndex } from './full-text' ;
21
22
import { ACTIVE } from './matching' ;
@@ -132,6 +133,20 @@ export const propPartialVal =
132
133
return { [ prop ?? key ] : { value : regexp ( `.*${ value } .*` , true ) } } ;
133
134
} ;
134
135
136
+ export const intersectsProp =
137
+ < T , K extends ConditionalKeys < Required < T > , readonly string [ ] > > (
138
+ prop ?: string ,
139
+ ) : Builder < T , K > =>
140
+ ( { key, value, query } ) => {
141
+ prop ??= key ;
142
+ query . match ( [
143
+ node ( 'node' ) ,
144
+ relation ( 'out' , '' , prop , ACTIVE ) ,
145
+ node ( prop , 'Property' ) ,
146
+ ] ) ;
147
+ return { [ `${ prop } .value` ] : intersects ( value as readonly string [ ] , prop ) } ;
148
+ } ;
149
+
135
150
export const stringListProp =
136
151
< T , K extends ConditionalKeys < Required < T > , readonly string [ ] > > (
137
152
prop ?: string ,
@@ -234,7 +249,11 @@ export const sub =
234
249
sub
235
250
. apply ( matchSubNode )
236
251
. apply ( subBuilder ( ) ( value ) )
237
- . return ( `true as ${ key } FiltersApplied` ) ,
252
+ . return ( `true as ${ key } FiltersApplied` )
253
+ // Prevent filter from increasing cardinality above 1.
254
+ // This happens with `1-Many` relationships matched in `matchSubNode`.
255
+ // Note they are allowed to reduce cardinality to 0.
256
+ . raw ( 'limit 1' ) ,
238
257
)
239
258
. with ( '*' ) ;
240
259
0 commit comments