diff --git a/lib/elasticsearch/config.js b/lib/elasticsearch/config.js index 8dbb7af..79d7524 100644 --- a/lib/elasticsearch/config.js +++ b/lib/elasticsearch/config.js @@ -1,3 +1,5 @@ +const util = require('../util') + // Configure search scopes: const SEARCH_SCOPES = { all: { @@ -78,17 +80,11 @@ const FILTER_CONFIG = { owner: { operator: 'match', field: ['items.owner.id', 'items.owner.label'], repeatable: true, path: 'items' }, subjectLiteral: { transform: (val, logger) => { - const removePeriod = (x) => { - if (x.slice(-1) === '.') { - logger.debug('Removing terminal period', JSON.stringify(val, null, 4)) - return x.slice(0, -1) - } else return x - } if (typeof val === 'string') { - return removePeriod(val) + return util.removeTrailingPeriod(val, logger) } if (Array.isArray(val)) { - return val.map(removePeriod) + return val.map((val) => util.removeTrailingPeriod(val, logger)) } }, operator: 'match', diff --git a/lib/util.js b/lib/util.js index f0da4ef..636d95b 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,6 +1,13 @@ const logger = require('./logger') const { isItemNyplOwned } = require('./ownership_determination') +exports.removeTrailingPeriod = (x, logger) => { + if (x.slice(-1) === '.') { + logger.debug('Removing terminal period', JSON.stringify(x, null, 4)) + return x.slice(0, -1) + } else return x +} + exports.sortOnPropWithUndefinedLast = (property) => { return function (a, b) { // equal items sort equally