Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit d4340f1

Browse files
Only return unique values for attribute value lookups
1 parent 5b5ea93 commit d4340f1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/common/es-helper.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ function buildEsQueryFromFilter (filter) {
701701
* @param perPage maximum number of matches to return, defaults to 5
702702
* @return {{}} created ES query object
703703
*/
704-
function buildEsQueryToGetAttributeValues (attributeId, attributeValue, page = 1, perPage = 5) {
704+
function buildEsQueryToGetAttributeValues (attributeId, attributeValue, page = 1, perPage = config.PAGE_SIZE) {
705705
const queryDoc = DOCUMENTS.user
706706

707707
const matchConditions = [{
@@ -1290,11 +1290,15 @@ async function searchAttributeValues ({ attributeId, attributeValue }) {
12901290
logger.debug(`ES query for searching attribute values: ${JSON.stringify(esQuery, null, 2)}`)
12911291

12921292
const esResult = await esClient.search(esQuery)
1293-
const result = esResult.hits.hits.map(hit => {
1293+
1294+
let result = esResult.hits.hits.map(hit => {
12941295
return hit.inner_hits.attributes.hits.hits[0]._source
12951296
})
12961297

1297-
return { total: getTotalCount(esResult.hits.total), result: result }
1298+
result = _.uniqBy(result, 'value') // de-dupe by value
1299+
result = result.splice(0, 5) // keep only the first five matches
1300+
1301+
return { result }
12981302
}
12991303

13001304
module.exports = {

0 commit comments

Comments
 (0)