@@ -13,7 +13,7 @@ const errors = require('../common/errors')
1313const JobService = require ( './JobService' )
1414const ResourceBookingService = require ( './ResourceBookingService' )
1515const HttpStatus = require ( 'http-status-codes' )
16- const { Op } = require ( 'sequelize' )
16+ const { Op, where , fn , col } = require ( 'sequelize' )
1717const models = require ( '../models' )
1818const stopWords = require ( '../../data/stopWords.json' )
1919const { getAuditM2Muser } = require ( '../common/helper' )
@@ -799,17 +799,30 @@ roleSearchRequest.schema = Joi.object()
799799 * @returns {Role } the best matching Role
800800 */
801801async function getRoleBySkills ( skills ) {
802+ // Case-insensitive search for roles matching any of the given skills
802803 const lowerCaseSkills = skills . map ( skill => skill . toLowerCase ( ) )
803- // find all roles which includes any of the given skills
804804 const queryCriteria = {
805- where : { listOfSkills : { [ Op . overlap ] : lowerCaseSkills } } ,
805+ where : where (
806+ fn (
807+ 'string_to_array' ,
808+ fn (
809+ 'lower' ,
810+ fn (
811+ 'array_to_string' ,
812+ col ( 'list_of_skills' ) ,
813+ ','
814+ )
815+ ) ,
816+ ','
817+ ) ,
818+ { [ Op . overlap ] : lowerCaseSkills } ) ,
806819 raw : true
807820 }
808821 const roles = await Role . findAll ( queryCriteria )
809822 if ( roles . length > 0 ) {
810823 let result = _ . each ( roles , role => {
811- // calculate each found roles matching rate
812- role . skillsMatch = _ . intersection ( role . listOfSkills , lowerCaseSkills ) . length / skills . length
824+ // calculate each found roles matching rate (must again be made case-insensitive)
825+ role . skillsMatch = _ . intersection ( role . listOfSkills . map ( skill => skill . toLowerCase ( ) ) , lowerCaseSkills ) . length / skills . length
813826 // each role can have multiple rates, get the maximum of global rates
814827 role . maxGlobal = _ . maxBy ( role . rates , 'global' ) . global
815828 } )
0 commit comments