Skip to content

Commit

Permalink
Creator search: Don't search labels when searching for URIs (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Apr 21, 2022
1 parent 1f6329a commit 2c6a930
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion services/annotations.js
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion services/concordances.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion services/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
}
}

Expand Down

0 comments on commit 2c6a930

Please sign in to comment.