[Library|Trunk]

Search Find:
	count query: use /resources2, use newSearchPage method, for creating the parameters (DOI, orcid, quotes)
	count outcomes: add open access filter
	fix keyword parameters
	for the active tab, initialize results total number with null



git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58416 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
argiro.kokogiannaki 2020-04-07 11:11:31 +00:00
parent 55c77ca0cb
commit 5a1f545b52
7 changed files with 111 additions and 45 deletions

View File

@ -31,6 +31,7 @@ import {SearchResearchResultsComponent} from "../searchResearchResults.component
import {SearchProjectsComponent} from "../searchProjects.component";
import {SearchOrganizationsComponent} from "../searchOrganizations.component";
import {SearchDataProvidersComponent} from "../searchDataProviders.component";
import {NewSearchPageComponent} from "../searchUtils/newSearchPage.component";
@Component({
changeDetection: ChangeDetectionStrategy.Default,
@ -65,9 +66,6 @@ export class SearchAllComponent {
public linkToSearchPublications = "";
public linkToSearchProjects = "";
public linkToSearchDataproviders = "";
public linkToSearchDatasets = "";
public linkToSearchSoftware = "";
public linkToSearchOrps = "";
public linkToSearchOrganizations = "";
public fetchPublications: FetchResearchResults;
@ -328,13 +326,17 @@ export class SearchAllComponent {
}
}
private prepareKeywordParam(keyword){
if (this.parameters["q"] && keyword.length == 0) {
if (this.parameters["q"]) {
delete this.parameters['q'];
delete this.parameters['op'];
} else {
}
if(keyword.length > 0){
this.parameters["fv0"] = keyword;
this.parameters["f0"] = "q";
}
}else if(keyword.length ==0 && this.parameters["f0"]=="q"){
delete this.parameters['f0'];
delete this.parameters['fv0'];
}
}
private prepareResultParameters() {
//quickSelections
@ -363,6 +365,7 @@ export class SearchAllComponent {
public quickSelectionsChanged() {
this.prepareResultParameters();
this.parameters["page"] = 1;
this.reload[this.activeEntity] = true;
this.router.navigate([location.pathname], {queryParams: this.parameters});
}
@ -370,6 +373,7 @@ export class SearchAllComponent {
public keywordChanged($event) {
this.prepareKeywordParam(this.selectedFields[0].value);
this.parameters["page"] = 1;
this.reloadTabs();
this.router.navigate([location.pathname], {queryParams: this.parameters});
}
@ -383,14 +387,15 @@ export class SearchAllComponent {
this.fetchPublications.searchUtils.status = this.errorCodes.LOADING;
this.reload["result"] = false;
this.fetchPublications.results = [];
this.subPub = this.numOfSearchResults(this.fetchPublications, refineParams);
//Add Open Access Filter
this.subPub = this.numOfSearchResults(this.fetchPublications, (refineParams ? (refineParams + '&') : '') + "&fq=resultbestaccessright%20exact%20%22Open%20Access%22");
}
if (this.activeEntity != "projects" && this.reload["projects"] && this.showProjects) {
this.fetchProjects.searchUtils.status = this.errorCodes.LOADING;
this.fetchProjects.results = [];
this.reload["projects"] = false;
this.subProjects = this._searchProjectsService.numOfSearchProjects(this.keyword, this.properties, refineParams).subscribe(
this.subProjects = this._searchProjectsService.numOfSearchProjects2(this.keyword.length>0?NewSearchPageComponent.createKeywordQuery("project",this.keyword,"q","="):"", this.properties, refineParams).subscribe(
data => {
this.fetchProjects.searchUtils.totalResults = data;
this.fetchProjects.searchUtils.status = this.errorCodes.DONE;
@ -408,13 +413,27 @@ export class SearchAllComponent {
if (this.activeEntity != "datasources" && this.reload["datasources"] && this.showDataProviders) {
this.fetchDataproviders.results = [];
this.reload["datasources"] = false;
this.fetchDataproviders.getNumForSearch(this.keyword, this.properties, refineParams);
// this.fetchDataproviders.getNumForSearch(this.keyword, this.properties, refineParams);
this.subDataPr = this._searchDataprovidersService.numOfSearchDataproviders2(this.keyword.length>0?NewSearchPageComponent.createKeywordQuery("datasources",this.keyword,"q","="):"", this.properties, refineParams).subscribe(
data => {
this.fetchDataproviders.searchUtils.totalResults = data;
this.fetchDataproviders.searchUtils.status = this.errorCodes.DONE;
if (this.fetchDataproviders.searchUtils.totalResults == 0) {
this.fetchDataproviders.searchUtils.status = this.errorCodes.NONE;
}
},
err => {
//console.log(err);
this.handleError("Error getting number of Projects", err);
this.fetchDataproviders.searchUtils.status = this.errorCodes.ERROR;
}
);
}
if (this.activeEntity != "organizations" && this.reload["organizations"] && this.showOrganizations) {
this.fetchOrganizations.searchUtils.status = this.errorCodes.LOADING;
this.fetchOrganizations.results = [];
this.reload["organizations"] = false;
this.subOrg = this._searchOrganizationsService.numOfSearchOrganizations(this.keyword, this.properties, refineParams).subscribe(
this.subOrg = this._searchOrganizationsService.numOfSearchOrganizations2(this.keyword.length>0?NewSearchPageComponent.createKeywordQuery("organizations",this.keyword,"q","="):"", this.properties, refineParams).subscribe(
data => {
this.fetchOrganizations.searchUtils.totalResults = data;
this.fetchOrganizations.searchUtils.status = this.errorCodes.DONE;
@ -435,7 +454,7 @@ export class SearchAllComponent {
}
private numOfSearchResults(fetchClass: FetchResearchResults, refineParams): Observable<any> {
return this._searchResearchResultsService.numOfResearchOutcomes(this.keyword, this.properties, refineParams).subscribe(
return this._searchResearchResultsService.numOfResearchOutcomes(this.keyword.length>0?NewSearchPageComponent.createKeywordQuery("result",this.keyword,"q","="):"", this.properties, refineParams).subscribe(
data => {
fetchClass.searchUtils.totalResults = data;
fetchClass.searchUtils.status = this.errorCodes.DONE;
@ -465,18 +484,6 @@ export class SearchAllComponent {
console.error("General Search Page: " + message, error);
}
private getEntityName(entityType: string, plural: boolean, full: boolean): string {
if (entityType == "publication") {
return "publication" + (plural ? "s" : "");
} else if (entityType == "dataset") {
return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
} else if (entityType == "software") {
return "software";
} else if (entityType == "other") {
return (full ? ("other research product" + (plural ? "s" : "")) : "other");
}
}
activeEntityUpdate($event) {
this.disableForms = $event.disableForms;
let updated = true;
@ -526,8 +533,8 @@ export class SearchAllComponent {
this.reload[entity]= true;
this.parameters["active"] = entity;
if ( this.keyword.length > 0) {
this.parameters["q"] = this.keyword;
this.parameters["op"] = "and";
this.parameters["fv0"] = this.keyword;
this.parameters["f0"] = "q";
}
this.router.navigate(["/search/find"], {queryParams: this.parameters});
}

View File

@ -660,7 +660,7 @@ export class NewSearchPageComponent {
} else {
if (this.selectedFields[i].id == "q") {
// console.log(this.selectedFields[i].value)
var op = "";
/* var op = "";
var doisParams = "";
if ((this.entityType == 'publication' || this.entityType == 'dataset' || this.entityType == 'software' || this.entityType == 'other' || this.entityType == "result")) {
var DOIs: Identifier[] = Identifier.getIdentifiersFromString(this.selectedFields[i].value);
@ -679,7 +679,8 @@ export class NewSearchPageComponent {
params += this.createQuotedKeywordQuery(this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId ,countParams,true, true) + " or " + doisParams;
} else {
params += this.createQuotedKeywordQuery(this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId,countParams,true);
}
}*/
params = NewSearchPageComponent.createKeywordQuery(this.entityType,this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId, countParams);
//TODO deposit case
// console.log(this.usedBy)
// console.log(this.keywordFields)
@ -693,7 +694,7 @@ export class NewSearchPageComponent {
if(j > 0) {
params += " or "
}
params += this.createQuotedKeywordQuery(this.selectedFields[i].value, this.keywordFields[j].name, " or ", countParams,false);
params += NewSearchPageComponent.createQuotedKeywordQuery(this.selectedFields[i].value, this.keywordFields[j].name, " or ", countParams,false);
// let field = this.keywordFields[i];
//keywordQuery += field.name+field.equalityOperator+StringUtils.URIEncode(keyword);
// params += field.name+field.equalityOperator+StringUtils.quote(StringUtils.URIEncode(keyword));
@ -706,7 +707,7 @@ export class NewSearchPageComponent {
} else if (countParams == 0 && this.selectedFields[i].operatorId == "not" && this.fieldIdsMap[this.selectedFields[i].id].equalityOperator != "=") {
params += " " + this.selectedFields[i].id + " <> " + '"' + StringUtils.URIEncode(this.selectedFields[i].value) + '"' + " ";
} else if(this.fieldIdsMap[this.selectedFields[i].id].equalityOperator == "=") {
params+=this.createQuotedKeywordQuery(this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId, countParams, false);
params+=NewSearchPageComponent.createQuotedKeywordQuery(this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId, countParams, false);
}else{
params += (countParams == 0 ? "" : this.selectedFields[i].operatorId + " ") + this.selectedFields[i].id + this.fieldIdsMap[this.selectedFields[i].id].equalityOperator + '"' + encodeURIComponent(this.selectedFields[i].value) + '"' + " ";
@ -723,8 +724,31 @@ export class NewSearchPageComponent {
// console.log(params)
return params;
}
public static createKeywordQuery(entityType:string, value:string, id, operatorId, countParams=0){
let params = "";
let doisParams = "";
if ((entityType == 'publication' || entityType == 'dataset' || entityType == 'software' || entityType == 'other' || entityType == "result")) {
var DOIs: Identifier[] = Identifier.getIdentifiersFromString(value);
for (let identifier of DOIs) {
// console.log(identifier)
// pidclassid exact \"doi\" and pid exact \"10.1016/j.nima.2015.11.134\"
//and (authorid exact \"0000-0001-7291-3210 \" )"
if(identifier.class == "ORCID"){
doisParams += (doisParams.length > 0 ? " or " : "") +'(authorid="' + identifier.id + '")';
}else{
doisParams += (doisParams.length > 0 ? " or " : "") +'(pidclassid exact "' + identifier.class + '" and pid="' + identifier.id + '")';
}
}
}
if (doisParams.length > 0) {
params += this.createQuotedKeywordQuery(value, id, operatorId ,countParams,true, true) + " or " + doisParams;
} else {
params += this.createQuotedKeywordQuery(value, id, operatorId,countParams,true);
}
return params;
createQuotedKeywordQuery(fieldValue, fieldId, fieldOperator, countParams:number, isSearchAll:boolean, forceQuotted:boolean=false){
}
private static createQuotedKeywordQuery(fieldValue, fieldId, fieldOperator, countParams:number, isSearchAll:boolean, forceQuotted:boolean=false){
let params = "";
let quotedParts = (fieldValue)?fieldValue.match(/(["'])(.*?)*?\1/g):[];
params+= (countParams == 0 ? "" : fieldOperator) + " (";
@ -768,10 +792,10 @@ export class NewSearchPageComponent {
return params;
}
private getQuotedQueryPart(fieldId:string, value:string, isSearchAll:boolean){
private static getQuotedQueryPart(fieldId:string, value:string, isSearchAll:boolean){
return (isSearchAll?"__all":fieldId)+" exact "+StringUtils.URIEncode(value);
}
private getNoQuotedQueryPart(fieldId:string, value:string, isSearchAll:boolean){
private static getNoQuotedQueryPart(fieldId:string, value:string, isSearchAll:boolean){
if(isSearchAll){
return value ;
}else{

View File

@ -4,7 +4,7 @@ export class SearchUtilsClass{
status:number = 1;
keyword:string = "";
baseUrl:string = "";
totalResults = 0;
totalResults = null;
totalResultsNoFilters:number; // for organization landing - tab with projects
sortBy: string = "";
}

View File

@ -471,6 +471,17 @@ export class SearchDataprovidersService {
return this.numOfDataproviders(url, properties);
}
numOfSearchDataproviders2(params: string, properties:EnvProperties, refineQuery:string=null):any {
let url: string = properties.searchAPIURLLAst+"resources2/?format=json&size=0&type=datasources";
if(params != "") {
url += "&query=" +params;
}
if(refineQuery!= null && refineQuery != '' ) {
url += refineQuery;
}
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
.pipe(map(res => res['meta']['total']));
}
/*
private quote(word: any): string {
return '"'+word+'"';

View File

@ -196,4 +196,16 @@ export class SearchOrganizationsService {
}
return this.numOfOrganizations(url, properties);
}
numOfSearchOrganizations2(params: string, properties:EnvProperties, refineParams:string=null ):any {
let url = properties.searchAPIURLLAst+"resources2/?format=json&size=0&type=organizations";
if(params != "") {
url += "&query=" + params;
}
if(refineParams!= null && refineParams != '' ) {
url += refineParams;
}
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
.pipe(map(res => res['meta']['total']));
}
}

View File

@ -288,4 +288,15 @@ export class SearchProjectsService {
}
return this.numOfProjects(url, properties);
}
numOfSearchProjects2(params: string, properties:EnvProperties, refineParams:string=null ):any {
let url = properties.searchAPIURLLAst+"resources2/?format=json&size=0&type=projects";
if(params != "") {
url += "&query=" + params;
}
if(refineParams!= null && refineParams != '' ) {
url += refineParams;
}
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
.pipe(map(res => res['meta']['total']));
}
}

View File

@ -388,19 +388,20 @@ export class SearchResearchResultsService {
return this.numOfResults(url , properties);
}
numOfResearchOutcomes( params: string, properties:EnvProperties, refineParams:string=null):any {
let url = properties.searchAPIURLLAst+"resources2/?format=json&size=0&type=publications&type=datasets&type=software&type=other";
let url = properties.searchAPIURLLAst+"resources2/?format=json&size=0&type=results";
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 += "&query=" + StringUtils.URIEncode(params);
}
// 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;
}
if(refineParams!= null && refineParams != '' ) {