diff --git a/src/services/JobService.js b/src/services/JobService.js index cdc22a72..4013bd97 100644 --- a/src/services/JobService.js +++ b/src/services/JobService.js @@ -456,8 +456,7 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false } query: { bool: { must: [], - filter: [], - should: [] + filter: [] } }, from: (page - 1) * perPage, @@ -480,7 +479,8 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false } 'title', 'status', 'minSalary', - 'maxSalary' + 'maxSalary', + 'jobLocation' ]), (value, key) => { let must if (key === 'description' || key === 'title') { @@ -497,6 +497,12 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false } [`${key}s`]: [value] } } + } else if (key === 'jobLocation' && value && value.length > 0) { + must = { + wildcard: { + [key]: `*${value}*` + } + } } else if (key === 'minSalary' || key === 'maxSalary') { const salaryOp = key === 'minSalary' ? 'gte' : 'lte' must = { @@ -517,27 +523,6 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false } } esQuery.body.query.bool.must.push(must) }) - // If criteria contains jobLocation, filter jobLocation with this value - if (criteria.jobLocation) { - // filter out null value - esQuery.body.query.bool.should.push({ - bool: { - must: [ - { - exists: { - field: 'jobLocation' - } - } - ] - } - }) - // filter the jobLocation - esQuery.body.query.bool.should.push({ - term: { - jobLocation: criteria.jobLocation - } - }) - } // If criteria contains projectIds, filter projectId with this value if (criteria.projectIds) { esQuery.body.query.bool.filter.push({