From c9c1aff2ff4a914b152f11228d0c8882be4b4301 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Wed, 1 Jun 2022 13:27:46 +0300 Subject: [PATCH] Change queries in advanced to support or not. Add different options for every equality operator. --- .../advancedSearchForm.component.html | 11 +++++------ .../advancedSearchForm.component.ts | 19 +++++++++++-------- .../searchUtils/newSearchPage.component.ts | 8 +++++--- utils/properties/searchFields.ts | 10 +++++----- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/searchPages/searchUtils/advancedSearchForm.component.html b/searchPages/searchUtils/advancedSearchForm.component.html index 1e772bd3..8ef7c5a1 100644 --- a/searchPages/searchUtils/advancedSearchForm.component.html +++ b/searchPages/searchUtils/advancedSearchForm.component.html @@ -27,9 +27,8 @@
-
-
includes
-
include
+
+
includes
diff --git a/searchPages/searchUtils/advancedSearchForm.component.ts b/searchPages/searchUtils/advancedSearchForm.component.ts index 3765f13f..9ee3d16f 100644 --- a/searchPages/searchUtils/advancedSearchForm.component.ts +++ b/searchPages/searchUtils/advancedSearchForm.component.ts @@ -18,7 +18,6 @@ import {EnvProperties} from '../../utils/properties/env-properties'; import {SearchCustomFilter} from "./searchUtils.class"; import {Subscriber} from "rxjs"; import {properties} from "../../../../environments/environment"; -import {Open} from "../../utils/modal/open.component"; import {Option} from "../../sharedComponents/input/input.component"; @Component({ @@ -52,8 +51,9 @@ export class AdvancedSearchFormComponent implements OnInit, OnDestroy, OnChanges properties: EnvProperties; public openaireEntities = OpenaireEntities; public operators: string[] = this.searchFields.ADVANCED_SEARCH_OPERATORS; - public notOperators: Option[] = []; - public logicalOperators: Option[] = []; + public isOperators: Option[] = [{label: 'is', value: true}, {label: 'is not', value: false}]; + public isWithinOperators: Option[] = [{label: 'is within', value: true}, {label: 'is not within', value: false}]; + public includesOperators: Option[] = [{label: 'includes', value: true}, {label: 'not includes', value: false}]; selectedEntity; selectedEntitySimpleUrl; selectedEntityAdvancedUrl; @@ -73,7 +73,6 @@ export class AdvancedSearchFormComponent implements OnInit, OnDestroy, OnChanges } this.newFieldId = this.fieldIds[0]; this.newFieldName = this.fieldIdsMap[this.newFieldId].name; - this.buildOperatorsOptions(); this.buildFieldIdsOptions(); } @@ -89,9 +88,14 @@ export class AdvancedSearchFormComponent implements OnInit, OnDestroy, OnChanges } } - buildOperatorsOptions() { - this.notOperators = [{label: 'includes', value: true}, {label: 'not includes', value: false}]; - this.logicalOperators = []; + getNotOperators(field: AdvancedField) { + if(this.fieldIdsMap[field.id].equalityOperator.includes('exact')) { + return this.isOperators; + } else if(this.fieldIdsMap[field.id].equalityOperator.includes('within')) { + return this.isWithinOperators; + } else { + return this.includesOperators; + } } buildFieldIdsOptions() { @@ -136,7 +140,6 @@ export class AdvancedSearchFormComponent implements OnInit, OnDestroy, OnChanges }); if (this.validDateFrom && this.validDateTo) { - this.queryChange.emit({}); } } diff --git a/searchPages/searchUtils/newSearchPage.component.ts b/searchPages/searchUtils/newSearchPage.component.ts index e8114ed5..5eec41c6 100644 --- a/searchPages/searchUtils/newSearchPage.component.ts +++ b/searchPages/searchUtils/newSearchPage.component.ts @@ -341,8 +341,8 @@ export class NewSearchPageComponent { } queryChanged($event) { + this.cdr.detectChanges(); if ($event == "filters_update") { - this.cdr.detectChanges(); return; } this.goTo(1, false); @@ -917,8 +917,10 @@ export class NewSearchPageComponent { } else if (this.selectedFields[i].type == "identifier") { params += NewSearchPageComponent.createKeywordQuery(this.entityType, this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId, countParams); - } else if ((!this.selectedFields[i].includes || (countParams == 0 && this.selectedFields[i].operatorId == "not" && this.fieldIdsMap[this.selectedFields[i].id].equalityOperator != "="))) { - params += (this.selectedFields[i].operatorId && countParams>0?this.selectedFields[i].operatorId:"") + " (" + this.selectedFields[i].id + " <> " + '"' + StringUtils.URIEncode(this.selectedFields[i].value) + '"' + ") "; + } 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.selectedFields[i].includes) { + params += (i > 0?this.selectedFields[i].operatorId:'') + " (*=* NOT " + this.selectedFields[i].id + this.fieldIdsMap[this.selectedFields[i].id].equalityOperator + '"' + StringUtils.URIEncode(this.selectedFields[i].value) + '"' + ") "; } else if (this.fieldIdsMap[this.selectedFields[i].id].equalityOperator == "=") { params += NewSearchPageComponent.createQuotedKeywordQuery(this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId, countParams, false); } else { diff --git a/utils/properties/searchFields.ts b/utils/properties/searchFields.ts index 0bffac9c..5b8cf21a 100644 --- a/utils/properties/searchFields.ts +++ b/utils/properties/searchFields.ts @@ -23,7 +23,7 @@ export class SearchFields { "relfundinglevel0_id", "relfundinglevel1_id", "relfundinglevel2_id", "resultlanguagename", "relorganizationid", "pid", "relprojectid", "instancetypename", "fos", "sdg"]; public RESULT_FIELDS: { [key: string]: FieldDetails } = { - ["q"]: {name: "All fields", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null}, + ["q"]: {name: "Any field", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null}, ["resulttitle"]: { name: "Title", type: "keyword", @@ -262,7 +262,7 @@ export class SearchFields { "projectstartdate", "projectenddate", "projectcode_nt", "relorganizationid", "collectedfromdatasourceid"]; public PROJECT_FIELDS: { [key: string]: FieldDetails } = { - ["q"]: {name: "All fields", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null}, + ["q"]: {name: "Any field", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null}, ["projectacronym"]: { name: "Acronym", type: "keyword", @@ -405,7 +405,7 @@ export class SearchFields { "datasourceodcontenttypes", "datasourcecompatibilityname", "relorganizationid", "collectedfromdatasourceid"]; public DATASOURCE_FIELDS: { [key: string]: FieldDetails } = { - ["q"]: {name: "All fields", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null}, + ["q"]: {name: "Any field", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null}, ["datasourceofficialname"]: { name: "English name", type: "keyword", @@ -600,7 +600,7 @@ export class SearchFields { public ORGANIZATION_ADVANCED_FIELDS: string[] = ["q", "organizationlegalname", "organizationlegalshortname", "country"]; public ORGANIZATION_FIELDS: { [key: string]: FieldDetails } = { - ["q"]: {name: "All fields", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null}, + ["q"]: {name: "Any field", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null}, ["organizationlegalname"]: { name: "Legal Name", type: "keyword", @@ -631,7 +631,7 @@ export class SearchFields { // public ORGANIZATION_INDEX_PARAM_MAP:{ [key:string]:string } = {["organizationlegalname"]:"contenttype", ["organizationlegalshortname"]:"type", // ["organizationcountryname"]:"country"};//,["organizationeclegalbody"]:"type"}; // public ORGANIZATION_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string , operator: "op", equalityOperator:string}} ={ - // ["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null, operator: "op", equalityOperator: "="}, + // ["q"]:{name:"Any field",operator:"op", type:"keyword", indexField:null, operator: "op", equalityOperator: "="}, // ["contenttype"]:{name:"Legal Name",operator:"cn", type:"keyword" , indexField:"organizationlegalname", operator: "op", equalityOperator: "="}, // ["compatibility"]:{name:"Legal Short Name",operator:"cm", type:"keyword", indexField:"organizationlegalshortname", operator: "op", equalityOperator: "="}, // ["country"]:{name:"Country",operator:"cu", type:"vocabulary", indexField:"organizationcountryname", operator: "op", equalityOperator: " exact "},