Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charmingduchess committed Sep 13, 2024
1 parent 13a17b8 commit 9dce2e5
Show file tree
Hide file tree
Showing 32 changed files with 50,225 additions and 25 deletions.
17 changes: 11 additions & 6 deletions lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,12 @@ module.exports = function (app, _private = null) {
}
}
}
if (params.all_items) {
const paramsIncludesItemLevelFiltering = Object.keys(params)
.filter((param) => param.startsWith('item_')).length > 0
const returnAllItems = params.all_items && !paramsIncludesItemLevelFiltering
if (returnAllItems) {
body._source.excludes = EXCLUDE_FIELDS.filter((field) => field !== '*_sort')
}
if (!params.all_items) {
} else {
// No specific item requested, so add pagination and matching params:
const itemsOptions = {
size: params.items_size,
Expand Down Expand Up @@ -276,6 +278,9 @@ module.exports = function (app, _private = null) {
return app.esClient.search(body)
.then((resp) => {
resp = resp.body
const fs = require('fs')
fs.writeFileSync('spaghetti.txt', JSON.stringify(resp))

// Mindfully throw errors for known issues:
if (!resp || !resp.hits) {
throw new Error('Error connecting to index')
Expand Down Expand Up @@ -1218,9 +1223,9 @@ const buildElasticQueryForFilters = function (params) {
const buildElasticQuery = function (params) {
// Build ES query:
const query = {}

// clean up params
;['q'].forEach(function (param) {
const paramsArray = ['q']
// clean up params
paramsArray.forEach(function (param) {
if (params[param]) {
params[param] = params[param].replace(/date:/g, 'dateStartYear:')
params[param] = params[param].replace(/location:/g, 'locations:')
Expand Down
8 changes: 6 additions & 2 deletions lib/response_massager.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ class ResponseMassager {

massagedResponse (request, options = {}) {
let response = this.elasticSearchResponse
const allItemsBibQuery = request?.query?.all_items
const queryKeys = Object.keys(request?.params || {})
const itemFilterQuery = queryKeys
.filter((param) => param.startsWith('item_')).length > 0
const returnAllItems = queryKeys?.includes('all_items') &&
!itemFilterQuery
// Inspect response inner_hits queries and move properties around to ease
// serialization:
response = this.processInnerHitsProperties(response, allItemsBibQuery)
response = this.processInnerHitsProperties(response, returnAllItems)

// Rename parallel fields:
response = parallelFieldsExtractor(response)
Expand Down
Loading

0 comments on commit 9dce2e5

Please sign in to comment.