@@ -226,14 +226,48 @@ async function searchChallenges (currentUser, criteria) {
226
226
} )
227
227
}
228
228
229
+ const multiMatchQuery = [ ]
229
230
if ( criteria . search ) {
230
- boolQuery . push ( {
231
- bool : {
232
- should : [
233
- { match_phrase_prefix : { 'name' : criteria . search } } ,
234
- { match_phrase_prefix : { 'description' : criteria . search } } ,
235
- { match_phrase_prefix : { 'tags' : criteria . search } }
236
- ]
231
+ multiMatchQuery . push ( {
232
+ // exact match
233
+ multi_match : {
234
+ query : criteria . search ,
235
+ fields : [
236
+ 'name.text^7' ,
237
+ 'tags^3' ,
238
+ 'description^2'
239
+ ] ,
240
+ type : 'phrase_prefix' ,
241
+ boost : 5
242
+ }
243
+ } )
244
+ multiMatchQuery . push ( {
245
+ // match 100% words
246
+ multi_match : {
247
+ query : criteria . search ,
248
+ fields : [
249
+ 'name.text^3.0' ,
250
+ 'tags^2.5' ,
251
+ 'description^1.0'
252
+ ] ,
253
+ type : 'most_fields' ,
254
+ minimum_should_match : '100%' ,
255
+ boost : 2.5
256
+ }
257
+ } )
258
+ multiMatchQuery . push ( {
259
+ // fuzzy match
260
+ multi_match : {
261
+ query : criteria . search ,
262
+ fields : [
263
+ 'name.text^2.5' ,
264
+ 'tags^1.5' ,
265
+ 'description^1.0'
266
+ ] ,
267
+ type : 'most_fields' ,
268
+ minimum_should_match : '50%' ,
269
+ fuzziness : 'AUTO' ,
270
+ boost : 1
237
271
}
238
272
} )
239
273
} else {
@@ -538,6 +572,14 @@ async function searchChallenges (currentUser, criteria) {
538
572
} )
539
573
}
540
574
575
+ if ( multiMatchQuery ) {
576
+ mustQuery . push ( {
577
+ bool : {
578
+ should : multiMatchQuery
579
+ }
580
+ } )
581
+ }
582
+
541
583
if ( boolQuery . length > 0 ) {
542
584
mustQuery . push ( {
543
585
bool : {
@@ -872,9 +914,7 @@ async function createChallenge (currentUser, challenge) {
872
914
const { billingAccountId, markup } = await helper . getProjectBillingInformation ( _ . get ( challenge , 'projectId' ) )
873
915
if ( billingAccountId && _ . isUndefined ( _ . get ( challenge , 'billing.billingAccountId' ) ) ) {
874
916
_ . set ( challenge , 'billing.billingAccountId' , billingAccountId )
875
- }
876
- if ( markup && _ . isUndefined ( _ . get ( challenge , 'billing.markup' ) ) ) {
877
- _ . set ( challenge , 'billing.markup' , markup )
917
+ _ . set ( challenge , 'billing.markup' , markup || 0 )
878
918
}
879
919
if ( _ . get ( type , 'isTask' ) ) {
880
920
_ . set ( challenge , 'task.isTask' , true )
@@ -1066,7 +1106,7 @@ createChallenge.schema = {
1066
1106
value : Joi . number ( ) . min ( 0 ) . required ( )
1067
1107
} ) ) . min ( 1 ) . required ( )
1068
1108
} ) ) ,
1069
- tags : Joi . array ( ) . items ( Joi . string ( ) . required ( ) ) , // tag names
1109
+ tags : Joi . array ( ) . items ( Joi . string ( ) ) , // tag names
1070
1110
projectId : Joi . number ( ) . integer ( ) . positive ( ) . required ( ) ,
1071
1111
legacyId : Joi . number ( ) . integer ( ) . positive ( ) ,
1072
1112
startDate : Joi . date ( ) ,
@@ -1252,9 +1292,7 @@ async function update (currentUser, challengeId, data, isFull) {
1252
1292
const { billingAccountId, markup } = await helper . getProjectBillingInformation ( _ . get ( challenge , 'projectId' ) )
1253
1293
if ( billingAccountId && _ . isUndefined ( _ . get ( challenge , 'billing.billingAccountId' ) ) ) {
1254
1294
_ . set ( data , 'billing.billingAccountId' , billingAccountId )
1255
- }
1256
- if ( markup && _ . isUndefined ( _ . get ( challenge , 'billing.markup' ) ) ) {
1257
- _ . set ( data , 'billing.markup' , markup )
1295
+ _ . set ( data , 'billing.markup' , markup || 0 )
1258
1296
}
1259
1297
if ( data . status ) {
1260
1298
if ( data . status === constants . challengeStatuses . Active ) {
@@ -1853,7 +1891,7 @@ fullyUpdateChallenge.schema = {
1853
1891
url : Joi . string ( ) ,
1854
1892
options : Joi . array ( ) . items ( Joi . object ( ) )
1855
1893
} ) ) ,
1856
- tags : Joi . array ( ) . items ( Joi . string ( ) . required ( ) ) , // tag names
1894
+ tags : Joi . array ( ) . items ( Joi . string ( ) ) , // tag names
1857
1895
projectId : Joi . number ( ) . integer ( ) . positive ( ) . required ( ) ,
1858
1896
legacyId : Joi . number ( ) . integer ( ) . positive ( ) ,
1859
1897
startDate : Joi . date ( ) ,
0 commit comments