@@ -14,6 +14,8 @@ import { Comparator } from 'cypher-query-builder/dist/typings/clauses/where-comp
14
14
import { identity , isFunction } from 'lodash' ;
15
15
import { AbstractClass , ConditionalKeys } from 'type-fest' ;
16
16
import { DateTimeFilter } from '~/common' ;
17
+ import { collect } from './cypher-functions' ;
18
+ import { escapeLuceneSyntax , FullTextIndex } from './full-text' ;
17
19
import { ACTIVE } from './matching' ;
18
20
import { WhereAndList } from './where-and-list' ;
19
21
import { path as pathPattern } from './where-path' ;
@@ -232,3 +234,35 @@ export const sub =
232
234
. return ( `true as ${ key } FiltersApplied` ) ,
233
235
)
234
236
. with ( '*' ) ;
237
+
238
+ export const fullText =
239
+ ( {
240
+ index,
241
+ matchToNode,
242
+ } : {
243
+ index : ( ) => FullTextIndex ;
244
+ matchToNode : ( query : Query ) => Query ;
245
+ } ) =>
246
+ < T , K extends ConditionalKeys < T , string | undefined > > ( {
247
+ value : input ,
248
+ key : field ,
249
+ query,
250
+ } : BuilderArgs < T , K > ) => {
251
+ if ( ! input || typeof input !== 'string' ) {
252
+ return null ;
253
+ }
254
+ const escaped = escapeLuceneSyntax ( input ) ;
255
+
256
+ const lucene = `*${ escaped } *` ;
257
+
258
+ query
259
+ . subQuery ( ( q ) =>
260
+ q
261
+ . call ( index ( ) . search ( lucene , { limit : 100 } ) . yield ( { node : 'match' } ) )
262
+ . apply ( matchToNode )
263
+ . return ( collect ( 'distinct node' ) . as ( `${ field } Matches` ) ) ,
264
+ )
265
+ . with ( '*' ) ;
266
+
267
+ return { node : inArray ( `${ field } Matches` , true ) } ;
268
+ } ;
0 commit comments