Skip to content

Commit

Permalink
Annotations/concordances: Extend search for creator
Browse files Browse the repository at this point in the history
- Allow searching multiple creators.
- Allow URI and name.
- Search part of name, case-insensitive.

Was required for gbv/cocoda#520.
  • Loading branch information
stefandesu committed Apr 21, 2022
1 parent 1b0552c commit 1f6329a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -799,11 +799,11 @@ Lists all concordances for mappings.

`uri=[uri]` URIs for concordances separated by `|`

`fromScheme=[uri|notation]` only show concordances from concept scheme (URI or notation), separated by `|`
`fromScheme=[uri|notation]` only show concordances from concept scheme (URI or notation) (separated by `|`)

`toScheme=[uri|notation]` only show concordances to concept scheme (URI or notation), separated by `|`
`toScheme=[uri|notation]` only show concordances to concept scheme (URI or notation) (separated by `|`)

`creator=[creator]` only show concordances from creator, separated by `|`
`creator=[creator]` only show concordances from creator (separated by `|`)

`mode=[mode]` specify the mode for the parameters above, one of `and` (default) and `or`

Expand Down Expand Up @@ -1789,7 +1789,7 @@ Returns an array of annotations. Each annotation has a property `id` under which

`id=[id]` specify an annotation ID

`creator=[uriOrName]` only return annotations that have a certain creator (name or URI)
`creator=[uriOrName]` only return annotations that have a certain creator (name or URI) (separated by `|`)

`target=[target]` only return annotations with a specific target URI (e.g. a mapping URI)

Expand Down
14 changes: 3 additions & 11 deletions services/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const config = require("../config")
const utils = require("../utils")
const _ = require("lodash")
const validate = require("jskos-validate")
const escapeStringRegexp = require("escape-string-regexp")

const Annotation = require("../models/annotations")
const { EntityNotFoundError, DatabaseAccessError, InvalidBodyError, MalformedBodyError, MalformedRequestError, ForbiddenAccessError } = require("../errors")
Expand Down Expand Up @@ -29,18 +30,9 @@ module.exports = class MappingService {
})
}
if (query.creator) {
const creators = query.creator.split("|")
criteria.push({
$or: [
{
creator: query.creator,
},
{
"creator.id": query.creator,
},
{
"creator.name": query.creator,
},
],
$or: _.flatten(creators.map(creator => [{ "creator.name": new RegExp(escapeStringRegexp(creator), "i") }, { "creator.id": creator }, { creator }])),
})
}
if (query.target) {
Expand Down
13 changes: 5 additions & 8 deletions services/concordances.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Mapping = require("../models/mappings")
const utils = require("../utils")
const config = require("../config")
const validate = require("jskos-validate")
const escapeStringRegexp = require("escape-string-regexp")

const validateConcordance = validate.concordance

Expand Down Expand Up @@ -43,14 +44,10 @@ module.exports = class ConcordanceService {
}
// Search by creator
if (query.creator) {
let or = []
for (let creator of query.creator.split("|")) {
or.push({ "creator.prefLabel.de": creator })
or.push({ "creator.prefLabel.en": creator })
}
if (or.length) {
conditions.push({ $or: or })
}
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 }])),
})
}
// Set mode
let mode = query.mode
Expand Down

0 comments on commit 1f6329a

Please sign in to comment.