|
1 | 1 | const config = require('config') |
2 | 2 | const _ = require('lodash') |
| 3 | +const querystring = require('querystring') |
3 | 4 | const logger = require('../common/logger') |
4 | 5 | const groupApi = require('./group-api') |
5 | 6 | const appConst = require('../consts') |
@@ -735,7 +736,7 @@ function buildEsQueryToGetAttributeValues (attributeId, attributeValue, size) { |
735 | 736 | values: { |
736 | 737 | terms: { |
737 | 738 | field: USER_ATTRIBUTE.esDocumentValueQuery, |
738 | | - include: `.*${attributeValue.replace(/[A-Za-z]/g, c => `[${c.toLowerCase()}${c.toUpperCase()}]`)}.*`, |
| 739 | + include: `.*${attributeValue.replace(/[^a-zA-Z]+/gi, c => `[${c}]`).replace(/[A-Za-z]/g, c => `[${c.toLowerCase()}${c.toUpperCase()}]`)}.*`, |
739 | 740 | order: { |
740 | 741 | _key: 'asc' |
741 | 742 | }, |
@@ -1175,6 +1176,7 @@ async function searchUsers (authUser, filter, params) { |
1175 | 1176 |
|
1176 | 1177 | const authUserOrganizationId = filter.organizationId |
1177 | 1178 | const filterKey = Object.keys(userFilters) |
| 1179 | + |
1178 | 1180 | for (const key of filterKey) { |
1179 | 1181 | const resolved = await resolveUserFilterFromDb(userFilters[key], authUser, authUserOrganizationId) |
1180 | 1182 | resolvedUserFilters.push(resolved) |
@@ -1257,11 +1259,11 @@ async function searchUsers (authUser, filter, params) { |
1257 | 1259 | * @param {Object} param0 The attribute id and the attribute value properties |
1258 | 1260 | */ |
1259 | 1261 | async function searchAttributeValues ({ attributeId, attributeValue }) { |
1260 | | - const esQuery = buildEsQueryToGetAttributeValues(attributeId, attributeValue, 5) |
| 1262 | + const esQuery = buildEsQueryToGetAttributeValues(attributeId, querystring.unescape(attributeValue), 5) |
1261 | 1263 | logger.debug(`ES query for searching attribute values: ${JSON.stringify(esQuery, null, 2)}`) |
1262 | 1264 |
|
1263 | 1265 | const esResult = await esClient.search(esQuery) |
1264 | | - |
| 1266 | + logger.debug(`ES Result: ${JSON.stringify(esResult, null, 2)}`) |
1265 | 1267 | const result = [] |
1266 | 1268 | const attributes = esResult.aggregations.attributes.ids.buckets |
1267 | 1269 |
|
|
0 commit comments