From 2c6a93099e417f3c5cfd56e79f2c48508320e760 Mon Sep 17 00:00:00 2001 From: Stefan Peters Date: Thu, 21 Apr 2022 11:11:43 +0200 Subject: [PATCH] Creator search: Don't search labels when searching for URIs (#170) --- services/annotations.js | 7 ++++++- services/concordances.js | 7 ++++++- services/mappings.js | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/services/annotations.js b/services/annotations.js index 0e7b2be..5bc63aa 100644 --- a/services/annotations.js +++ b/services/annotations.js @@ -1,4 +1,5 @@ const config = require("../config") +const jskos = require("jskos-tools") const utils = require("../utils") const _ = require("lodash") const validate = require("jskos-validate") @@ -32,7 +33,11 @@ module.exports = class MappingService { if (query.creator) { const creators = query.creator.split("|") criteria.push({ - $or: _.flatten(creators.map(creator => [{ "creator.name": new RegExp(escapeStringRegexp(creator), "i") }, { "creator.id": creator }, { creator }])), + $or: _.flatten(creators.map(creator => [ + jskos.isValidUri(creator) ? null : { "creator.name": new RegExp(escapeStringRegexp(creator), "i") }, + jskos.isValidUri(creator) ? { "creator.id": creator } : null, + { creator }, + ].filter(Boolean))), }) } if (query.target) { diff --git a/services/concordances.js b/services/concordances.js index 0bd4947..573e3bd 100644 --- a/services/concordances.js +++ b/services/concordances.js @@ -3,6 +3,7 @@ const Concordance = require("../models/concordances") const Mapping = require("../models/mappings") const utils = require("../utils") const config = require("../config") +const jskos = require("jskos-tools") const validate = require("jskos-validate") const escapeStringRegexp = require("escape-string-regexp") @@ -46,7 +47,11 @@ module.exports = class ConcordanceService { if (query.creator) { const creators = query.creator.split("|") conditions.push({ - $or: _.flatten(creators.map(creator => [{ "creator.prefLabel.de": new RegExp(escapeStringRegexp(creator), "i") }, { "creator.prefLabel.en": new RegExp(escapeStringRegexp(creator), "i") }, { "creator.uri": creator }])), + $or: _.flatten(creators.map(creator => [ + jskos.isValidUri(creator) ? null : { "creator.prefLabel.de": new RegExp(escapeStringRegexp(creator), "i") }, + jskos.isValidUri(creator) ? null : { "creator.prefLabel.en": new RegExp(escapeStringRegexp(creator), "i") }, + jskos.isValidUri(creator) ? { "creator.uri": creator } : null, + ].filter(Boolean))), }) } // Set mode diff --git a/services/mappings.js b/services/mappings.js index 74e91b0..9dfac6b 100644 --- a/services/mappings.js +++ b/services/mappings.js @@ -213,7 +213,11 @@ module.exports = class MappingService { if (creator) { let creators = creator.split("|") mongoQuery4 = { - $or: _.flatten(creators.map(creator => [{ "creator.prefLabel.de": new RegExp(escapeStringRegexp(creator), "i") }, { "creator.prefLabel.en": new RegExp(escapeStringRegexp(creator), "i") }, { "creator.uri": creator }])), + $or: _.flatten(creators.map(creator => [ + jskos.isValidUri(creator) ? null : { "creator.prefLabel.de": new RegExp(escapeStringRegexp(creator), "i") }, + jskos.isValidUri(creator) ? null : { "creator.prefLabel.en": new RegExp(escapeStringRegexp(creator), "i") }, + jskos.isValidUri(creator) ? { "creator.uri": creator } : null, + ].filter(Boolean))), } }