File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -82,5 +82,11 @@ export default {
82
82
} ,
83
83
procedure : async ( parent , { id } , { ProcedureModel } ) =>
84
84
ProcedureModel . findOne ( { procedureId : id } ) ,
85
+
86
+ searchProcedures : ( parent , { term } , { ProcedureModel } ) =>
87
+ ProcedureModel . find (
88
+ { $text : { $search : term } , period : 19 } ,
89
+ { score : { $meta : 'textScore' } } ,
90
+ ) . sort ( { score : { $meta : 'textScore' } } ) ,
85
91
} ,
86
92
} ;
Original file line number Diff line number Diff line change @@ -22,4 +22,5 @@ type Procedure {
22
22
type Query {
23
23
procedure (id : ID ! ): Procedure
24
24
procedures (type : ProcedureType ! , pageSize : Int , offset : Int ): [Procedure ]
25
+ searchProcedures (term : String ! ): [Procedure ]
25
26
}
Original file line number Diff line number Diff line change @@ -25,4 +25,30 @@ const ProcedureSchema = new Schema(
25
25
{ timestamps : true } ,
26
26
) ;
27
27
28
+ ProcedureSchema . index (
29
+ {
30
+ procedureId : 'text' ,
31
+ title : 'text' ,
32
+ abstract : 'text' ,
33
+ tags : 'text' ,
34
+ subjectGroups : 'text' ,
35
+ } ,
36
+ {
37
+ name : 'searchIndex' ,
38
+ default_language : 'german' ,
39
+ weights : {
40
+ title : 10 ,
41
+ abstract : 5 ,
42
+ } ,
43
+ } ,
44
+ ) ;
45
+
28
46
export default mongoose . model ( 'Procedure' , ProcedureSchema ) ;
47
+
48
+ mongoose . model ( 'Procedure' ) . ensureIndexes ( ( err ) => {
49
+ if ( ! err ) {
50
+ console . log ( 'SearchIndexs for Procedures created' ) ;
51
+ } else {
52
+ console . log ( { err } ) ;
53
+ }
54
+ } ) ;
You can’t perform that action at this time.
0 commit comments