Change queries in advanced to support or not. Add different options for every equality operator.

This commit is contained in:
Konstantinos Triantafyllou 2022-06-01 13:27:46 +03:00
parent b0c9ee3736
commit c9c1aff2ff
4 changed files with 26 additions and 22 deletions

View File

@ -27,9 +27,8 @@
<div class="uk-grid uk-flex-middle uk-child-width-1-2@m uk-child-width-1-1">
<div input [(value)]="selectedField.id" inputClass="border-bottom" [tooltip]="true"
[options]="fieldIdsOptions" (valueChange)="fieldIdsChanged(i,selectedField.id)" type="select"></div>
<div input *ngIf="selectedField.id != 'q' && !onlyIncludesSupported(i)" [(value)]="selectedField.includes" inputClass="border-bottom" [options]="notOperators" type="select"></div>
<div *ngIf="selectedField.id != 'q' && onlyIncludesSupported(i)">includes</div>
<div *ngIf="selectedField.id == 'q'">include</div>
<div input *ngIf="selectedField.id != 'q'" [(value)]="selectedField.includes" inputClass="border-bottom" [options]="getNotOperators(selectedField)" type="select"></div>
<div *ngIf="selectedField.id == 'q'">includes</div>
</div>
<!-- <mat-select [(ngModel)]="selectedField.id" name="selectField_{{i}}" [disableOptionCentering]="true" class="matSelection" panelClass="matSelectionPanel"
(ngModelChange)="fieldIdsChanged(i,selectedField.id)">&lt;!&ndash;(click)="fieldIdsChanged(i)" &ndash;&gt;
@ -91,9 +90,9 @@
</span>
</td>
<td class="uk-width-small">
<div *ngIf="i+1 <selectedFields.length && !onlyAndSupported(i)" [(value)]="selectedFields[i+1].operatorId" (valueChange)="fieldOperatorChanged(i+1, $event, $event)"
<div *ngIf="i+1 <selectedFields.length" [(value)]="selectedFields[i+1].operatorId" (valueChange)="fieldOperatorChanged(i+1, $event, $event)"
input [options]="operators" inputClass="border-bottom" type="select"></div>
<div *ngIf="i+1 <selectedFields.length && onlyAndSupported(i)">and</div>
<!-- <div *ngIf="i+1 <selectedFields.length && onlyAndSupported(i)">and</div>-->
</td>
<td [class.uk-invisible]="selectedFields.length === 1">
<button class="uk-icon uk-close"
@ -104,7 +103,7 @@
</tr>
</table>
<div class="uk-margin-small-top">
<button (click)="addField()" class="uk-button uk-button-link uk-flex uk-flex-middle">
<button type="button" (click)="addField()" class="uk-button uk-button-link uk-flex uk-flex-middle">
<icon name="add" [flex]="true"></icon>
<span class="uk-margin-small-left">Add rule</span>
</button>

View File

@ -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({});
}
}

View File

@ -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 {

View File

@ -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 "},