From 70bd195043d669157b58fb57038538c46932fc95 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Fri, 2 Dec 2016 17:27:10 +0000 Subject: [PATCH] mv utils/dates.class.ts to utils/string-utils.class.ts -> put there utils for Dates,DOIs | check if keywords used in search are dois and then search by doi or keyword git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@44797 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../claim-utils/claimDataset.component.ts | 61 +++++++--- .../claimPublication.component.html | 1 + .../claim-utils/claimPublication.component.ts | 80 ++++++++----- .../linking/bulkClaim/bulkClaim.component.ts | 28 ++--- .../searchUtils/searchPage.component.ts | 108 +++++++++++++----- .../simple/searchDataproviders.component.ts | 4 +- .../simple/searchDatasets.component.ts | 13 ++- .../simple/searchOrganizations.component.ts | 2 +- .../simple/searchPeople.component.ts | 2 +- .../simple/searchProjects.component.ts | 2 +- .../simple/searchPublications.component.ts | 13 ++- .../app/services/searchCrossref.service.ts | 16 ++- .../app/services/searchDatasets.service.ts | 29 ++++- .../services/searchOrganizations.service.ts | 2 +- .../src/app/services/searchPeople.service.ts | 2 +- .../app/services/searchProjects.service.ts | 2 +- .../services/searchPublications.service.ts | 35 +++++- portal-2/src/app/test/test.component.ts | 4 +- .../{dates.class.ts => string-utils.class.ts} | 26 +++++ 19 files changed, 324 insertions(+), 106 deletions(-) rename portal-2/src/app/utils/{dates.class.ts => string-utils.class.ts} (59%) diff --git a/portal-2/src/app/claimPages/claim-utils/claimDataset.component.ts b/portal-2/src/app/claimPages/claim-utils/claimDataset.component.ts index 2462ed85..dde05b8f 100644 --- a/portal-2/src/app/claimPages/claim-utils/claimDataset.component.ts +++ b/portal-2/src/app/claimPages/claim-utils/claimDataset.component.ts @@ -4,6 +4,7 @@ import { SearchDataciteService } from '../../services/searchDatacite.service'; import {SearchDatasetsService} from '../../services/searchDatasets.service'; import {ClaimResult} from '../../utils/entities/claimEntities.class'; import { ErrorCodes} from '../../utils/properties/openaireProperties'; +import{DOI} from '../../utils/string-utils.class'; @Component({ @@ -111,10 +112,12 @@ export class ClaimDatasetComponent { private todayDate = ''; private nextDate = ''; + private DOIs:string[] = []; + public search(term: string, size : number, page : number){ + this.DOIs = DOI.getDOIsFromString(term); this.searchDatacite(term,10,1); this.searchOpenaire(term,10,1); - //TODO add openaire search } private searchDatacite (term: string, size : number, page : number) { this.getDataciteResults(term,size,page); @@ -123,24 +126,44 @@ export class ClaimDatasetComponent { } private searchOpenaire (term: string, size : number, page : number) { - this._searchDatasetsService.searchDatasets('q='+term+'&op=and', null, page, size, []).subscribe( - data => { - if(data != null) { - this.openairePage=page; - this.openaireResultsNum = data[0]; - this.openaireResults = data[1]; - this.openaireStatus = this.errorCodes.DONE; - if(this.openaireResultsNum == 0){ - this.openaireStatus = this.errorCodes.NONE; - } - } - }, - err => { - console.error(err.status); - this.openaireStatus = this.errorCodes.ERROR; + if(this.DOIs.length > 0 ){ + this.openaireStatus = this.errorCodes.LOADING; + this._searchDatasetsService.searchDatasetsByDois(this.DOIs, null, page, size, []).subscribe( + data => { + if(data != null) { + this.openairePage=page; + this.openaireResultsNum = data[0]; + this.openaireResults = data[1]; + this.openaireStatus = this.errorCodes.DONE; + if(this.openaireResultsNum == 0){ + this.openaireStatus = this.errorCodes.NONE; } - ); - + } + }, + err => { + this.openaireStatus = this.errorCodes.ERROR; + console.error(err.status); + } + ); + }else{ + this._searchDatasetsService.searchDatasets('q="'+term+'"', null, page, size, []).subscribe( + data => { + if(data != null) { + this.openairePage=page; + this.openaireResultsNum = data[0]; + this.openaireResults = data[1]; + this.openaireStatus = this.errorCodes.DONE; + if(this.openaireResultsNum == 0){ + this.openaireStatus = this.errorCodes.NONE; + } + } + }, + err => { + this.openaireStatus = this.errorCodes.ERROR; + console.error(err.status); + } + ); + } this.warningMessage = ""; this.infoMessage = ""; @@ -156,8 +179,8 @@ export class ClaimDatasetComponent { }, err => { - console.error(err); this.dataciteStatus = this.errorCodes.ERROR; + console.error(err); } ); diff --git a/portal-2/src/app/claimPages/claim-utils/claimPublication.component.html b/portal-2/src/app/claimPages/claim-utils/claimPublication.component.html index 9be05844..d1967261 100644 --- a/portal-2/src/app/claimPages/claim-utils/claimPublication.component.html +++ b/portal-2/src/app/claimPages/claim-utils/claimPublication.component.html @@ -62,6 +62,7 @@ +
No results found
Not the right author? Choose one of these: diff --git a/portal-2/src/app/claimPages/claim-utils/claimPublication.component.ts b/portal-2/src/app/claimPages/claim-utils/claimPublication.component.ts index 7fffefa7..53911f72 100644 --- a/portal-2/src/app/claimPages/claim-utils/claimPublication.component.ts +++ b/portal-2/src/app/claimPages/claim-utils/claimPublication.component.ts @@ -6,7 +6,7 @@ import {SearchOrcidService} from '../../services/searchOrcid.service'; import {SearchPublicationsService} from '../../services/searchPublications.service'; import { ErrorCodes} from '../../utils/properties/openaireProperties'; import {ClaimResult} from '../../utils/entities/claimEntities.class'; - +import{DOI} from '../../utils/string-utils.class'; @Component({ selector: 'claim-publication', @@ -77,11 +77,12 @@ ngOnDestroy() { todayDate = ''; nextDate = ''; - +private DOIs:string[] = []; public search(term: string){ this.warningMessage = ""; this.infoMessage = ""; + this.DOIs = DOI.getDOIsFromString(term); this.getCrossrefResults(term, this.size,1); this.searchOrcid(term); this.searchOpenaire(term, this.size, 1); @@ -90,8 +91,8 @@ public search(term: string){ private getCrossrefResults (term: string, size : number, page : number) { this.crossrefStatus = this.errorCodes.LOADING; - if(term.split(' ').length == 1 ){ - this._searchCrossrefService.searchCrossrefByDOI(term).subscribe( + if( this.DOIs.length > 0 ){ + this._searchCrossrefService.searchCrossrefByDOIs(this.DOIs).subscribe( data => { if(data != null) { this.crossrefResults = data.items; @@ -164,30 +165,57 @@ private getCrossrefResults (term: string, size : number, page : number) { } } private searchOpenaire(term: string, size : number, page : number) { - this.openaireStatus = this.errorCodes.LOADING; - this._searchPublicationsService.searchPublications('q='+term+'&op=and', null, page, size, []).subscribe( - data => { - if(data != null) { - this.openairePage=page; - this.openaireResultsNum = data[0]; - this.openaireResults = data[1]; - this.openaireStatus = this.errorCodes.DONE; - if(this.openaireResultsNum == 0){ - this.openaireStatus = this.errorCodes.NONE; - } - }else { - this.openaireStatus = this.errorCodes.ERROR; - } - }, - err => { - console.error(err.status); - this.openaireStatus = this.errorCodes.ERROR; - } - ); + if(this.DOIs.length > 0 ){ + this.openaireStatus = this.errorCodes.LOADING; + this._searchPublicationsService.searchPublicationsByDois(this.DOIs, null, page, size, []).subscribe( + data => { + if(data != null) { + this.openairePage=page; + this.openaireResultsNum = data[0]; + this.openaireResults = data[1]; + this.openaireStatus = this.errorCodes.DONE; + if(this.openaireResultsNum == 0){ + this.openaireStatus = this.errorCodes.NONE; + } + }else { + this.openaireStatus = this.errorCodes.ERROR; + } + }, + err => { + this.openaireStatus = this.errorCodes.ERROR; + console.error(err.status); + } + ); + }else{ + this.openaireStatus = this.errorCodes.LOADING; + this._searchPublicationsService.searchPublications('q="'+term+'"', null, page, size, []).subscribe( + data => { + if(data != null) { + this.openairePage=page; + this.openaireResultsNum = data[0]; + this.openaireResults = data[1]; + this.openaireStatus = this.errorCodes.DONE; + if(this.openaireResultsNum == 0){ + this.openaireStatus = this.errorCodes.NONE; + } + }else { + this.openaireStatus = this.errorCodes.ERROR; + } + }, + err => { + this.openaireStatus = this.errorCodes.ERROR; + console.error(err.status); + } + ); + } } private searchOrcid (term: string) { + if(this.DOIs.length > 0){ + this.orcidStatus = this.errorCodes.NONE; + return; + } this.orcidStatus = this.errorCodes.LOADING; this.authorIds = new Array(); this.authorGivenNames = new Array(); @@ -236,8 +264,8 @@ private getCrossrefResults (term: string, size : number, page : number) { if(err.status == 404){ this.getOrcidAuthors(term); } else { - console.error(err.status); this.orcidStatus = this.errorCodes.ERROR; + console.error(err.status); } } @@ -257,8 +285,8 @@ private getCrossrefResults (term: string, size : number, page : number) { }, err => { - console.error(err.status); this.orcidStatus = this.errorCodes.ERROR; + console.error(err.status); } ); } diff --git a/portal-2/src/app/claimPages/linking/bulkClaim/bulkClaim.component.ts b/portal-2/src/app/claimPages/linking/bulkClaim/bulkClaim.component.ts index cc31a158..6d55b36c 100644 --- a/portal-2/src/app/claimPages/linking/bulkClaim/bulkClaim.component.ts +++ b/portal-2/src/app/claimPages/linking/bulkClaim/bulkClaim.component.ts @@ -2,7 +2,7 @@ import {Component, Input, Output, EventEmitter,ViewChild} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {SearchCrossrefService} from '../../../services/searchCrossref.service'; import {ModalLoading} from '../../../utils/modal/loading.component'; -import {Dates} from '../../../utils/dates.class'; +import {Dates, DOI} from '../../../utils/string-utils.class'; @Component({ @@ -100,18 +100,20 @@ export class BulkClaimComponent { this.all++; var id=this.removeDoubleQuotes(values[0]); - var accessMode = (values[1] != undefined) ? this.removeDoubleQuotes(values[1]):"OPEN"; - accessMode = (this.validateAccessMode(accessMode)?accessMode:"OPEN"); - var embargoDate =(values[2] != undefined) ? this.removeDoubleQuotes(values[2]):Dates.getDateToday(); - embargoDate = (Dates.isValidDate(embargoDate)?embargoDate:Dates.getDateToday()); - if(this.allIds.indexOf(id)>-1){ - this.duplicate++; - this.duplicateIds.push(id); - }else{ - this.allIds.push(id); - this.fetchResult(id,accessMode,embargoDate); - } + if(DOI.isValidDOI(id)){ + var accessMode = (values[1] != undefined) ? this.removeDoubleQuotes(values[1]):"OPEN"; + accessMode = (this.validateAccessMode(accessMode)?accessMode:"OPEN"); + var embargoDate =(values[2] != undefined) ? this.removeDoubleQuotes(values[2]):Dates.getDateToday(); + embargoDate = (Dates.isValidDate(embargoDate)?embargoDate:Dates.getDateToday()); + if(this.allIds.indexOf(id)>-1){ + this.duplicate++; + this.duplicateIds.push(id); + }else{ + this.allIds.push(id); + this.fetchResult(id,accessMode,embargoDate); + } } + } } @@ -167,7 +169,7 @@ export class BulkClaimComponent { } fetchResult(id:string,accessMode:string,date:string){ - this._searchCrossrefService.searchCrossrefByDOI(id).subscribe( + this._searchCrossrefService.searchCrossrefByDOIs([id]).subscribe( data => { var crossrefResult = data.items[0]; diff --git a/portal-2/src/app/searchPages/searchUtils/searchPage.component.ts b/portal-2/src/app/searchPages/searchUtils/searchPage.component.ts index db7c4802..53886eea 100644 --- a/portal-2/src/app/searchPages/searchUtils/searchPage.component.ts +++ b/portal-2/src/app/searchPages/searchUtils/searchPage.component.ts @@ -5,6 +5,7 @@ import { Filter, Value} from './searchHelperClasses.class'; import {SearchResult} from '../../utils/entities/searchResult'; import {SearchFields} from '../../utils/properties/searchFields'; import {SearchUtilsClass} from './searchUtils.class'; +import {DOI} from '../../utils/string-utils.class'; @Component({ selector: 'search-page', @@ -125,9 +126,25 @@ export class SearchPageComponent { } var keyword = params['keyword']; console.info("Type:" + this.type + "filters: "+allFqs); - var doiQuery =(keyword && keyword.length > 0 && keyword.split(" ").length ==1 )?'or ((pidclassid exact doi) and (pid exact "'+ keyword+'"))':""; - var keywordQuery =(doiQuery.length > 0 )? "((" + this.quote(keyword) + ")" + doiQuery + ")":this.quote(keyword); - return (keyword && keyword.length > 0?'q='+(this.type == 'publication' ||this.type == 'dataset' ?keywordQuery:keyword)+"&op=and":'') + allFqs; + var doiQuery = ""; + var keywordQuery = ""; + if((keyword && keyword.length > 0)){ + if((this.type == 'publication' ||this.type == 'dataset')){ + var DOIs:string[] = DOI.getDOIsFromString(keyword); + var doisParams = ""; + + for(var i =0 ;i < DOIs.length; i++){ + doisParams+=(doisParams.length > 0?" or ":"")+'((pidclassid exact doi) and (pid exact "'+ DOIs[i]+'"))'; + } + if(doisParams.length > 0){ + doiQuery += "q=("+doisParams+")" + } + }else{ + keywordQuery += "q=("+this.quote(keyword) +")" + + } + } + return (doiQuery.length > 0 ? doiQuery:keywordQuery) + allFqs; } public getIndexQueryParametersFromUrl(params){ var parameters = ""; @@ -157,12 +174,26 @@ export class SearchPageComponent { } var keyword = params['keyword']; - var doiQuery =(keyword && keyword.length > 0 && keyword.split(" ").length ==1 )?'or ((pidclassid exact doi) and (pid exact "'+ keyword+'"))':""; - var keywordQuery =(doiQuery.length > 0 )? "((" + this.quote(keyword) + ")" + doiQuery + ")":this.quote(keyword); - // parameters += (keyword && keyword.length > 0?' and '+(this.type == 'publication' ||this.type == 'dataset' ?keywordQuery:keyword)+' ':''); - // allFqs += ; + var doiQuery = ""; + var keywordQuery = ""; + if((keyword && keyword.length > 0)){ + if((this.type == 'publication' ||this.type == 'dataset')){ + var DOIs:string[] = DOI.getDOIsFromString(keyword); + var doisParams = ""; + + for(var i =0 ;i < DOIs.length; i++){ + doisParams+=(doisParams.length > 0?" or ":"")+'((pidclassid exact doi) and (pid exact "'+ DOIs[i]+'"))'; + } + if(doisParams.length > 0){ + doiQuery += "q=("+doisParams+")" + } + }else{ + keywordQuery += "q=("+this.quote(keyword) +")" + + } + } + return (doiQuery.length > 0 ? doiQuery:keywordQuery) + allFqs; - return (keyword && keyword.length > 0?' and '+(this.type == 'publication' ||this.type == 'dataset' ?keywordQuery:keyword)+' ':'')+allFqs; } /* * Mark as check the new filters that are selected, when you get them from search @@ -227,64 +258,81 @@ export class SearchPageComponent { * */ private createSearchQueryParameters(filters:Filter[]){ - // var allLimits=""; var allFqs = ""; for (let filter of filters){ if(filter.countSelectedValues > 0){ - // var filterLimits=""; var fq = ""; var count_selected=0; var fieldId = this.indexIdsMap[filter.filterId]; for (let value of filter.values){ if(value.selected == true){ count_selected++; - // filterLimits+='&' + fieldId+ '='+ value.id+"&" + this.fieldIdsMap[fieldId].operator + "="+((count_selected == 1)?"and":filter.filterOperator); fq+=(fq.length > 0 ? " " + filter.filterOperator + " ":"" ) + filter.filterId + " exact " + this.quote(value.id); } } fq="&fq="+fq; - // allLimits += filterLimits; allFqs += fq; } } -//TODO when final search is done- remove op=and from keyword - var doiQuery =(this.searchUtils.keyword.length > 0 && this.searchUtils.keyword.split(" ").length ==1 )?'or ((pidclassid exact doi) and (pid exact "'+ this.searchUtils.keyword+'"))':""; - var keywordQuery =(doiQuery.length > 0 )? "((" + this.quote(this.searchUtils.keyword) + ")" + doiQuery + ")":this.quote(this.searchUtils.keyword); - return (this.searchUtils.keyword.length > 0?'q='+(this.type == 'publication' ||this.type == 'dataset' ?keywordQuery:this.searchUtils.keyword)+"&op=and":'')+allFqs; + var doiQuery = ""; + var keywordQuery = ""; + if((this.searchUtils.keyword && this.searchUtils.keyword.length > 0)){ + if((this.type == 'publication' ||this.type == 'dataset')){ + var DOIs:string[] = DOI.getDOIsFromString(this.searchUtils.keyword); + var doisParams = ""; + + for(var i =0 ;i < DOIs.length; i++){ + doisParams+=(doisParams.length > 0?" or ":"")+'((pidclassid exact doi) and (pid exact "'+ DOIs[i]+'"))'; + } + if(doisParams.length > 0){ + doiQuery += "q=("+doisParams+")" + } + }else{ + keywordQuery += "q=("+this.quote(this.searchUtils.keyword) +")" + } + } + return (doiQuery.length > 0 ? doiQuery:keywordQuery) + allFqs; + } private createIndexQueryParameters(filters:Filter[]){ - //TODO - // var allLimits=""; var allFqs = ""; for (let filter of filters){ if(filter.countSelectedValues > 0){ - // var filterLimits=""; var count_selected=0; var fq = ""; - var fieldId = this.indexIdsMap[filter.filterId]; for (let value of filter.values){ if(value.selected == true){ count_selected++; - // filterLimits+=((count_selected == 1)?" and (":" "+filter.filterOperator+" ") + filter.filterId+ '='+ value.id; - fq+=(fq.length > 0 ? " " + filter.filterOperator + " ":"" ) + filter.filterId + " exact " + this.quote(value.id); - + fq+=(fq.length > 0 ? " " + filter.filterOperator + " ":"" ) + filter.filterId + " exact " + this.quote(value.id); } } - // filterLimits+=(filterLimits.length > 0 )?' ) ':''; - // allLimits += filterLimits; if(count_selected > 0){ fq="&fq="+fq; allFqs += fq; } } } - // allLimits += (this.searchUtils.keyword && this.searchUtils.keyword.length > 0?' and '+this.searchUtils.keyword+' ':''); - var doiQuery =(this.searchUtils.keyword.length > 0 && this.searchUtils.keyword.split(" ").length ==1 )?'or ((pidclassid exact doi) and (pid exact "'+ this.searchUtils.keyword+'"))':""; - var keywordQuery =(doiQuery.length > 0 )? "((" + this.quote(this.searchUtils.keyword) + ")" + doiQuery + ")":this.quote(this.searchUtils.keyword); - return (this.searchUtils.keyword && this.searchUtils.keyword.length > 0?' and '+(this.type == 'publication' ||this.type == 'dataset' ?keywordQuery:this.searchUtils.keyword)+' ':'')+allFqs; + var doiQuery = ""; + var keywordQuery = ""; + if((this.searchUtils.keyword && this.searchUtils.keyword.length > 0)){ + if((this.type == 'publication' ||this.type == 'dataset')){ + var DOIs:string[] = DOI.getDOIsFromString(this.searchUtils.keyword); + var doisParams = ""; + for(var i =0 ;i < DOIs.length; i++){ + doisParams+=(doisParams.length > 0?" or ":"")+'((pidclassid exact doi) and (pid exact "'+ DOIs[i]+'"))'; + } + if(doisParams.length > 0){ + doiQuery += "q=("+doisParams+")" + } + }else{ + keywordQuery += "q=("+this.quote(this.searchUtils.keyword) +")" + + } + } + return (doiQuery.length > 0 ? doiQuery:keywordQuery) + allFqs; + } - // private isFiltered(){ var filtered=false; for (let filter of this.filters){ diff --git a/portal-2/src/app/searchPages/simple/searchDataproviders.component.ts b/portal-2/src/app/searchPages/simple/searchDataproviders.component.ts index a6b4d38b..21cea78f 100644 --- a/portal-2/src/app/searchPages/simple/searchDataproviders.component.ts +++ b/portal-2/src/app/searchPages/simple/searchDataproviders.component.ts @@ -100,7 +100,7 @@ console.info("PAGE init = "+this.searchUtils.page); public getNumForSearch(keyword: string) { var parameters="datasources/count"; if(keyword != "") { - parameters += "?q="+keyword; + parameters += "?q="+'"'+keyword+'"'; } this._searchDataprovidersService.numOfDataproviders(parameters).subscribe( data => { @@ -210,7 +210,7 @@ public getResultsForDeposit(id:string, type:string, page: number, size: number) public getResults(keyword:string,refine:boolean, page: number, size: number){ var parameters = ""; if(keyword.length > 0){ - parameters = "q=" + keyword + "&op=and"; + parameters = "q="+'"' + keyword + '"'; } this._getResults(parameters,refine,page,this.searchUtils.size); } diff --git a/portal-2/src/app/searchPages/simple/searchDatasets.component.ts b/portal-2/src/app/searchPages/simple/searchDatasets.component.ts index 552cac05..8928c35c 100644 --- a/portal-2/src/app/searchPages/simple/searchDatasets.component.ts +++ b/portal-2/src/app/searchPages/simple/searchDatasets.component.ts @@ -9,6 +9,7 @@ import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openairePro import {SearchFields} from '../../utils/properties/searchFields'; import {SearchPageComponent } from '../searchUtils/searchPage.component'; import {SearchUtilsClass } from '../searchUtils/searchUtils.class'; +import {DOI} from '../../utils/string-utils.class'; @Component({ selector: 'search-datasets', @@ -148,7 +149,17 @@ public getResultsForDataproviders(id:string, resultsFrom:string, page: number, s public getResults(keyword:string,refine:boolean, page: number, size: number){ var parameters = ""; if(keyword.length > 0){ - parameters = "q=" + keyword + "&op=and"; + var DOIs:string[] = DOI.getDOIsFromString(keyword); + var doisParams = ""; + + for(var i =0 ;i < DOIs.length; i++){ + doisParams+=(doisParams.length > 0?" or ":"")+'((pidclassid exact doi) and (pid exact "'+ DOIs[i]+'"))'; + } + if(doisParams.length > 0){ + parameters += "q=("+doisParams+")" + }else{ + parameters = "q="+'"' + keyword + '"'; + } } this._getResults(parameters,refine,page,size); } diff --git a/portal-2/src/app/searchPages/simple/searchOrganizations.component.ts b/portal-2/src/app/searchPages/simple/searchOrganizations.component.ts index 9486ff94..8b0370e5 100644 --- a/portal-2/src/app/searchPages/simple/searchOrganizations.component.ts +++ b/portal-2/src/app/searchPages/simple/searchOrganizations.component.ts @@ -73,7 +73,7 @@ export class SearchOrganizationsComponent { public getResults(keyword:string,refine:boolean, page: number, size: number){ var parameters = ""; if(keyword.length > 0){ - parameters = "q=" + keyword + "&op=and"; + parameters = "q="+'"' + keyword + '"'; } this._getResults(parameters,refine,page,this.searchUtils.size); } diff --git a/portal-2/src/app/searchPages/simple/searchPeople.component.ts b/portal-2/src/app/searchPages/simple/searchPeople.component.ts index 3951fd0d..abf06f82 100644 --- a/portal-2/src/app/searchPages/simple/searchPeople.component.ts +++ b/portal-2/src/app/searchPages/simple/searchPeople.component.ts @@ -147,7 +147,7 @@ export class SearchPeopleComponent { public getResults(keyword:string,refine:boolean, page: number, size: number){ var parameters = ""; if(keyword.length > 0){ - parameters = "q=" + keyword + "&op=and"; + parameters = "q="+'"' + keyword + '"'; } this._getResults(parameters,refine,page,this.searchUtils.size); } diff --git a/portal-2/src/app/searchPages/simple/searchProjects.component.ts b/portal-2/src/app/searchPages/simple/searchProjects.component.ts index 87e86d7e..66db822f 100644 --- a/portal-2/src/app/searchPages/simple/searchProjects.component.ts +++ b/portal-2/src/app/searchPages/simple/searchProjects.component.ts @@ -79,7 +79,7 @@ export class SearchProjectsComponent { public getResults(keyword:string,refine:boolean, page: number, size: number){ var parameters = ""; if(keyword.length > 0){ - parameters = "q=" + keyword + "&op=and"; + parameters = "q="+'"' + keyword + '"'; } this._getResults(parameters,refine,page,this.searchUtils.size); } diff --git a/portal-2/src/app/searchPages/simple/searchPublications.component.ts b/portal-2/src/app/searchPages/simple/searchPublications.component.ts index 95dc90fb..533b4973 100644 --- a/portal-2/src/app/searchPages/simple/searchPublications.component.ts +++ b/portal-2/src/app/searchPages/simple/searchPublications.component.ts @@ -11,6 +11,7 @@ import {SearchFields} from '../../utils/properties/searchFields'; import {SearchPageComponent } from '../searchUtils/searchPage.component'; import {SearchUtilsClass} from '../searchUtils/searchUtils.class'; import {ExportCSVComponent} from '../../utils/exportCSV.component'; +import {DOI} from '../../utils/string-utils.class'; @Component({ selector: 'search-publications', @@ -177,7 +178,17 @@ public getResultsForDataproviders(id:string, resultsFrom:string, page: number, s public getResults(keyword:string,refine:boolean, page: number, size: number){ var parameters = ""; if(keyword.length > 0){ - parameters = "q=" + keyword + "&op=and"; + var DOIs:string[] = DOI.getDOIsFromString(keyword); + var doisParams = ""; + + for(var i =0 ;i < DOIs.length; i++){ + doisParams+=(doisParams.length > 0?" or ":"")+'((pidclassid exact doi) and (pid exact "'+ DOIs[i]+'"))'; + } + if(doisParams.length > 0){ + parameters += "q=("+doisParams+")" + }else{ + parameters = "q="+'"' + keyword + '"'; + } } this._getResults(parameters,refine,page,size); } diff --git a/portal-2/src/app/services/searchCrossref.service.ts b/portal-2/src/app/services/searchCrossref.service.ts index b28f8065..6a4958d6 100644 --- a/portal-2/src/app/services/searchCrossref.service.ts +++ b/portal-2/src/app/services/searchCrossref.service.ts @@ -27,8 +27,18 @@ export class SearchCrossrefService { //.catch(this.handleError); } - searchCrossrefByDOI(doi: string):any { - let url = OpenaireProperties.getSearchCrossrefAPIURL()+'?filter=doi:'+doi; + searchCrossrefByDOIs(DOIs: string[]):any { + /* + $request ="http://api.crossref.org/works"."?filter="; + foreach($dois as $doi){ + $request.="doi:".urlencode( trim($doi)).","; + } + */ + var doisParams = ""; + for(var i =0 ;i < DOIs.length; i++){ + doisParams+=(doisParams.length > 0?",":"")+'doi:'+DOIs[i]; + } + let url = OpenaireProperties.getSearchCrossrefAPIURL()+'?filter='+doisParams; let key = url; if (this._cache.has(key)) { return Observable.of(this._cache.get(key)); @@ -36,7 +46,7 @@ export class SearchCrossrefService { return this.http.get( url) .map(request => request.json().message) - .do(items => console.log("Crossref Results: total results = "+items['total-results']+" for doi = "+doi)) + .do(items => console.log("Crossref Results: total results = "+items['total-results']+" for doi = "+doisParams)) .do(res => { this._cache.set(key, res); }); diff --git a/portal-2/src/app/services/searchDatasets.service.ts b/portal-2/src/app/services/searchDatasets.service.ts index e9aeb82c..a93a7752 100644 --- a/portal-2/src/app/services/searchDatasets.service.ts +++ b/portal-2/src/app/services/searchDatasets.service.ts @@ -39,7 +39,34 @@ export class SearchDatasetsService { this._cache.set(key, res); }); } + searchDatasetsByDois (DOIs: string[], refineParams:string, page: number, size: number, refineFields:string[] ):any { + let link = OpenaireProperties.getSearchAPIURLLast()+"datasets"; + let url = link+"?"; + var doisParams = ""; + for(var i =0 ;i < DOIs.length; i++){ + doisParams+=(doisParams.length > 0?" or ":"")+'((pidclassid exact doi) and (pid exact "'+ DOIs[i]+'"))'; + } + if(doisParams.length > 0){ + url += "q=("+doisParams+")" + } + if(refineParams!= null && refineParams != '' ) { + url += refineParams; + } + url += "&page="+ (page-1) +"&size="+size+"&format=json"; + + let key = url; + if (this._cache.has(key)) { + return Observable.of(this._cache.get(key)); + } + return this.http.get(url) + .map(res => res.json()) + //.do(res => console.info(res)) + .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)]) + .do(res => { + this._cache.set(key, res); + }); + } advancedSearchDatasets (params: string, page: number, size: number ):any { let url = OpenaireProperties.getSearchResourcesAPIURL(); var basicQuery = "(oaftype exact result) and (resulttypeid exact dataset) " @@ -225,7 +252,7 @@ export class SearchDatasetsService { //OpenaireProperties.getSearchAPIURLLast() //"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" - let url = OpenaireProperties.getSearchAPIURLLast()+"datasets/count?q="+params+"&format=json"; + let url = OpenaireProperties.getSearchAPIURLLast()+"datasets/count?q="+'"' + params + '"'+"&format=json"; let key = url; if (this._cache.has(key)) { return Observable.of(this._cache.get(key)); diff --git a/portal-2/src/app/services/searchOrganizations.service.ts b/portal-2/src/app/services/searchOrganizations.service.ts index c815b041..eb47b679 100644 --- a/portal-2/src/app/services/searchOrganizations.service.ts +++ b/portal-2/src/app/services/searchOrganizations.service.ts @@ -226,7 +226,7 @@ export class SearchOrganizationsService { //OpenaireProperties.getSearchAPIURLLast() //"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" - let url = OpenaireProperties.getSearchAPIURLLast()+"organizations/count?q="+params+ "&format=json"; + let url = OpenaireProperties.getSearchAPIURLLast()+"organizations/count?q="+'"' + params + '"'+ "&format=json"; let key = url; if (this._cache.has(key)) { diff --git a/portal-2/src/app/services/searchPeople.service.ts b/portal-2/src/app/services/searchPeople.service.ts index 2e3c6d14..8cb7f891 100644 --- a/portal-2/src/app/services/searchPeople.service.ts +++ b/portal-2/src/app/services/searchPeople.service.ts @@ -109,7 +109,7 @@ export class SearchPeopleService { //OpenaireProperties.getSearchAPIURLLast() //"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" - let url = OpenaireProperties.getSearchAPIURLLast()+"people/count?q="+params+ "&format=json"; + let url = OpenaireProperties.getSearchAPIURLLast()+"people/count?q="+'"' + params + '"'+ "&format=json"; let key = url; if (this._cache.has(key)) { return Observable.of(this._cache.get(key)); diff --git a/portal-2/src/app/services/searchProjects.service.ts b/portal-2/src/app/services/searchProjects.service.ts index 4ba099e7..b94defb4 100644 --- a/portal-2/src/app/services/searchProjects.service.ts +++ b/portal-2/src/app/services/searchProjects.service.ts @@ -225,7 +225,7 @@ export class SearchProjectsService { //OpenaireProperties.getSearchAPIURLLast() //"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" - let url = OpenaireProperties.getSearchAPIURLLast()+"projects/count?q="+params+ "&format=json"; + let url = OpenaireProperties.getSearchAPIURLLast()+"projects/count?q="+'"' + params + '"'+ "&format=json"; let key = url; if (this._cache.has(key)) { return Observable.of(this._cache.get(key)); diff --git a/portal-2/src/app/services/searchPublications.service.ts b/portal-2/src/app/services/searchPublications.service.ts index 397287ba..0ed1c3be 100644 --- a/portal-2/src/app/services/searchPublications.service.ts +++ b/portal-2/src/app/services/searchPublications.service.ts @@ -15,7 +15,6 @@ export class SearchPublicationsService { private sizeOfDescription: number = 497; constructor(private http: Http, public _cache: CacheService) {} - searchPublications (params: string, refineParams:string, page: number, size: number, refineFields:string[] ):any { let link = OpenaireProperties.getSearchAPIURLLast()+"publications"; @@ -43,6 +42,38 @@ export class SearchPublicationsService { }); } + searchPublicationsByDois (DOIs: string[], refineParams:string, page: number, size: number, refineFields:string[] ):any { + + let link = OpenaireProperties.getSearchAPIURLLast()+"publications"; + + let url = link+"?"+"&format=json&"; + var doisParams = ""; + + for(var i =0 ;i < DOIs.length; i++){ + doisParams+=(doisParams.length > 0?" or ":"")+'((pidclassid exact doi) and (pid exact "'+ DOIs[i]+'"))'; + } + if(doisParams.length > 0){ + url += "q=("+doisParams+")" + } + if(refineParams!= null && refineParams != '' ) { + url += refineParams; + } + url += "&page="+(page-1)+"&size="+size; + + let key = url; + if (this._cache.has(key)) { + return Observable.of(this._cache.get(key)); + } + + return this.http.get(url) + .map(res => res.json()) + //.do(res => console.info(res)) + .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)]) + .do(res => { + this._cache.set(key, res); + }); + } + advancedSearchPublications (params: string, page: number, size: number ):any { let url = OpenaireProperties.getSearchResourcesAPIURL(); var basicQuery = "(oaftype exact result) and (resulttypeid exact publication) "; @@ -340,7 +371,7 @@ export class SearchPublicationsService { //OpenaireProperties.getSearchAPIURLLast() //"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" - let url = OpenaireProperties.getSearchAPIURLLast()+"publications/count?q="+params+ "&format=json"; + let url = OpenaireProperties.getSearchAPIURLLast()+"publications/count?q="+ '"' + params + '"' +"&format=json"; let key = url; if (this._cache.has(key)) { return Observable.of(this._cache.get(key)); diff --git a/portal-2/src/app/test/test.component.ts b/portal-2/src/app/test/test.component.ts index cc15a3eb..ba05e015 100644 --- a/portal-2/src/app/test/test.component.ts +++ b/portal-2/src/app/test/test.component.ts @@ -8,7 +8,7 @@ import {SearchPublicationsService} from '../services/searchPublications.service' import {SearchDatasetsService} from '../services/searchDatasets.service'; import {ISVocabulariesService} from '../services/ISVocabularies.service'; -import {Dates} from '../utils/dates.class'; +import {Dates} from '../utils/string-utils.class'; @Component({ selector: 'test', template: ` @@ -17,7 +17,7 @@ import {Dates} from '../utils/dates.class';
- +
Selected:: diff --git a/portal-2/src/app/utils/dates.class.ts b/portal-2/src/app/utils/string-utils.class.ts similarity index 59% rename from portal-2/src/app/utils/dates.class.ts rename to portal-2/src/app/utils/string-utils.class.ts index adc75ac8..c2ccba91 100644 --- a/portal-2/src/app/utils/dates.class.ts +++ b/portal-2/src/app/utils/string-utils.class.ts @@ -33,3 +33,29 @@ export class Dates { } } + +export class DOI{ + + public static getDOIsFromString(str:string):string[]{ + var DOIs:string[] = []; + var words:string[] = str.split(" "); + + for(var i=0; i< words.length; i++){ + if(DOI.isValidDOI(words[i]) && DOIs.indexOf(words[i]) == -1){ + DOIs.push(words[i]); + } + } + return DOIs; + } + public static isValidDOI(str:string):boolean{ + + var exp1 = /\b(10[.][0-9]{4,}(?:[.][0-9]+)*\/(?:(?!["&\'<>])\S)+)\b/g + var exp2 = /\b(10[.][0-9]{4,}(?:[.][0-9]+)*\/(?:(?!["&\'<>])[[:graph:]])+)\b/g + if(str.match(exp1)!=null || str.match(exp2)!=null){ + // console.log("It's a DOI"); + return true; + } + return false; + + } +}