From a899d7f02e05b059c691cf6af21b7f7c878bd263 Mon Sep 17 00:00:00 2001 From: Quinn Hart Date: Mon, 18 Nov 2024 17:22:01 -0800 Subject: [PATCH] Updated API to saerch on availability prefLabels --- experts-api/lib/schema/expert/3/context.jsonld | 1 + services/base-service/models/base/schema/minimal.json | 10 +++++++--- services/base-service/models/expert/model.js | 5 +++-- services/base-service/models/middleware.js | 11 ++++++++--- services/base-service/models/search/api.js | 6 +++--- .../base-service/models/search/template/complete.js | 10 +++++----- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/experts-api/lib/schema/expert/3/context.jsonld b/experts-api/lib/schema/expert/3/context.jsonld index a6ac61f4..9628050b 100644 --- a/experts-api/lib/schema/expert/3/context.jsonld +++ b/experts-api/lib/schema/expert/3/context.jsonld @@ -159,6 +159,7 @@ "page":{"@id":"cite:page"}, "Person":{"@id":"ucdlib:Person","@type":"@id"}, "PrincipalInvestigatorRole":{"@id":"vivo:PrincipalInvestigatorRole"}, + "prefLabel":{"@id":"skos:prefLabel"}, "pronouns":{"@id":"vcard:pronouns"}, "publisher":{"@id":"cite:publisher"}, "publisher-place":{"@id":"cite:publisher-place"}, diff --git a/services/base-service/models/base/schema/minimal.json b/services/base-service/models/base/schema/minimal.json index 8e740345..a0303514 100644 --- a/services/base-service/models/base/schema/minimal.json +++ b/services/base-service/models/base/schema/minimal.json @@ -8,9 +8,13 @@ "type" : "boolean" }, "hasAvailability": { - "type": "keyword", - "normalizer": "identifier", - "ignore_above": 128 + "properties" : { + "prefLabel" : { + "type": "keyword", + "normalizer": "identifier", + "ignore_above": 128 + } + } }, "@type" : { "type" : "keyword", diff --git a/services/base-service/models/expert/model.js b/services/base-service/models/expert/model.js index e7de7b63..eeb0347b 100644 --- a/services/base-service/models/expert/model.js +++ b/services/base-service/models/expert/model.js @@ -324,12 +324,13 @@ class ExpertModel extends BaseModel { doc["is-visible"] = node["is-visible"]; } if (node["hasAvailability"]) { - doc["hasAvailability"] = []; + doc["hasAvailability"]=[]; if (! Array.isArray(node["hasAvailability"])) { node["hasAvailability"] = [node["hasAvailability"]]; } + // this is for later if we want to pair down the availability node["hasAvailability"].forEach(availability => { - doc["hasAvailability"].push(availability["@id"]); + doc["hasAvailability"].push(availability); }); } diff --git a/services/base-service/models/middleware.js b/services/base-service/models/middleware.js index bd748bf2..87ee96cf 100644 --- a/services/base-service/models/middleware.js +++ b/services/base-service/models/middleware.js @@ -321,16 +321,21 @@ const openapi = OpenAPI( style: "simple", explode: false }, - hasAvailability: { + availability: { in: "query", - name: "hasAvailability", + name: "availability", description: "Comma-separated search filter on expert availability types", required: false, schema: { type: "arary", items: { type: "string", - enum: ["collab","community","industry","media"] + enum: [ + "community partnerships", + "collaborative projects", + "industry Projects", + "media enquiries" + ] } }, style: "simple", diff --git a/services/base-service/models/search/api.js b/services/base-service/models/search/api.js index 08897518..c99a4e76 100644 --- a/services/base-service/models/search/api.js +++ b/services/base-service/models/search/api.js @@ -45,7 +45,7 @@ router.get( search_valid_path( { description: "Returns matching search results for experts, including the number of matching works and grants", - parameters: ['p', 'page', 'size', 'type','status','hasAvailability'], + parameters: ['p', 'page', 'size', 'type','status','availability'], responses: { "200": openapi.response('Search'), "400": openapi.response('Invalid_request') @@ -62,8 +62,8 @@ router.get( if (req.query[key]) { params[key] = req.query[key]; } }); - if (req?.query.hasAvailability) { - params.hasAvailability = req.query.hasAvailability.split(','); + if (req?.query.availability) { + params.availability = req.query.availability.split(','); } if (req?.query.status) { params.status = req.query.status.split(','); diff --git a/services/base-service/models/search/template/complete.js b/services/base-service/models/search/template/complete.js index 8f48bee4..147f7cd8 100644 --- a/services/base-service/models/search/template/complete.js +++ b/services/base-service/models/search/template/complete.js @@ -23,18 +23,18 @@ template = { "bool": { "must": [ { "term": { "@type": "Expert" }} - {{#hasAvailability}} + {{#availability}} ,{ "bool": { "must": [ - { "exists": { "field": "hasAvailability" }}, + { "exists": { "field": "hasAvailability.prefLabel" }}, { "terms": { - "hasAvailability": {{#toJson}}hasAvailability{{/toJson}} + "hasAvailability.prefLabel": {{#toJson}}availability{{/toJson}} }} ] } } - {{/hasAvailability}} + {{/availability}} ] } }, @@ -145,7 +145,7 @@ template = { }, "availability": { "terms": { - "field": "hasAvailability", + "field": "hasAvailability.prefLabel", "size": 10 } },