@dpc-sdp/ripple-tide-search-api
Advanced tools
Comparing version 1.32.2 to 1.32.3
{ | ||
"name": "@dpc-sdp/ripple-tide-search-api", | ||
"version": "1.32.2", | ||
"version": "1.32.3", | ||
"description": "Ripple API endpoints for Tide search provider", | ||
@@ -33,3 +33,3 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "f2125672194ad6ef956753a73a5d4230344c8357" | ||
"gitHead": "d9ef69e64e1b9078903d78dc98400d29b6c2f3db" | ||
} |
@@ -27,3 +27,3 @@ import get from 'lodash.get' | ||
if (field) { | ||
if (field.length > 0 && field[0].length > 0) { | ||
if (field.length > 0 && field[0].length > 0 && Array.isArray(field)) { | ||
return field[0] | ||
@@ -105,1 +105,24 @@ } | ||
} | ||
export const getAggregations = (params) => { | ||
let aggs = {} | ||
if (params.aggs) { | ||
aggs = { | ||
...params.aggs.reduce((obj, agg) => { | ||
const isObject = typeof agg === 'object' && Object.keys(agg).length | ||
let key = isObject ? Object.keys(agg)[0] : agg | ||
let options = { field: key, size: 100 } | ||
// Optionally allow for aggs to be sorted by key | ||
if (isObject) { | ||
options.order = { '_key': Object.values(agg)[0] || 'asc' } | ||
} | ||
return { ...obj, [key]: { 'terms': { ...options } } } | ||
}, {}) | ||
} | ||
} | ||
return aggs | ||
} |
@@ -68,2 +68,6 @@ import { Client } from '@elastic/elasticsearch' | ||
getIndex (reqHeaders) { | ||
return reqHeaders?.['tide-api-search-index'] || this.index | ||
} | ||
async mapResults (res, templateName = null) { | ||
@@ -86,3 +90,3 @@ const totalhits = res.hits.total.hasOwnProperty('value') ? res.hits.total.value : res.hits.total | ||
} else if (typeof template.responseMapping === 'function') { | ||
result = template.responseMapping(hit) | ||
result = template.responseMapping(hit, result) | ||
} else if (typeof template.responseMapping === 'object') { | ||
@@ -115,2 +119,4 @@ result = await responseMappingByType(template.responseMapping, hit) | ||
async searchByTemplate (template, params, reqHeaders = {}, isDev) { | ||
const searchIndex = this.getIndex(reqHeaders) | ||
try { | ||
@@ -125,3 +131,3 @@ const headers = this.getHeaders(reqHeaders) | ||
const searchQuery = await this.getQuery(template, params) | ||
const { body, statusCode } = await this.search(searchQuery, reqConfig) | ||
const { body, statusCode } = await this.search(searchQuery, reqConfig, searchIndex) | ||
@@ -140,3 +146,4 @@ if (body && statusCode === 200) { | ||
message: `${error.message}`, | ||
meta: error.meta | ||
meta: error.meta, | ||
req: { reqHeaders, searchIndex } | ||
} | ||
@@ -154,4 +161,5 @@ } | ||
const searchQuery = reqBody | ||
const searchIndex = this.getIndex(reqHeaders) | ||
const { body, statusCode } = await this.search(searchQuery, reqConfig) | ||
const { body, statusCode } = await this.search(searchQuery, reqConfig, searchIndex) | ||
if (body && statusCode === 200) { | ||
@@ -158,0 +166,0 @@ return body |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36283
682