@@ -80,7 +80,6 @@ export class MappingService {
80
80
} else {
81
81
result = fromTo == "from" ? "to" : "from"
82
82
}
83
- count -= 1
84
83
return result
85
84
}
86
85
// Converts value to regex object for MongoDB if it ends with `*`.
@@ -121,10 +120,12 @@ export class MappingService {
121
120
}
122
121
123
122
// Handle from/fromScheme/to/toScheme here
124
- let criteria = [ "from" , "to" ] . map ( part => {
125
- count = direction == "both" ? 2 : 1
126
- let or = [ ]
127
- while ( count > 0 ) {
123
+ let criteria = [ ]
124
+ let or = [ ]
125
+ count = direction == "both" ? 2 : 1
126
+ while ( count > 0 ) {
127
+ let and = [ ]
128
+ for ( const part of [ "from" , "to" ] ) {
128
129
const conceptOr = [ ] , schemeOr = [ ]
129
130
// Depending on `count` and `direction`, the value of `side` will either be "from" or "to"
130
131
const side = fromTo ( part )
@@ -148,16 +149,21 @@ export class MappingService {
148
149
schemeOr . push ( { [ `${ side } Scheme.uri` ] : uri } )
149
150
schemeOr . push ( { [ `${ side } Scheme.notation` ] : uri } )
150
151
}
151
- if ( conceptOr . length && schemeOr . length ) {
152
- or . push ( { $and : [ { $or : conceptOr } , { $or : schemeOr } ] } )
153
- } else if ( conceptOr . length ) {
154
- or = or . concat ( conceptOr )
155
- } else if ( schemeOr . length ) {
156
- or = or . concat ( schemeOr )
152
+ if ( conceptOr . length ) {
153
+ and . push ( { $or : conceptOr } )
154
+ }
155
+ if ( schemeOr . length ) {
156
+ and . push ( { $or : schemeOr } )
157
157
}
158
158
}
159
- return { $or : or }
160
- } ) . filter ( entry => entry . $or . length > 0 )
159
+ if ( and . length ) {
160
+ or . push ( { $and : and } )
161
+ }
162
+ count -= 1
163
+ }
164
+ if ( or . length ) {
165
+ criteria . push ( { $or : or } )
166
+ }
161
167
if ( identifier ) {
162
168
// Add identifier to criteria
163
169
criteria . push ( { $or : identifier . split ( "|" ) . map ( id => ( { $or : [ { identifier : id } , { uri : id } ] } ) ) } )
0 commit comments