Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated API to saerch on availability prefLabels #654

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions experts-api/lib/schema/expert/3/context.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
10 changes: 7 additions & 3 deletions services/base-service/models/base/schema/minimal.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions services/base-service/models/expert/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
11 changes: 8 additions & 3 deletions services/base-service/models/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions services/base-service/models/search/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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(',');
Expand Down
10 changes: 5 additions & 5 deletions services/base-service/models/search/template/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
]
}
},
Expand Down Expand Up @@ -145,7 +145,7 @@ template = {
},
"availability": {
"terms": {
"field": "hasAvailability",
"field": "hasAvailability.prefLabel",
"size": 10
}
},
Expand Down