2019-06-05 15:33:18 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {HttpClient} from "@angular/common/http";
|
|
|
|
import {SearchResult} from '../utils/entities/searchResult';
|
|
|
|
import {RefineResultsUtils} from './servicesUtils/refineResults.class';
|
|
|
|
import {DOI, StringUtils} from '../utils/string-utils.class';
|
|
|
|
import {ParsingFunctions} from '../landingPages/landing-utils/parsingFunctions.class';
|
|
|
|
import {EnvProperties} from '../utils/properties/env-properties';
|
|
|
|
import {map} from "rxjs/operators";
|
|
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class SearchResearchResultsService {
|
|
|
|
private sizeOfDescription: number = 270;
|
|
|
|
public parsingFunctions: ParsingFunctions = new ParsingFunctions();
|
|
|
|
|
|
|
|
constructor(private http: HttpClient ) {}
|
|
|
|
|
|
|
|
search (resultType:string, params: string, refineParams:string, page: number, size: number, sortBy: string, refineFields:string[] , properties:EnvProperties):any {
|
|
|
|
let link = properties.searchAPIURLLAst+this.getEntityName(resultType,true);
|
|
|
|
|
|
|
|
let url = link+"?";
|
|
|
|
if(params!= null && params != '' ) {
|
|
|
|
url += params;
|
|
|
|
}
|
|
|
|
if(refineParams!= null && refineParams != '' ) {
|
|
|
|
url += refineParams;
|
|
|
|
}
|
|
|
|
if(sortBy) {
|
|
|
|
url += "&sortBy=" + sortBy;
|
|
|
|
}
|
|
|
|
url += "&page="+(page-1)+"&size="+size+"&format=json";
|
|
|
|
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2020-04-10 09:31:14 +02:00
|
|
|
.pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "publication")]));
|
2019-06-05 15:33:18 +02:00
|
|
|
}
|
|
|
|
|
2019-09-11 11:45:54 +02:00
|
|
|
searchById (resultType:string, id: string, properties:EnvProperties ):any {
|
2019-06-05 15:33:18 +02:00
|
|
|
let url = properties.searchAPIURLLAst+this.getEntityName(resultType,true) +"/"+id+"?format=json";
|
|
|
|
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
|
|
.pipe(map(res => this.parseResults(resultType, res, properties)));
|
|
|
|
}
|
|
|
|
|
2019-09-11 11:45:54 +02:00
|
|
|
searchAggregators (resultType:string, id: string, params: string, refineParams:string, page: number, size: number, properties:EnvProperties ):any {
|
|
|
|
let link = properties.searchAPIURLLAst+this.getEntityName(resultType,true);
|
2019-06-05 15:33:18 +02:00
|
|
|
|
|
|
|
let url = link+"?"+"&format=json";
|
|
|
|
if(params!= null && params != '' ) {
|
|
|
|
url += params;
|
|
|
|
}
|
|
|
|
if(refineParams!= null && refineParams != '' ) {
|
|
|
|
url += refineParams;
|
|
|
|
}
|
|
|
|
url += "&page="+(page-1)+"&size="+size;
|
|
|
|
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
|
|
.pipe(map(res => this.parseRefineResults(id, res['refineResults'])));
|
|
|
|
}
|
|
|
|
|
|
|
|
searchByListOfDOI (resultType:string, DOIs: string[], refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any {
|
|
|
|
let link = properties.searchAPIURLLAst+ this.getEntityName(resultType,true);
|
|
|
|
|
|
|
|
let url = link+"?"+"&format=json&";
|
|
|
|
var doisParams = "";
|
|
|
|
|
|
|
|
for(var i =0 ;i < DOIs.length; i++){
|
|
|
|
doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
|
|
|
}
|
|
|
|
if(doisParams.length > 0){
|
|
|
|
url +="&"+doisParams;
|
|
|
|
|
|
|
|
}
|
|
|
|
if(refineParams!= null && refineParams != '' ) {
|
|
|
|
url += refineParams;
|
|
|
|
}
|
|
|
|
url += "&page="+(page-1)+"&size="+size;
|
|
|
|
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
|
|
.pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "publication")]));
|
|
|
|
}
|
|
|
|
|
2020-01-31 16:12:51 +01:00
|
|
|
advancedSearch (resultType:string, params: string, page: number, size: number, sortBy: string, properties:EnvProperties, refineParams:string=null, refineFields:string[] =null, refineQuery:string = null ):any {
|
2019-06-05 15:33:18 +02:00
|
|
|
let url = properties.searchResourcesAPIURL;
|
|
|
|
var basicQuery = "(oaftype exact result) and (resulttypeid exact "+this.getEntityName(resultType,false) + ") ";
|
|
|
|
url += "?query=";
|
|
|
|
if(params!= null && params != '' ) {
|
|
|
|
url +=" ( "+basicQuery+ " ) " +" and (" + params + ")";
|
|
|
|
}else{
|
|
|
|
url +=" ( "+basicQuery+ " ) ";
|
|
|
|
}
|
2020-01-31 16:12:51 +01:00
|
|
|
if(refineParams!= null && refineParams != '' ) {
|
|
|
|
url += refineParams;
|
|
|
|
}
|
2019-06-05 15:33:18 +02:00
|
|
|
if(sortBy) {
|
|
|
|
let sortOptions = sortBy.split(",");
|
|
|
|
url += "sortBy "+sortOptions[0]+"/sort."+sortOptions[1]+" ";
|
|
|
|
}
|
2020-01-31 16:12:51 +01:00
|
|
|
if(refineQuery) {
|
|
|
|
url += "&" + refineQuery;
|
|
|
|
}
|
2019-06-05 15:33:18 +02:00
|
|
|
|
|
|
|
url += "&page="+(page-1)+"&size="+size;
|
|
|
|
url += "&format=json";
|
|
|
|
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2020-01-31 16:12:51 +01:00
|
|
|
.pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "publication")]));
|
2019-06-05 15:33:18 +02:00
|
|
|
}
|
2020-02-11 12:58:51 +01:00
|
|
|
advancedSearchResults (resultType:string, params: string, page: number, size: number, sortBy: string, properties:EnvProperties, refineParams:string=null, refineFields:string[] =null, refineQuery:string = null ):any {
|
2020-02-13 15:44:51 +01:00
|
|
|
let url = properties.searchAPIURLLAst+"resources2/?format=json";
|
2020-02-11 12:58:51 +01:00
|
|
|
if(params!= null && params != '' ) {
|
|
|
|
url +="&query=(" + params + ")";
|
|
|
|
}
|
|
|
|
if(sortBy) {
|
|
|
|
let sortOptions = sortBy.split(",");
|
2020-02-24 14:19:16 +01:00
|
|
|
url += (params ? " " : "&query=(*) ")+"sortBy "+sortOptions[0]+"/sort."+sortOptions[1]+(params ? " " : " ");
|
|
|
|
}
|
|
|
|
if(refineParams!= null && refineParams != '' ) {
|
|
|
|
url += refineParams;
|
2020-02-11 12:58:51 +01:00
|
|
|
}
|
|
|
|
if(refineQuery) {
|
|
|
|
url += "&" + refineQuery;
|
|
|
|
}
|
|
|
|
|
|
|
|
url += "&page="+(page-1)+"&size="+size;
|
|
|
|
// url += "&format=json";
|
|
|
|
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
|
|
.pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "publication")]));
|
|
|
|
}
|
2019-09-11 11:45:54 +02:00
|
|
|
|
2019-06-05 15:33:18 +02:00
|
|
|
searchResultForEntity (resultType:string, params: string, page: number, size: number, properties:EnvProperties):any {
|
|
|
|
let link = properties.searchAPIURLLAst;
|
|
|
|
let url = link+params+"/"+this.getEntityName(resultType,true)+ "?format=json";
|
|
|
|
url += "&page="+(page-1)+"&size="+size;
|
|
|
|
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
|
|
.pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties)]));
|
|
|
|
}
|
|
|
|
//???? why different from above?
|
|
|
|
searchForDataproviders(resultType:string, params: string, page: number, size: number, properties:EnvProperties):any {
|
|
|
|
let link = properties.searchAPIURLLAst;
|
|
|
|
let url = link+params+ "&page="+(page-1)+"&size="+size + "&format=json";
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
|
|
.pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties)]));
|
|
|
|
}
|
|
|
|
|
|
|
|
parseResults(resultType:string, data: any, properties: EnvProperties): SearchResult[] {
|
|
|
|
let results: SearchResult[] = [];
|
|
|
|
|
|
|
|
let length = Array.isArray(data) ? data.length : 1;
|
|
|
|
|
|
|
|
for(let i=0; i<length; i++) {
|
|
|
|
let resData = Array.isArray(data) ? data[i]['result']['metadata']['oaf:entity']['oaf:result'] : data['result']['metadata']['oaf:entity']['oaf:result'];
|
|
|
|
|
|
|
|
var result: SearchResult = new SearchResult();
|
2020-02-14 16:08:54 +01:00
|
|
|
if(resData['resulttype']) {
|
|
|
|
result.entityType = resData['resulttype']['classname'];
|
|
|
|
} else {
|
|
|
|
result.entityType = resultType;
|
|
|
|
}
|
2019-06-05 15:33:18 +02:00
|
|
|
result.types = new Array<string>();
|
|
|
|
let types = new Set<string>();
|
|
|
|
|
|
|
|
let instance;
|
|
|
|
let length = Array.isArray(resData['children']['instance']) ? resData['children']['instance'].length : 1;
|
|
|
|
|
|
|
|
for(let i=0; i<length; i++) {
|
|
|
|
instance = Array.isArray(resData['children']['instance']) ? resData['children']['instance'][i] : resData['children']['instance'];
|
|
|
|
this.parsingFunctions.parseTypes(result.types, types, instance);
|
|
|
|
}
|
2020-04-06 16:49:38 +02:00
|
|
|
/////////////////////////// Athena Code ///////////////////////////
|
2020-04-09 11:40:54 +02:00
|
|
|
if(resData['pid']) {
|
|
|
|
for(let i=0; i<resData['pid'].length; i++){
|
|
|
|
if(resData['pid'][i].classid == 'doi'){
|
|
|
|
if(resData['pid'][i].content != '' && resData['pid'][i].content != null){
|
|
|
|
result.DOI = resData['pid'][i].content.replace("https://doi.org/","");
|
|
|
|
break;
|
|
|
|
}
|
2020-04-06 16:49:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/////////////////////////// Athena Code ///////////////////////////
|
2019-09-11 11:45:54 +02:00
|
|
|
if(resData['programmingLanguage'] && resData['programmingLanguage'] != null) {
|
|
|
|
result.programmingLanguages = new Array<string>();
|
|
|
|
|
|
|
|
if(!Array.isArray(resData['programmingLanguage'])) {
|
|
|
|
if(resData['programmingLanguage'].classname != "Undetermined" && resData['programmingLanguage'].classname) {
|
|
|
|
result.programmingLanguages.push(resData['programmingLanguage'].classname);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(let i=0; i<resData['programmingLanguage'].length; i++) {
|
|
|
|
if(resData['programmingLanguage'][i].classname != "Undetermined" && resData['programmingLanguage'][i].classname) {
|
|
|
|
result.programmingLanguages.push(resData['programmingLanguage'][i].classname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-05 15:33:18 +02:00
|
|
|
if(resData['language'] && resData['language'] != null) {
|
|
|
|
result.languages = new Array<string>();
|
|
|
|
|
|
|
|
if(!Array.isArray(resData['language'])) {
|
|
|
|
if(resData['language'].classname != "Undetermined" && resData['language'].classname) {
|
|
|
|
result.languages.push(resData['language'].classname);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(let i=0; i<resData['language'].length; i++) {
|
|
|
|
if(resData['language'][i].classname != "Undetermined" && resData['language'][i].classname) {
|
|
|
|
result.languages.push(resData['language'][i].classname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(resData['country'] && resData['country'] != null) {
|
|
|
|
result.countriesForResults = new Array<string>();
|
|
|
|
|
|
|
|
if(!Array.isArray(resData['country'])) {
|
|
|
|
if(resData['country'].classname != "Undetermined" && resData['country'].classname) {
|
|
|
|
result.countriesForResults.push(resData['country'].classname);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(let i=0; i<resData['country'].length; i++) {
|
|
|
|
if(resData['country'][i].classname != "Undetermined" && resData['country'][i].classname) {
|
|
|
|
result.countriesForResults.push(resData['country'][i].classname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result['title'] = {"name": '', "accessMode": '', "sc39": ''};
|
|
|
|
|
|
|
|
if(Array.isArray(resData['title'])) {
|
2020-02-24 14:19:16 +01:00
|
|
|
result['title'].name = (resData['title'][0] && resData['title'][0].content) ? String(resData['title'][0].content) : "";
|
2019-06-05 15:33:18 +02:00
|
|
|
} else {
|
2020-02-24 14:19:16 +01:00
|
|
|
result['title'].name = (resData['title'] && resData['title'].content) ? String(resData['title'].content) : "";
|
2019-06-05 15:33:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result['id'] = Array.isArray(data) ? data[i]['result']['header']['dri:objIdentifier'] : data['result']['header']['dri:objIdentifier'];
|
2020-02-07 14:05:07 +01:00
|
|
|
if(resData['bestaccessright'] && resData['bestaccessright'].hasOwnProperty("classname")) {
|
|
|
|
result['title'].accessMode = resData['bestaccessright'].classname;
|
2019-06-05 15:33:18 +02:00
|
|
|
}
|
|
|
|
if(resData['rels'].hasOwnProperty("rel")) {
|
|
|
|
let relLength = Array.isArray(resData['rels']['rel']) ? resData['rels']['rel'].length : 1;
|
|
|
|
|
|
|
|
for(let j=0; j<relLength; j++) {
|
|
|
|
let relation = Array.isArray(resData['rels']['rel']) ? resData['rels']['rel'][j] : resData['rels']['rel'];
|
|
|
|
|
|
|
|
if(relation.hasOwnProperty("to")) {
|
2019-09-11 11:45:54 +02:00
|
|
|
if(relation['to'].class == "isProducedBy") {
|
2019-06-05 15:33:18 +02:00
|
|
|
result['projects'] = this.parseProjects(result['projects'], relation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(resData.hasOwnProperty("creator") && resData['creator'] != null) {
|
|
|
|
if(result['authors'] == undefined) {
|
|
|
|
result['authors'] = new Array<{"fullName": string, "orcid": string}>();
|
|
|
|
}
|
|
|
|
|
|
|
|
let authors = resData['creator'];
|
|
|
|
let length = Array.isArray(authors) ? authors.length : 1;
|
|
|
|
|
|
|
|
for(let i=0; i<length; i++) {
|
|
|
|
let author = Array.isArray(authors) ? authors[i] : authors;
|
|
|
|
if(author) {
|
|
|
|
result['authors'][author.rank] = {"fullName": author.content, "orcid": author.ORCID};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.authors = result.authors.filter(function (item) {
|
|
|
|
return (item != undefined && item.fullName != undefined);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var date:string = (resData.dateofacceptance)+""; // transform to string in case it is an integer
|
|
|
|
result.year = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date;
|
|
|
|
|
|
|
|
if(!Array.isArray(resData.description)) {
|
2020-03-12 11:46:02 +01:00
|
|
|
result.description = (resData.description) ? String(resData.description) : "";
|
2019-06-05 15:33:18 +02:00
|
|
|
} else {
|
2020-03-12 11:46:02 +01:00
|
|
|
result.description = (resData.description[0]) ? String(resData.description[0]) : "";
|
2019-06-05 15:33:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(result.description && result.description.length > this.sizeOfDescription) {
|
|
|
|
result.description = result.description.substring(0, this.sizeOfDescription) + "...";
|
|
|
|
}
|
|
|
|
|
2020-02-07 14:05:07 +01:00
|
|
|
if(resData.embargoenddate && resData.embargoenddate != '') {
|
|
|
|
result.embargoEndDate = new Date(resData.embargoenddate);
|
|
|
|
}
|
2019-06-05 15:33:18 +02:00
|
|
|
|
2019-09-11 11:45:54 +02:00
|
|
|
if(!Array.isArray(resData.publisher)) {
|
|
|
|
result.publisher = resData.publisher;
|
|
|
|
} else {
|
|
|
|
for(let i=0; i<resData.publisher.length; i++) {
|
|
|
|
if(result.publisher != undefined){
|
|
|
|
result.publisher += ', '+resData['publisher'][i];
|
|
|
|
} else {
|
|
|
|
result.publisher = resData['publisher'][i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-05 15:33:18 +02:00
|
|
|
results.push(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
parseProjects(projects: { "id": string, "acronym": string, "title": string,
|
|
|
|
"funderShortname": string, "funderName": string,
|
|
|
|
"code": string }[], relation: any ) : {
|
|
|
|
"id": string, "acronym": string, "title": string,
|
|
|
|
"funderShortname": string, "funderName": string,
|
|
|
|
"code": string }[] {
|
|
|
|
if(projects == undefined) {
|
|
|
|
projects = new Array<
|
|
|
|
{ "id": string, "acronym": string, "title": string,
|
|
|
|
"funderShortname": string, "funderName": string,
|
|
|
|
"code": string
|
|
|
|
}>();
|
|
|
|
}
|
|
|
|
|
|
|
|
let countProjects = projects.length;
|
|
|
|
|
|
|
|
projects[countProjects] = {
|
|
|
|
"id": "", "acronym": "", "title": "",
|
|
|
|
"funderShortname": "", "funderName": "",
|
|
|
|
"code": ""
|
2019-09-11 11:45:54 +02:00
|
|
|
};
|
2019-06-05 15:33:18 +02:00
|
|
|
|
|
|
|
if(relation.title != 'unidentified') {
|
2019-09-11 11:45:54 +02:00
|
|
|
projects[countProjects]['id'] = relation['to'].content;
|
2019-06-05 15:33:18 +02:00
|
|
|
projects[countProjects]['acronym'] = relation.acronym;
|
|
|
|
projects[countProjects]['title'] = relation.title;
|
|
|
|
projects[countProjects]['code'] = relation.code;
|
|
|
|
} else {
|
|
|
|
projects[countProjects]['id'] = "";
|
|
|
|
projects[countProjects]['acronym'] = "";
|
|
|
|
projects[countProjects]['title'] = "";
|
|
|
|
projects[countProjects]['code'] = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(relation.hasOwnProperty("funding")) {
|
|
|
|
let fundingLength = Array.isArray(relation['funding']) ? relation['funding'].length : 1;
|
|
|
|
|
|
|
|
for(let z=0; z<fundingLength; z++) {
|
|
|
|
let fundingData = Array.isArray(relation['funding']) ? relation['funding'][z] : relation['funding'];
|
|
|
|
|
|
|
|
if(fundingData.hasOwnProperty("funder")) {
|
|
|
|
projects[countProjects]['funderShortname'] = fundingData['funder'].shortname;
|
|
|
|
projects[countProjects]['funderName'] = fundingData['funder'].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return projects;
|
|
|
|
}
|
|
|
|
parseRefineResults(id: string, data: any): any {
|
|
|
|
var results:any = [];
|
|
|
|
if(data.hasOwnProperty("resulthostingdatasource")) {
|
|
|
|
let length = Array.isArray(data['resulthostingdatasource']) ? data['resulthostingdatasource'].length : 1;
|
|
|
|
|
|
|
|
for(let i=0; i<length; i++) {
|
|
|
|
let datasource = Array.isArray(data['resulthostingdatasource']) ? data['resulthostingdatasource'][i] : data['resulthostingdatasource'];
|
|
|
|
|
|
|
|
let result: {"name": string, "id": string, "count": number} = {"name": "", "id": "", "count": 0};
|
|
|
|
result['name'] = datasource.name;
|
|
|
|
result['id'] = datasource.id.split("||")[0];
|
|
|
|
result['count'] = datasource.count;
|
|
|
|
|
|
|
|
if(result['id'] != id && result['name'] != "Unknown Repository") {
|
|
|
|
results.push(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
private numOfResults(url: string, properties:EnvProperties): any {
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
|
|
.pipe(map(res => res['total']));
|
|
|
|
}
|
|
|
|
|
|
|
|
numOfEntityResults(resultType:string, id: string, entity: string, properties:EnvProperties):any {
|
|
|
|
var parameters: string = "";
|
|
|
|
parameters = this.getEntityName(entity, true) + "/"+id+"/"+this.getEntityName(resultType, true)+"/count";
|
|
|
|
let url = properties.searchAPIURLLAst+parameters+"?format=json";
|
|
|
|
return this.numOfResults(url , properties);
|
|
|
|
}
|
2020-02-19 16:35:48 +01:00
|
|
|
numOfResearchOutcomes( params: string, properties:EnvProperties, refineParams:string=null):any {
|
2020-04-07 13:11:31 +02:00
|
|
|
let url = properties.searchAPIURLLAst+"resources2/?format=json&size=0&type=results";
|
2020-02-19 16:35:48 +01:00
|
|
|
if(params.length > 0){
|
2020-04-07 13:11:31 +02:00
|
|
|
// var DOIs:string[] = DOI.getDOIsFromString(params);
|
|
|
|
// var doisParams = "";
|
|
|
|
//
|
|
|
|
// for(var i =0 ;i < DOIs.length; i++){
|
|
|
|
// doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
|
|
|
// }
|
|
|
|
// if(doisParams.length > 0){
|
|
|
|
// url += "&"+doisParams;
|
|
|
|
// }else{
|
|
|
|
// url += "&query=" + StringUtils.URIEncode(params);
|
|
|
|
// }
|
|
|
|
url += "&query=" + params;
|
2020-02-19 16:35:48 +01:00
|
|
|
}
|
2019-06-05 15:33:18 +02:00
|
|
|
|
2020-02-19 16:35:48 +01:00
|
|
|
if(refineParams!= null && refineParams != '' ) {
|
|
|
|
url += refineParams;
|
|
|
|
}
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
|
|
.pipe(map(res => res['meta']['total']));
|
|
|
|
}
|
2019-06-05 15:33:18 +02:00
|
|
|
numOfSearchResults(resultType:string, params: string, properties:EnvProperties, refineParams:string=null):any {
|
|
|
|
let url = properties.searchAPIURLLAst+this.getEntityName(resultType, true)+"/count?format=json";
|
|
|
|
if(params.length > 0){
|
|
|
|
var DOIs:string[] = DOI.getDOIsFromString(params);
|
|
|
|
var doisParams = "";
|
|
|
|
|
|
|
|
for(var i =0 ;i < DOIs.length; i++){
|
|
|
|
doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
|
|
|
}
|
|
|
|
if(doisParams.length > 0){
|
|
|
|
url += "&"+doisParams;
|
|
|
|
}else{
|
|
|
|
url += "&q=" + StringUtils.URIEncode(params);
|
|
|
|
}
|
|
|
|
}
|
2019-09-11 11:45:54 +02:00
|
|
|
|
2019-06-05 15:33:18 +02:00
|
|
|
if(refineParams!= null && refineParams != '' ) {
|
|
|
|
url += refineParams;
|
|
|
|
}
|
|
|
|
return this.numOfResults(url, properties);
|
|
|
|
}
|
2019-11-08 14:44:00 +01:00
|
|
|
numOfSearchResultsLinkedToPub(resultType:string, properties:EnvProperties):any {
|
|
|
|
let url = properties.searchAPIURLLAst+"resources?query="+encodeURIComponent("( (oaftype exact result) and (resulttypeid exact "+resultType+") and (relresulttype=publication) )")+"&page=0&size=0&format=json";
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
|
|
.pipe(map(res => res['meta']['total']));
|
|
|
|
}
|
2019-09-11 11:45:54 +02:00
|
|
|
|
|
|
|
countTotalResults(resultType:string, properties:EnvProperties, refineParams:string=null):any {
|
|
|
|
let url = properties.searchAPIURLLAst+this.getEntityName(resultType, true)+"/count?format=json"+refineParams;
|
|
|
|
return this.numOfResults(url, properties);
|
|
|
|
}
|
2019-06-05 15:33:18 +02:00
|
|
|
/*
|
|
|
|
private quote(word: any): string {
|
|
|
|
return '"'+word+'"';
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2019-09-11 11:45:54 +02:00
|
|
|
private getEntityName (entityType:string, plural:boolean){
|
|
|
|
if(entityType == "publication" ||entityType == "dataset" || entityType == "organization" || entityType == "datasource" || entityType == "project" ){
|
|
|
|
if(plural){
|
|
|
|
return entityType+ "s";
|
|
|
|
}else{
|
|
|
|
return entityType;
|
|
|
|
}
|
2019-06-05 15:33:18 +02:00
|
|
|
}else{
|
|
|
|
return entityType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|